[add]: Loan details and repayment fix

This commit is contained in:
VivianDee
2025-04-10 12:20:57 +01:00
parent edd19b9a39
commit 1b973322c9
6 changed files with 80 additions and 33 deletions
+16 -1
View File
@@ -7,6 +7,7 @@ from app.utils.logger import logger
from app.api.schemas.provide_loan import ProvideLoanSchema
from app.api.integrations import KafkaIntegration
from threading import Thread
from app.models.loan import Loan
class ProvideLoanService(BaseService):
@@ -32,8 +33,23 @@ class ProvideLoanService(BaseService):
transaction_id = validated_data.get('transactionId')
if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
# Save the loan details here
loan_id = f"loan_{transaction.id}"
loan = Loan.create_loan(
id=loan_id,
customer_id=customer_id,
account_id=account_id,
product_id=validated_data.get('productId'),
principal_amount=validated_data.get('requestedAmount'),
status="active"
)
transaction = ProvideLoanService.log_transaction(validated_data = validated_data)
if not transaction:
logger.error(f"Failed to log transaction")
return jsonify({
@@ -89,4 +105,3 @@ class ProvideLoanService(BaseService):
KafkaIntegration.send_loan_request(loan_data = loan_data, request_id = request_id)
KafkaIntegration.flush()
+4 -2
View File
@@ -21,10 +21,12 @@ class RepaymentService(BaseService):
"""
try:
validated_data = RepaymentService.validate_data(data, RepaymentSchema())
account_id = validated_data.get('accountId')
customer_id = validated_data.get('customerId')
customer = RepaymentService.get_or_create_customer(validated_data)
account = customer.accounts[0]
if (RepaymentService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
if (RepaymentService.validate_account_ownership(account_id = account.id, customer_id = customer_id)):
transaction = RepaymentService.log_transaction(validated_data = validated_data)
if not transaction:
+1 -1
View File
@@ -3,7 +3,7 @@ from marshmallow import ValidationError
from app.api.services.base_service import BaseService
from app.api.enums import TransactionType
from app.utils.logger import logger
from app.api.schemas.select_offer import SelectOfferSchema
from app.api.schemas.select_offer import SelectOfferSchema
class SelectOfferService(BaseService):
TRANSACTION_TYPE = TransactionType.SELECT_OFFER