Initial commit
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
"""
|
||||
Controller for eligibility check endpoints.
|
||||
"""
|
||||
from flask import Blueprint, request, jsonify, current_app
|
||||
from flask.typing import ResponseReturnValue
|
||||
from api.middleware import basic_auth_required
|
||||
from api.models import EligibilityCheckRequest, EligibilityCheckResponse, EligibleOffer
|
||||
import logging
|
||||
from typing import Dict, Any, List
|
||||
|
||||
# Configure logger
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Create blueprint
|
||||
eligibility_bp = Blueprint('eligibility', __name__)
|
||||
|
||||
@eligibility_bp.route('/EligibilityCheck', methods=['POST'])
|
||||
@basic_auth_required
|
||||
def eligibility_check() -> ResponseReturnValue:
|
||||
"""
|
||||
Endpoint to check customer eligibility for loans.
|
||||
|
||||
This endpoint initiates the eligibility check process and performs RAC checks.
|
||||
|
||||
Returns:
|
||||
JSON response with eligibility status and available offers
|
||||
"""
|
||||
try:
|
||||
# Parse and validate request
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
logger.warning("Invalid JSON payload received")
|
||||
return jsonify({
|
||||
'resultCode': '400',
|
||||
'resultDescription': 'Invalid JSON payload'
|
||||
}), 400
|
||||
|
||||
# Validate required fields
|
||||
required_fields = ['$type', 'transactionId', 'countryCode', 'customerId',
|
||||
'accountId', 'lienAmount', 'channel']
|
||||
missing_fields = [field for field in required_fields if field not in data]
|
||||
if missing_fields:
|
||||
logger.warning(f"Missing required fields: {', '.join(missing_fields)}")
|
||||
return jsonify({
|
||||
'resultCode': '422',
|
||||
'resultDescription': f'Missing required fields: {", ".join(missing_fields)}'
|
||||
}), 422
|
||||
|
||||
# Create request model
|
||||
req = EligibilityCheckRequest.from_dict(data)
|
||||
|
||||
# Process eligibility check (this would connect to the business logic)
|
||||
# For demonstration, we'll return a mock response
|
||||
|
||||
# Create sample offers
|
||||
offers: List[EligibleOffer] = [
|
||||
EligibleOffer(
|
||||
minamount=5000.0,
|
||||
maxamount=20000.0,
|
||||
productId=101,
|
||||
offerid=101,
|
||||
Tenor=30
|
||||
),
|
||||
EligibleOffer(
|
||||
minamount=10000.0,
|
||||
maxamount=50000.0,
|
||||
productId=102,
|
||||
offerid=102,
|
||||
Tenor=60
|
||||
)
|
||||
]
|
||||
|
||||
# Create response
|
||||
response = EligibilityCheckResponse(
|
||||
customerId=req.customerId,
|
||||
transactionId=req.transactionId,
|
||||
eligibleOffers=[offer.to_dict() for offer in offers],
|
||||
resultCode="00",
|
||||
resultDescription="Successful",
|
||||
msisdn=req.msisdn
|
||||
)
|
||||
|
||||
logger.info(f"Processed eligibility check for customer {req.customerId}")
|
||||
return jsonify(response.to_dict())
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(f"Error processing eligibility check: {str(e)}")
|
||||
return jsonify({
|
||||
'resultCode': '500',
|
||||
'resultDescription': f'Internal server error: {str(e)}'
|
||||
}), 500
|
||||
Reference in New Issue
Block a user