From 0d87c82e3b7ea668489d7eee84c8e50c0907ac9f Mon Sep 17 00:00:00 2001 From: VivianDee <115420678+VivianDee@users.noreply.github.com> Date: Tue, 25 Mar 2025 08:52:33 +0100 Subject: [PATCH] [update]: Swagger documentation and responses --- README.md | 2 +- app/api/routes/routes.py | 14 ++-- app/api/schemas/loan_information.py | 5 -- app/api/schemas/loan_status.py | 8 +++ app/api/schemas/provide_loan.py | 2 +- app/api/services/__init__.py | 2 +- .../{loan_information.py => loan_status.py} | 36 +++++----- app/api/services/provide_loan.py | 2 +- app/config.py | 2 +- app/swagger/digifi_swagger.json | 14 ++-- .../{LoanInformation.json => LoanStatus.json} | 16 ++--- app/swagger/paths/NotificationCallback.json | 10 +-- app/swagger/paths/ProvideLoan.json | 10 +-- .../schemas/CustomerConsentRequest.json | 2 +- .../schemas/LoanInformationResponse.json | 28 -------- ...ionRequest.json => LoanStatusRequest.json} | 6 +- app/swagger/schemas/LoanStatusResponse.json | 70 +++++++++++++++++++ app/swagger/schemas/ProvideLoanRequest.json | 21 ++++-- app/swagger/schemas/RepaymentRequest.json | 2 +- 19 files changed, 153 insertions(+), 99 deletions(-) delete mode 100644 app/api/schemas/loan_information.py create mode 100644 app/api/schemas/loan_status.py rename app/api/services/{loan_information.py => loan_status.py} (73%) rename app/swagger/paths/{LoanInformation.json => LoanStatus.json} (72%) delete mode 100644 app/swagger/schemas/LoanInformationResponse.json rename app/swagger/schemas/{LoanInformationRequest.json => LoanStatusRequest.json} (75%) create mode 100644 app/swagger/schemas/LoanStatusResponse.json diff --git a/README.md b/README.md index b52e6ae..7911c12 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Then, open the `.env` file and add the following: ```ini # Environment Variables -BASIC_AUTH_USERNAME=admin +BASIC_AUTH_USERNAME=user BASIC_AUTH_PASSWORD=password SWAGGER_URL="/documentation" API_URL="/swagger.json" diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 4586f56..8530b0e 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -3,7 +3,7 @@ from app.api.services import ( EligibilityCheckService, SelectOfferService, ProvideLoanService, - LoanInformationService, + LoanStatusService, RepaymentService, CustomerConsentService, NotificationCallbackService @@ -65,13 +65,13 @@ def provide_loan(): return response -# LoanInformation Endpoint -@api.route('/LoanInformation', methods=['GET']) +# LoanStatus Endpoint +@api.route('/LoanStatus', methods=['POST']) @require_auth -def loan_information(): - data = request.args.to_dict() - # logger.info(f"LoanInformation request received: {data}") - response = LoanInformationService.process_request(data) +def loan_status(): + data = request.get_json() + # logger.info(f"LoanStatus request received: {data}") + response = LoanStatusService.process_request(data) return response diff --git a/app/api/schemas/loan_information.py b/app/api/schemas/loan_information.py deleted file mode 100644 index 4d9b5ab..0000000 --- a/app/api/schemas/loan_information.py +++ /dev/null @@ -1,5 +0,0 @@ -from marshmallow import Schema, fields - -# Loan Information Schema -class LoanInformationSchema(Schema): - loan_id = fields.Str(required=True) \ No newline at end of file diff --git a/app/api/schemas/loan_status.py b/app/api/schemas/loan_status.py new file mode 100644 index 0000000..7599d5f --- /dev/null +++ b/app/api/schemas/loan_status.py @@ -0,0 +1,8 @@ +from marshmallow import Schema, fields + +# Loan Information Schema +class LoanStatusSchema(Schema): + transactionId = fields.Str(required=True) + customerId = fields.Str(required=True) + msisdn = fields.Str(required=False) + channel = fields.Str(required=True) \ No newline at end of file diff --git a/app/api/schemas/provide_loan.py b/app/api/schemas/provide_loan.py index ca82352..cd1d417 100644 --- a/app/api/schemas/provide_loan.py +++ b/app/api/schemas/provide_loan.py @@ -2,7 +2,7 @@ from marshmallow import Schema, fields # Provide Loan Schema class ProvideLoanSchema(Schema): - type = fields.Str(required=True) + type = fields.Str(required=False) requestId = fields.Str(required=True) transactionId = fields.Str(required=True) customerId = fields.Str(required=True) diff --git a/app/api/services/__init__.py b/app/api/services/__init__.py index 911e4d1..de551bb 100644 --- a/app/api/services/__init__.py +++ b/app/api/services/__init__.py @@ -1,7 +1,7 @@ from app.api.services.eligibility_check import EligibilityCheckService from app.api.services.select_offer import SelectOfferService from app.api.services.provide_loan import ProvideLoanService -from app.api.services.loan_information import LoanInformationService +from app.api.services.loan_status import LoanStatusService from app.api.services.repayment import RepaymentService from app.api.services.customer_consent import CustomerConsentService from app.api.services.notification_callback import NotificationCallbackService \ No newline at end of file diff --git a/app/api/services/loan_information.py b/app/api/services/loan_status.py similarity index 73% rename from app/api/services/loan_information.py rename to app/api/services/loan_status.py index d2e49a1..b163e89 100644 --- a/app/api/services/loan_information.py +++ b/app/api/services/loan_status.py @@ -1,9 +1,9 @@ from flask import request, jsonify from marshmallow import ValidationError from app.utils.logger import logger -from app.api.schemas.loan_information import LoanInformationSchema +from app.api.schemas.loan_status import LoanStatusSchema -class LoanInformationService: +class LoanStatusService: @staticmethod def process_request(data): """ @@ -16,27 +16,31 @@ class LoanInformationService: dict: A standardized response. """ try: - logger.info("Processing LoanInformation request") + logger.info("Processing LoanStatus request") # Validate input data using the imported schema - schema = LoanInformationSchema() + schema = LoanStatusSchema() validated_data = schema.load(data) # Raises ValidationError if invalid + loans = [ + { + "debtId": "123456789", + "loanDate": "2019-10-18 14:26:21.063", + "dueDate": "2019-11-20 14:26:21.063", + "currentLoanAmount": 8500, + "initialLoanAmount": 10000, + "defaultPenaltyFee": 0, + "continuousFee": 0, + "productId": "101" + } + ] + # Simulated processing logic response_data = { "customerId": "CN621868", - "loans": [ - { - "debtId": "123456789", - "loanDate": "2019-10-18 14:26:21.063", - "dueDate": "2019-11-20 14:26:21.063", - "currentLoanAmount": 8500.0, - "initialLoanAmount": 10000.0, - "defaultFee": 0.0, - "continuousFee": 0.0, - "productId": "101" - } - ], + "transactionId": "Tr201712RK9232P115", + "loans": loans, + "totalDebtAmount": 8500, "resultCode": "00", "resultDescription": "Successful" } diff --git a/app/api/services/provide_loan.py b/app/api/services/provide_loan.py index d55e79b..8d57343 100644 --- a/app/api/services/provide_loan.py +++ b/app/api/services/provide_loan.py @@ -23,7 +23,7 @@ class ProvideLoanService: validated_data = schema.load(data) # Raises ValidationError if invalid # Business logic - providing a loan - response_data ={ + response_data = { "requestId": "202111170001371256908", "transactionId": "Tr201712RK9232P115", "customerId": "CN621868", diff --git a/app/config.py b/app/config.py index a1f4794..9d37a22 100644 --- a/app/config.py +++ b/app/config.py @@ -13,5 +13,5 @@ class Config: DEBUG = True VALID_APP_ID = os.getenv("VALID_APP_ID", "app1") VALID_API_KEY = os.getenv("VALID_API_KEY", "test-api-key-12345") - BASIC_AUTH_USERNAME = os.environ.get("BASIC_AUTH_USERNAME", "admin") + BASIC_AUTH_USERNAME = os.environ.get("BASIC_AUTH_USERNAME", "user") BASIC_AUTH_PASSWORD = os.environ.get("BASIC_AUTH_PASSWORD", "password") \ No newline at end of file diff --git a/app/swagger/digifi_swagger.json b/app/swagger/digifi_swagger.json index 42b5d06..8b2755d 100644 --- a/app/swagger/digifi_swagger.json +++ b/app/swagger/digifi_swagger.json @@ -44,7 +44,7 @@ } }, { - "name": "LoanInformation", + "name": "LoanStatus", "description": "Loan Information Request.", "externalDocs": { "description": "Find out more", @@ -86,8 +86,8 @@ "/ProvideLoan": { "$ref": "swagger/paths/ProvideLoan.json" }, - "/LoanInformation": { - "$ref": "swagger/paths/LoanInformation.json" + "/LoanStatus": { + "$ref": "swagger/paths/LoanStatus.json" }, "/Repayment": { "$ref": "swagger/paths/Repayment.json" @@ -113,11 +113,11 @@ "SelectOfferResponse": { "$ref": "swagger/schemas/SelectOfferResponse.json" }, - "LoanInformationRequest": { - "$ref": "swagger/schemas/LoanInformationRequest.json" + "LoanStatusRequest": { + "$ref": "swagger/schemas/LoanStatusRequest.json" }, - "LoanInformationResponse": { - "$ref": "swagger/schemas/LoanInformationResponse.json" + "LoanStatusResponse": { + "$ref": "swagger/schemas/LoanStatusResponse.json" }, "RepaymentRequest": { "$ref": "swagger/schemas/RepaymentRequest.json" diff --git a/app/swagger/paths/LoanInformation.json b/app/swagger/paths/LoanStatus.json similarity index 72% rename from app/swagger/paths/LoanInformation.json rename to app/swagger/paths/LoanStatus.json index 659c55b..ee1b633 100644 --- a/app/swagger/paths/LoanInformation.json +++ b/app/swagger/paths/LoanStatus.json @@ -1,27 +1,27 @@ { - "get": { + "post": { "tags": [ - "LoanInformation" + "LoanStatus" ], "summary": "Loan Information Request ", "description": "Loan Information Request", - "operationId": "LoanInformation", + "operationId": "LoanStatus", "requestBody": { "description": "Post JSON to conduct eligibility tests", "content": { "application/json": { "schema": { - "$ref": "../schemas/LoanInformationRequest.json" + "$ref": "../schemas/LoanStatusRequest.json" } }, "application/xml": { "schema": { - "$ref": "../schemas/LoanInformationRequest.json" + "$ref": "../schemas/LoanStatusRequest.json" } }, "application/x-www-form-urlencoded": { "schema": { - "$ref": "../schemas/LoanInformationRequest.json" + "$ref": "../schemas/LoanStatusRequest.json" } } }, @@ -33,12 +33,12 @@ "content": { "application/json": { "schema": { - "$ref": "../schemas/LoanInformationResponse.json" + "$ref": "../schemas/LoanStatusResponse.json" } }, "application/xml": { "schema": { - "$ref": "../schemas/LoanInformationResponse.json" + "$ref": "../schemas/LoanStatusResponse.json" } } } diff --git a/app/swagger/paths/NotificationCallback.json b/app/swagger/paths/NotificationCallback.json index cb0b103..d241e1e 100644 --- a/app/swagger/paths/NotificationCallback.json +++ b/app/swagger/paths/NotificationCallback.json @@ -11,17 +11,17 @@ "content": { "application/json": { "schema": { - "$ref": "../schemas/LoanInformationRequest.json" + "$ref": "../schemas/NotificationCallbackRequest.json" } }, "application/xml": { "schema": { - "$ref": "../schemas/LoanInformationRequest.json" + "$ref": "../schemas/NotificationCallbackRequest.json" } }, "application/x-www-form-urlencoded": { "schema": { - "$ref": "../schemas/LoanInformationRequest.json" + "$ref": "../schemas/NotificationCallbackRequest.json" } } }, @@ -33,12 +33,12 @@ "content": { "application/json": { "schema": { - "$ref": "../schemas/LoanInformationResponse.json" + "$ref": "../schemas/NotificationCallbackResponse.json" } }, "application/xml": { "schema": { - "$ref": "../schemas/LoanInformationResponse.json" + "$ref": "../schemas/NotificationCallbackResponse.json" } } } diff --git a/app/swagger/paths/ProvideLoan.json b/app/swagger/paths/ProvideLoan.json index fc856e9..a201879 100644 --- a/app/swagger/paths/ProvideLoan.json +++ b/app/swagger/paths/ProvideLoan.json @@ -11,17 +11,17 @@ "content": { "application/json": { "schema": { - "$ref": "../schemas/EligibilityCheckRequest.json" + "$ref": "../schemas/ProvideLoanRequest.json" } }, "application/xml": { "schema": { - "$ref": "../schemas/EligibilityCheckRequest.json" + "$ref": "../schemas/ProvideLoanRequest.json" } }, "application/x-www-form-urlencoded": { "schema": { - "$ref": "../schemas/EligibilityCheckRequest.json" + "$ref": "../schemas/ProvideLoanRequest.json" } } }, @@ -33,12 +33,12 @@ "content": { "application/json": { "schema": { - "$ref": "../schemas/EligibilityCheckResponse.json" + "$ref": "../schemas/ProvideLoanResponse.json" } }, "application/xml": { "schema": { - "$ref": "../schemas/EligibilityCheckResponse.json" + "$ref": "../schemas/ProvideLoanResponse.json" } } } diff --git a/app/swagger/schemas/CustomerConsentRequest.json b/app/swagger/schemas/CustomerConsentRequest.json index c8c9e70..a86c53a 100644 --- a/app/swagger/schemas/CustomerConsentRequest.json +++ b/app/swagger/schemas/CustomerConsentRequest.json @@ -1,7 +1,7 @@ { "type": "object", "properties": { - "$type": { + "type": { "type": "string", "example": "CustomerConsentRequest" }, diff --git a/app/swagger/schemas/LoanInformationResponse.json b/app/swagger/schemas/LoanInformationResponse.json deleted file mode 100644 index 528abd9..0000000 --- a/app/swagger/schemas/LoanInformationResponse.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "type": "object", - "properties": { - "transactionId": { - "type": "string", - "example": "Tr201712RK9232P115" - }, - "resultDescription": { - "type": "string", - "example": "Successful" - }, - "resultCode": { - "type": "string", - "example": "00" - }, - "customerId": { - "type": "string", - "example": "CN621868" - }, - "loan": { - "type": "string", - "example": "Arrray of loans" - } - }, - "xml": { - "name": "LoanInformationResponse" - } -} \ No newline at end of file diff --git a/app/swagger/schemas/LoanInformationRequest.json b/app/swagger/schemas/LoanStatusRequest.json similarity index 75% rename from app/swagger/schemas/LoanInformationRequest.json rename to app/swagger/schemas/LoanStatusRequest.json index 70d753c..0252f26 100644 --- a/app/swagger/schemas/LoanInformationRequest.json +++ b/app/swagger/schemas/LoanStatusRequest.json @@ -5,10 +5,6 @@ "type": "string", "example": "Tr201712RK9232P115" }, - "resultDescription": { - "type": "string", - "example": "Successful" - }, "customerId": { "type": "string", "example": "CN621868" @@ -23,6 +19,6 @@ } }, "xml": { - "name": "LoanInformationRequest" + "name": "LoanStatusRequest" } } \ No newline at end of file diff --git a/app/swagger/schemas/LoanStatusResponse.json b/app/swagger/schemas/LoanStatusResponse.json new file mode 100644 index 0000000..6e9e877 --- /dev/null +++ b/app/swagger/schemas/LoanStatusResponse.json @@ -0,0 +1,70 @@ +{ + "type": "object", + "properties": { + "customerId": { + "type": "string", + "example": "CN621868" + }, + "transactionId": { + "type": "string", + "example": "Tr201712RK9232P115" + }, + "loans": { + "type": "array", + "items": { + "type": "object", + "properties": { + "debtId": { + "type": "string", + "example": "123456789" + }, + "loanDate": { + "type": "string", + "format": "date-time", + "example": "2019-10-18 14:26:21.063" + }, + "dueDate": { + "type": "string", + "format": "date-time", + "example": "2019-11-20 14:26:21.063" + }, + "currentLoanAmount": { + "type": "integer", + "example": 8500 + }, + "initialLoanAmount": { + "type": "integer", + "example": 10000 + }, + "defaultPenaltyFee": { + "type": "integer", + "example": 0 + }, + "continuousFee": { + "type": "integer", + "example": 0 + }, + "productId": { + "type": "string", + "example": "101" + } + } + } + }, + "totalDebtAmount": { + "type": "integer", + "example": 8500 + }, + "resultCode": { + "type": "string", + "example": "00" + }, + "resultDescription": { + "type": "string", + "example": "Successful" + } + }, + "xml": { + "name": "LoanStatusResponse" + } +} \ No newline at end of file diff --git a/app/swagger/schemas/ProvideLoanRequest.json b/app/swagger/schemas/ProvideLoanRequest.json index 8d20f34..59be3f5 100644 --- a/app/swagger/schemas/ProvideLoanRequest.json +++ b/app/swagger/schemas/ProvideLoanRequest.json @@ -1,26 +1,35 @@ { "type": "object", "properties": { - "transactionId": { + "requestId": { "type": "string", "example": "202111170001371256908" }, - "accountId": { + "transactionId": { "type": "string", - "example": "ACN8263457" + "example": "Tr201712RK9232P115" }, "customerId": { "type": "string", "example": "CN621868" }, + "accountId": { + "type": "string", + "example": "ACN8263457" + }, "msisdn": { "type": "string", - "example": "9012345678" + "example": "3451342" }, "productId": { "type": "string", "example": "101" }, + "lienAmount": { + "type": "number", + "format": "decimal", + "example": 400 + }, "requestedAmount": { "type": "number", "format": "decimal", @@ -30,13 +39,13 @@ "type": "integer", "example": 1 }, - "offerID": { + "loanType": { "type": "integer", "example": 0 }, "channel": { "type": "string", - "example": "100" + "example": "USSD" } }, "xml": { diff --git a/app/swagger/schemas/RepaymentRequest.json b/app/swagger/schemas/RepaymentRequest.json index c463d70..36d588e 100644 --- a/app/swagger/schemas/RepaymentRequest.json +++ b/app/swagger/schemas/RepaymentRequest.json @@ -1,7 +1,7 @@ { "type": "object", "properties": { - "$type": { + "type": { "type": "string", "example": "RepaymentRequest" },