[add]: routes and defaults

This commit is contained in:
VivianDee
2025-10-20 16:47:47 +01:00
parent 55140efed8
commit 17c760981a
3 changed files with 83 additions and 40 deletions
+1 -1
View File
@@ -158,7 +158,7 @@ def health_check():
except Exception as e: except Exception as e:
events_service_status = "Connection Successful" events_service_status = "Connection Failed"
status = "failed" status = "failed"
errors.append(f"Events Service connection failed: {str(e)}") errors.append(f"Events Service connection failed: {str(e)}")
+56 -13
View File
@@ -143,10 +143,10 @@ class ProvideLoanService(BaseService):
db.session.flush() db.session.flush()
current_product_id = offer.product_id current_product_id = offer.product_id
schedule = LoanRepaymentSchedule.add_repayment_schedule(loan = loan, num_schedules = num_schedules, transaction_id = transaction_id) schedules = LoanRepaymentSchedule.add_repayment_schedule(loan = loan, num_schedules = num_schedules, transaction_id = transaction_id)
if not schedule: if not schedules:
logger.error(f"Failed to create repayment schedule for loan ID {loan.id}") logger.error(f"Failed to create repayment schedule for loan ID {loan.id}")
return ResponseHelper.error(result_description="Failed to generate loan repayment schedule.") return ResponseHelper.error(result_description="Failed to generate loan repayment schedule.")
@@ -162,16 +162,15 @@ class ProvideLoanService(BaseService):
else: else:
return ResponseHelper.error(result_description="Invalid Customer or Account") return ResponseHelper.error(result_description="Invalid Customer or Account")
charge_schedule_items = []
for idx, charge in enumerate(loan_charges, start=len(charge_schedule_items) + 1): charge_schedule_items = ProvideLoanService.get_charge_schedule_items(
charge_schedule_items.append({ loan_charges=loan_charges,
"id": idx, offer=offer,
"dueDate": charge.due_date.isoformat(), loan_ref=loan_ref,
"amountDue": float(charge.amount), amount=amount,
"componentName": charge.code.upper(), # e.g. INTEREST, MGMT_FEE, VAT_FEE schedules=schedules
"startDate": charge.created_at.isoformat(), )
})
response_data = { response_data = {
"requestId": request_id, "requestId": request_id,
"transactionId": transaction_id, "transactionId": transaction_id,
@@ -215,4 +214,48 @@ class ProvideLoanService(BaseService):
response = EventServiceIntegration.direct_loan(transaction_id=transaction_id) response = EventServiceIntegration.direct_loan(transaction_id=transaction_id)
return response return response
@classmethod
def get_charge_schedule_items(cls, loan_charges, offer, loan_ref, amount, schedules):
now = datetime.now(timezone.utc)
due_date = now + timedelta(days=offer.tenor)
charge_schedule_items = []
charge_schedule_items.append({
"id": 1,
"dueDate": due_date.isoformat(),
"amountDue": amount,
"componentName": "PRINCIPAL",
"startDate": now.isoformat(),
})
for idx, charge in enumerate(loan_charges, start=len(charge_schedule_items) + 1):
item = {
"id": idx,
"dueDate": charge.due_date.isoformat(),
"amountDue": float(charge.amount),
"componentName": charge.code.upper(), # e.g. INTEREST, MGMT_FEE, VAT_FEE
"startDate": charge.created_at.isoformat(),
}
if charge.code.upper() == "INTEREST":
item["loanRef"] = loan_ref
charge_schedule_items.append(item)
for idx, schedule in enumerate(schedules, start=len(charge_schedule_items) + 1):
item = {
"id": idx,
"dueDate": schedule.due_date.isoformat(),
"amountDue": float(schedule.installment_amount),
"componentName": "DEFAULT",
"startDate": schedule.created_at.isoformat(),
"loanRef": loan_ref
}
charge_schedule_items.append(item)
return charge_schedule_items
+26 -26
View File
@@ -28,6 +28,10 @@
} }
], ],
"tags": [ "tags": [
{
"name": "Health",
"description": "System health check including DB status."
},
{ {
"name": "Authorize", "name": "Authorize",
"description": "This feature will be used for authorizing customers.", "description": "This feature will be used for authorizing customers.",
@@ -83,34 +87,9 @@
"description": "Find out more", "description": "Find out more",
"url": "https://www.simbrellang.net" "url": "https://www.simbrellang.net"
} }
},
{
"name": "Health",
"description": "System health check including DB status."
} }
], ],
"paths": { "paths": {
"/Authorize": {
"$ref": "swagger/paths/Authorize.json"
},
"/AuthorizeRefresh": {
"$ref": "swagger/paths/AuthorizeRefresh.json"
},
"/EligibilityCheck": {
"$ref": "swagger/paths/EligibilityCheck.json"
},
"/SelectOffer": {
"$ref": "swagger/paths/SelectOffer.json"
},
"/ProvideLoan": {
"$ref": "swagger/paths/ProvideLoan.json"
},
"/LoanStatus": {
"$ref": "swagger/paths/LoanStatus.json"
},
"/Repayment": {
"$ref": "swagger/paths/Repayment.json"
},
"/health": { "/health": {
"get": { "get": {
"tags": ["Health"], "tags": ["Health"],
@@ -135,7 +114,7 @@
"content": { "content": {
"application/json": { "application/json": {
"example": { "example": {
"status": "ok", "status": "failed",
"db_status": "Connection Failed", "db_status": "Connection Failed",
"events_service_status": "unhealthy", "events_service_status": "unhealthy",
"error":["could not connect to server: Connection refused"] "error":["could not connect to server: Connection refused"]
@@ -145,6 +124,27 @@
} }
} }
} }
},
"/Authorize": {
"$ref": "swagger/paths/Authorize.json"
},
"/AuthorizeRefresh": {
"$ref": "swagger/paths/AuthorizeRefresh.json"
},
"/EligibilityCheck": {
"$ref": "swagger/paths/EligibilityCheck.json"
},
"/SelectOffer": {
"$ref": "swagger/paths/SelectOffer.json"
},
"/ProvideLoan": {
"$ref": "swagger/paths/ProvideLoan.json"
},
"/LoanStatus": {
"$ref": "swagger/paths/LoanStatus.json"
},
"/Repayment": {
"$ref": "swagger/paths/Repayment.json"
} }
}, },
"components": { "components": {