[add]: account_id to loan status and repayment

This commit is contained in:
VivianDee
2025-04-14 15:26:46 +01:00
parent 6476b62d3c
commit 482a860bd2
4 changed files with 52 additions and 29 deletions
+14 -7
View File
@@ -32,17 +32,24 @@ class LoanStatusService(BaseService):
customer_id = validated_data.get('customerId') customer_id = validated_data.get('customerId')
customer = Customer.get_customer(customer_id) customer = Customer.get_customer(customer_id)
transactionId = validated_data.get('transactionId') transactionId = validated_data.get('transactionId')
account_id = validated_data.get('accountId')
# Get loans if(LoanStatusService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
loans = [loan.to_dict() for loan in customer.loans if loan.status == LoanStatus.ACTIVE]
transaction = LoanStatusService.log_transaction(validated_data = validated_data) # Get loans
loans = [loan.to_dict() for loan in customer.loans if loan.status == LoanStatus.ACTIVE]
if not transaction: transaction = LoanStatusService.log_transaction(validated_data = validated_data)
logger.error(f"Failed to log transaction")
if not transaction:
logger.error(f"Failed to log transaction")
return jsonify({
"message": "Failed to log transaction."
}), 400
else:
return jsonify({ return jsonify({
"message": "Failed to log transaction." "message": "Invalid Customer or Account"
}), 400 }), 400
# loans = [ # loans = [
+30 -22
View File
@@ -2,6 +2,7 @@ from flask import request, jsonify
from marshmallow import ValidationError from marshmallow import ValidationError
from app.api.enums.loan_status import LoanStatus from app.api.enums.loan_status import LoanStatus
from app.models import Repayment from app.models import Repayment
from app.models.customer import Customer
from app.models.loan import Loan from app.models.loan import Loan
from app.utils.logger import logger from app.utils.logger import logger
from app.api.schemas.repayment import RepaymentSchema from app.api.schemas.repayment import RepaymentSchema
@@ -31,35 +32,42 @@ class RepaymentService(BaseService):
request_id = validated_data.get('requestId') request_id = validated_data.get('requestId')
loan_id = validated_data.get('debtId') loan_id = validated_data.get('debtId')
product_id = validated_data.get('productId') product_id = validated_data.get('productId')
account_id = validated_data.get('accountId')
customer = Customer.get_customer(customer_id)
if(RepaymentService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
# Save the repayment details
repayment = Repayment.create_repayment(
customer_id = customer_id,
loan_id = loan_id,
product_id = product_id
)
if not repayment:
logger.error(f"Failed to save repayment details")
return jsonify({
"message": "Failed to save repayment details."
}), 400
#Update Loan status
Loan.update_status(loan_id = loan_id, status = LoanStatus.REPAID)
# Save the repayment details transaction = RepaymentService.log_transaction(validated_data = validated_data)
repayment = Repayment.create_repayment(
customer_id = customer_id,
loan_id = loan_id,
product_id = product_id
) if not transaction:
logger.error(f"Failed to log transaction")
if not repayment: return jsonify({
logger.error(f"Failed to save repayment details") "message": "Failed to log transaction."
}), 400
else:
return jsonify({ return jsonify({
"message": "Failed to save repayment details." "message": "Invalid Customer or Account"
}), 400 }), 400
#Update Loan status
Loan.update_status(loan_id = loan_id, status = LoanStatus.REPAID)
transaction = RepaymentService.log_transaction(validated_data = validated_data)
if not transaction:
logger.error(f"Failed to log transaction")
return jsonify({
"message": "Failed to log transaction."
}), 400
# Simulated processing logic # Simulated processing logic
response_data = { response_data = {
@@ -16,6 +16,10 @@
"channel": { "channel": {
"type": "string", "type": "string",
"example": "USSD" "example": "USSD"
},
"accountId": {
"type": "string",
"example": "ACN8263457"
} }
}, },
"xml": { "xml": {
@@ -24,6 +24,10 @@
"channel": { "channel": {
"type": "string", "type": "string",
"example": "USSD" "example": "USSD"
},
"accountId": {
"type": "string",
"example": "ACN8263457"
} }
}, },
"xml": { "xml": {