[add]: Kafka Integration

This commit is contained in:
VivianDee
2025-04-03 10:49:21 +01:00
parent 39d1a1eddc
commit b180f8411d
21 changed files with 131 additions and 26 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ from app.api.services.base_service import BaseService
from app.api.schemas.eligibility_check import EligibilityCheckSchema
from marshmallow import ValidationError
from app.api.enums import TransactionType
from app.api.integrations import SimbrellaClient
from app.api.integrations import SimbrellaIntegration
class EligibilityCheckService(BaseService):
TRANSACTION_TYPE = TransactionType.ELIGIBILITY_CHECK
@@ -42,7 +42,7 @@ class EligibilityCheckService(BaseService):
}), 400
# Call RACCheck
response = SimbrellaClient.rac_check(
response = SimbrellaIntegration.rac_check(
customer_id = customer_id,
account_id = account_id,
transaction_id = transaction.id,
+3 -2
View File
@@ -22,10 +22,11 @@ class LoanStatusService(BaseService):
"""
try:
validated_data = LoanStatusService.validate_data(data, LoanStatusSchema())
account_id = validated_data.get('accountId')
customer_id = validated_data.get('customerId')
customer = LoanStatusService.get_or_create_customer(validated_data)
account = customer.accounts[0]
if (LoanStatusService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
if (LoanStatusService.validate_account_ownership(account_id = account.id, customer_id = customer_id)):
transaction = LoanStatusService.log_transaction(validated_data = validated_data)
if not transaction:
+10 -5
View File
@@ -1,9 +1,11 @@
from flask import request, jsonify
from marshmallow import ValidationError
from app.api.integrations.kafka import KafkaIntegration
from app.api.services.base_service import BaseService
from app.api.enums import TransactionType
from app.utils.logger import logger
from app.api.schemas.provide_loan import ProvideLoanSchema
from app.api.schemas.provide_loan import ProvideLoanSchema
from app.api.integrations import KafkaIntegration
class ProvideLoanService(BaseService):
TRANSACTION_TYPE = TransactionType.PROVIDE_LOAN
@@ -24,6 +26,7 @@ class ProvideLoanService(BaseService):
validated_data = ProvideLoanService.validate_data(data, ProvideLoanSchema())
account_id = validated_data.get('accountId')
customer_id = validated_data.get('customerId')
request_id = validated_data.get('requestId')
if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
transaction = ProvideLoanService.log_transaction(validated_data = validated_data)
@@ -40,16 +43,17 @@ class ProvideLoanService(BaseService):
response_data = {
"requestId": "202111170001371256908",
"requestId": request_id,
"transactionId": "Tr201712RK9232P115",
"customerId": "CN621868",
"accountId": "ACN8263457",
"customerId": customer_id,
"accountId": account_id,
"msisdn": "3451342",
"resultCode": "00",
"resultDescription": "Successful"
}
response = KafkaIntegration.send_loan_request(loan_data = response_data, request_id = request_id)
return response_data
@@ -72,4 +76,5 @@ class ProvideLoanService(BaseService):
logger.error(f"An error occurred: {str(e)}", exc_info=True)
return jsonify({
"message": "Internal Server Error"
}) , 500
}) , 500