60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
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, CollectLoanResponseSchema
|
|
|
|
class CollectLoanService:
|
|
@staticmethod
|
|
def process_request(data):
|
|
"""
|
|
Process the CollectLoan request.
|
|
|
|
Args:
|
|
data (dict): The request data.
|
|
|
|
Returns:
|
|
tuple: JSON response and status code.
|
|
"""
|
|
try:
|
|
logger.info("Processing CollectLoan request")
|
|
|
|
# Validate input data using CollectLoanSchema
|
|
schema = CollectLoanSchema()
|
|
validated_data = schema.load(data)
|
|
|
|
# Simulated processing logic
|
|
response_data = {
|
|
"transactionId": validated_data.get("transactionId", "T002"),
|
|
"debtId": validated_data.get("debtId", "273194670"),
|
|
"customerId": validated_data.get("customerId", "CN621868"),
|
|
"accountId": validated_data.get("accountId", "2017821799"),
|
|
"productId": validated_data.get("productId", "101"),
|
|
"amountCollected": validated_data.get("collectAmount", 60000.00),
|
|
"countryId": validated_data.get("countryId", "01"),
|
|
"comment": validated_data.get("comment", "Testing CollectionLoanRequest"),
|
|
"responseCode": "00",
|
|
"responseDescr": "Loan Collection Successful",
|
|
"fullDescription": "Loan collection completed successfully",
|
|
"responseMessage": "Loan collection completed successfully"
|
|
}
|
|
|
|
# Validate and serialize the response data
|
|
response_schema = CollectLoanResponseSchema()
|
|
result = response_schema.dump(response_data)
|
|
|
|
return jsonify(result), 200
|
|
|
|
except ValidationError as err:
|
|
logger.error(f"Validation Error: {err.messages}")
|
|
return jsonify({
|
|
"message": "Validation exception",
|
|
"errors": 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
|