[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:
events_service_status = "Connection Successful"
events_service_status = "Connection Failed"
status = "failed"
errors.append(f"Events Service connection failed: {str(e)}")
+56 -13
View File
@@ -143,10 +143,10 @@ class ProvideLoanService(BaseService):
db.session.flush()
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}")
return ResponseHelper.error(result_description="Failed to generate loan repayment schedule.")
@@ -162,16 +162,15 @@ class ProvideLoanService(BaseService):
else:
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.append({
"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(),
})
charge_schedule_items = ProvideLoanService.get_charge_schedule_items(
loan_charges=loan_charges,
offer=offer,
loan_ref=loan_ref,
amount=amount,
schedules=schedules
)
response_data = {
"requestId": request_id,
"transactionId": transaction_id,
@@ -215,4 +214,48 @@ class ProvideLoanService(BaseService):
response = EventServiceIntegration.direct_loan(transaction_id=transaction_id)
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": [
{
"name": "Health",
"description": "System health check including DB status."
},
{
"name": "Authorize",
"description": "This feature will be used for authorizing customers.",
@@ -83,34 +87,9 @@
"description": "Find out more",
"url": "https://www.simbrellang.net"
}
},
{
"name": "Health",
"description": "System health check including DB status."
}
],
"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": {
"get": {
"tags": ["Health"],
@@ -135,7 +114,7 @@
"content": {
"application/json": {
"example": {
"status": "ok",
"status": "failed",
"db_status": "Connection Failed",
"events_service_status": "unhealthy",
"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": {