Major update

This commit is contained in:
Azeez Muibi
2025-03-27 08:21:20 +01:00
parent 1a36416094
commit ba4d878daf
24 changed files with 776 additions and 254 deletions
+30 -24
View File
@@ -1,8 +1,8 @@
from flask import request, jsonify
from marshmallow import ValidationError
from app.utils.logger import logger
from app.api.helpers.response_helper import ResponseHelper
from app.api.schemas.collect_loan import CollectLoanSchema
from app.api.schemas.collect_loan import CollectLoanSchema, CollectLoanResponseSchema
class CollectLoanService:
@staticmethod
@@ -21,41 +21,47 @@ class CollectLoanService:
# Validate input data using CollectLoanSchema
schema = CollectLoanSchema()
validated_data = schema.load(data)
validated_data = schema.load(data) # Raises ValidationError if invalid
# Simulated processing logic
# In a real implementation, this would interact with your business logic
# to process the loan collection
# For demonstration, we'll simulate a partial collection
collect_amount = validated_data.get('collectAmount') * 0.75 # 75% of requested amount
lien_amount = validated_data.get('lienAmount') * 0.25 # 25% of requested amount as lien
response_data = {
"transactionId": "T002",
"debtId": "273194670",
"customerId": "CN621868",
"accountId": "2017821799",
"productId": "101",
"collectAmount": 60000.00,
"penalCharge": 0,
"lienAmount": 20000,
"countryId": "01",
"comment": "Testing CollectionLoanRequest",
"transactionId": validated_data.get('transactionId'),
"debtId": validated_data.get('debtId'),
"customerId": validated_data.get('customerId'),
"accountId": validated_data.get('accountId'),
"productId": validated_data.get('productId'),
"collectAmount": collect_amount,
"penalCharge": validated_data.get('penalCharge', 0),
"lienAmount": lien_amount,
"countryId": validated_data.get('countryId'),
"comment": validated_data.get('comment', ""),
"resultCode": "00",
"resultDescription": "Loan Collection Successful"
}
# Validate the response using the response schema
response_schema = CollectLoanResponseSchema()
validated_response = response_schema.dump(response_data)
# return ResponseHelper.success(
# data=response_data,
# message="Loan collection completed successfully"
# )
return response_data
return jsonify(validated_response)
except ValidationError as err:
logger.error(f"Validation Error: {err.messages}")
return jsonify({
"message": "Validation exception"
}) , 422
"resultCode": "01",
"resultDescription": f"Validation error: {err.messages}"
}), 422
except Exception as e:
logger.error(f"An error occurred: {str(e)}", exc_info=True)
return jsonify({
"message": "Internal Server Error"
}) , 500
"resultCode": "08",
"resultDescription": f"Error occurred: {str(e)}"
}), 500