Files
Azeez Muibi ba4d878daf Major update
2025-03-27 08:21:20 +01:00

54 lines
1.8 KiB
Python

from flask import request, jsonify
from marshmallow import ValidationError
from app.utils.logger import logger
from app.api.schemas.penal_charge import PenalChargeSchema, PenalChargeResponseSchema
class PenalChargeService:
@staticmethod
def process_request(data):
"""
Process the PenalCharge request.
Args:
data (dict): The request data.
Returns:
dict: A standardized response.
"""
try:
logger.info("Processing PenalCharge request")
# Validate input data using PenalChargeSchema
schema = PenalChargeSchema()
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 penal charge
# For demonstration, we'll simulate a successful penal charge
response_data = {
"resultCode": "00",
"resultDescription": "Penal charge debited successfully"
}
# Validate the response using the response schema
response_schema = PenalChargeResponseSchema()
validated_response = response_schema.dump(response_data)
return jsonify(validated_response)
except ValidationError as err:
logger.error(f"Validation Error: {err.messages}")
return jsonify({
"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({
"resultCode": "08",
"resultDescription": f"Error occurred: {str(e)}"
}), 500