bluprints, schemas,helpers and routes
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
from flask import request
|
||||
from marshmallow import ValidationError
|
||||
from app.utils.logger import logger
|
||||
from app.helpers.response_helper import ResponseHelper
|
||||
from app.schemas.disbursement import DisbursementSchema
|
||||
|
||||
class DisbursementService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process the Disbursement request.
|
||||
|
||||
Args:
|
||||
data (dict): The request data.
|
||||
|
||||
Returns:
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
logger.info("Processing Disbursement request")
|
||||
|
||||
# Validate input data using DisbursementSchema
|
||||
schema = DisbursementSchema()
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated processing logic
|
||||
response_data = {
|
||||
"disbursement_id": validated_data.get("disbursement_id", "11223"),
|
||||
"status": "Completed",
|
||||
"amount": validated_data.get("amount"),
|
||||
"recipient_account": validated_data.get("recipient_account"),
|
||||
}
|
||||
|
||||
# return ResponseHelper.success(
|
||||
# data=response_data,
|
||||
# message="Disbursement completed successfully"
|
||||
# )
|
||||
|
||||
return response_data
|
||||
|
||||
except ValidationError as err:
|
||||
logger.error(f"Validation Error: {err.messages}")
|
||||
return ResponseHelper.error(
|
||||
message="Invalid input data",
|
||||
status_code=400,
|
||||
error=err.messages
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
return ResponseHelper.error(
|
||||
message="An internal error occurred",
|
||||
status_code=500,
|
||||
error=str(e)
|
||||
)
|
||||
Reference in New Issue
Block a user