[update]: Loan Status

This commit was merged in pull request #8.
This commit is contained in:
VivianDee
2025-04-11 15:54:26 +01:00
parent e69335cb71
commit 6476b62d3c
7 changed files with 148 additions and 27 deletions
+8 -2
View File
@@ -1,5 +1,6 @@
from flask import request, jsonify
from marshmallow import ValidationError
from app.api.enums.loan_status import LoanStatus
from app.models import Customer
from app.utils.logger import logger
from app.api.schemas.loan_status import LoanStatusSchema
@@ -33,7 +34,7 @@ class LoanStatusService(BaseService):
transactionId = validated_data.get('transactionId')
# Get loans
loans = [loan.to_dict() for loan in customer.loans]
loans = [loan.to_dict() for loan in customer.loans if loan.status == LoanStatus.ACTIVE]
transaction = LoanStatusService.log_transaction(validated_data = validated_data)
@@ -57,12 +58,17 @@ class LoanStatusService(BaseService):
# }
# ]
total_debt_amount = sum(
loan.get("currentLoanAmount") or 0
for loan in loans
)
# Simulated processing logic
response_data = {
"customerId": customer_id,
"transactionId": transactionId,
"loans": loans,
"totalDebtAmount": 8500,
"totalDebtAmount": total_debt_amount,
"resultCode": "00",
"resultDescription": "Successful"
}
+8 -5
View File
@@ -31,6 +31,7 @@ class ProvideLoanService(BaseService):
account_id = validated_data.get('accountId')
customer_id = validated_data.get('customerId')
request_id = validated_data.get('requestId')
collection_type = validated_data.get('collectionType')
transaction_id = validated_data.get('transactionId')
if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
@@ -38,11 +39,13 @@ class ProvideLoanService(BaseService):
# Save the loan details
loan = Loan.create_loan(
customer_id=customer_id,
account_id=account_id,
offer_id=validated_data.get('offerId'),
principal_amount=validated_data.get('requestedAmount'),
status=LoanStatus.ACTIVE
customer_id = customer_id,
account_id = account_id,
offer_id = validated_data.get('offerId'),
collection_type = collection_type,
transaction_id = validated_data.get('transactionId'),
initial_loan_amount = validated_data.get('requestedAmount'),
status= LoanStatus.ACTIVE
)
if not loan: