update
This commit is contained in:
Generated
+1
@@ -3,4 +3,5 @@
|
|||||||
<component name="Black">
|
<component name="Black">
|
||||||
<option name="sdkName" value="Python 3.13 (digifi-FirstCore)" />
|
<option name="sdkName" value="Python 3.13 (digifi-FirstCore)" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (digifi-FirstCore)" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
||||||
@@ -1,14 +1,7 @@
|
|||||||
from flask import Blueprint, request, jsonify, send_from_directory
|
from flask import Blueprint, request, jsonify, send_from_directory
|
||||||
from app.api.services import (
|
from app.api.services import (
|
||||||
EligibilityCheckService,
|
|
||||||
SelectOfferService,
|
|
||||||
ProvideLoanService,
|
|
||||||
LoanStatusService,
|
|
||||||
RepaymentService,
|
|
||||||
CustomerConsentService,
|
|
||||||
NotificationCallbackService,
|
|
||||||
AuthorizationService,
|
AuthorizationService,
|
||||||
TransactionService,
|
TransactionService, LoanService,
|
||||||
)
|
)
|
||||||
from app.utils.logger import logger
|
from app.utils.logger import logger
|
||||||
from app.api.middlewares import enforce_json, require_auth
|
from app.api.middlewares import enforce_json, require_auth
|
||||||
@@ -61,6 +54,25 @@ def get_transactions():
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
# Get All Loans Endpoint
|
||||||
|
@api.route("/loans", methods=["GET"])
|
||||||
|
@jwt_required()
|
||||||
|
def get_loans():
|
||||||
|
# Extract query parameters for filtering
|
||||||
|
filters = {
|
||||||
|
'customer_id': request.args.get('customer_id'),
|
||||||
|
'account_id': request.args.get('account_id'),
|
||||||
|
'offer_id': request.args.get('offer_id'),
|
||||||
|
'status': request.args.get('status'),
|
||||||
|
'start_date': request.args.get('start_date'),
|
||||||
|
'end_date': request.args.get('end_date')
|
||||||
|
}
|
||||||
|
|
||||||
|
# logger.info(f"Get loans request received with filters: {filters}")
|
||||||
|
response = LoanService.process_request(filters)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
# Authorize endpoint
|
# Authorize endpoint
|
||||||
@api.route("/Authorize", methods=["POST"])
|
@api.route("/Authorize", methods=["POST"])
|
||||||
def authorize():
|
def authorize():
|
||||||
|
|||||||
@@ -7,3 +7,4 @@ from app.api.services.customer_consent import CustomerConsentService
|
|||||||
from app.api.services.notification_callback import NotificationCallbackService
|
from app.api.services.notification_callback import NotificationCallbackService
|
||||||
from app.api.services.authorization import AuthorizationService
|
from app.api.services.authorization import AuthorizationService
|
||||||
from app.api.services.transaction import TransactionService
|
from app.api.services.transaction import TransactionService
|
||||||
|
from app.api.services.loan import LoanService
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
from flask import jsonify
|
||||||
|
from app.utils.logger import logger
|
||||||
|
from app.api.services.base_service import BaseService
|
||||||
|
from app.models.loan import Loan
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
class LoanService(BaseService):
|
||||||
|
@staticmethod
|
||||||
|
def process_request(filters=None):
|
||||||
|
"""
|
||||||
|
Process the get loans request.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
filters (dict, optional): Filters for the loans query.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: A standardized response with loans data.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if filters is None:
|
||||||
|
filters = {}
|
||||||
|
|
||||||
|
# Extract filters
|
||||||
|
customer_id = filters.get('customer_id')
|
||||||
|
account_id = filters.get('account_id')
|
||||||
|
offer_id = filters.get('offer_id')
|
||||||
|
status = filters.get('status')
|
||||||
|
start_date = filters.get('start_date')
|
||||||
|
end_date = filters.get('end_date')
|
||||||
|
|
||||||
|
# Convert string dates to datetime objects if provided
|
||||||
|
if start_date and isinstance(start_date, str):
|
||||||
|
start_date = datetime.fromisoformat(start_date.replace('Z', '+00:00'))
|
||||||
|
if end_date and isinstance(end_date, str):
|
||||||
|
end_date = datetime.fromisoformat(end_date.replace('Z', '+00:00'))
|
||||||
|
|
||||||
|
# Get loans with filters
|
||||||
|
query = Loan.query
|
||||||
|
|
||||||
|
if customer_id:
|
||||||
|
query = query.filter(Loan.customer_id == customer_id)
|
||||||
|
|
||||||
|
if account_id:
|
||||||
|
query = query.filter(Loan.account_id == account_id)
|
||||||
|
|
||||||
|
if offer_id:
|
||||||
|
query = query.filter(Loan.offer_id == offer_id)
|
||||||
|
|
||||||
|
if status:
|
||||||
|
query = query.filter(Loan.status == status)
|
||||||
|
|
||||||
|
if start_date:
|
||||||
|
query = query.filter(Loan.created_at >= start_date)
|
||||||
|
|
||||||
|
if end_date:
|
||||||
|
query = query.filter(Loan.created_at <= end_date)
|
||||||
|
|
||||||
|
# Order by created_at descending (newest first)
|
||||||
|
query = query.order_by(Loan.created_at.desc())
|
||||||
|
|
||||||
|
loans = query.all()
|
||||||
|
|
||||||
|
# Convert loans to dictionary format
|
||||||
|
loans_data = []
|
||||||
|
for loan in loans:
|
||||||
|
loans_data.append({
|
||||||
|
'id': loan.id,
|
||||||
|
'customer_id': loan.customer_id,
|
||||||
|
'account_id': loan.account_id,
|
||||||
|
'offer_id': loan.offer_id,
|
||||||
|
'principal_amount': loan.principal_amount,
|
||||||
|
'status': loan.status,
|
||||||
|
'created_at': loan.created_at.isoformat(),
|
||||||
|
'updated_at': loan.updated_at.isoformat()
|
||||||
|
})
|
||||||
|
|
||||||
|
response_data = {
|
||||||
|
'loans': loans_data,
|
||||||
|
'count': len(loans_data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return response_data
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error retrieving loans: {str(e)}", exc_info=True)
|
||||||
|
return jsonify({
|
||||||
|
'status': 'error',
|
||||||
|
'message': f'Failed to retrieve loans: {str(e)}'
|
||||||
|
}), 500
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
from flask import jsonify
|
from flask import jsonify
|
||||||
from marshmallow import ValidationError
|
|
||||||
from app.utils.logger import logger
|
from app.utils.logger import logger
|
||||||
from app.api.services.base_service import BaseService
|
from app.api.services.base_service import BaseService
|
||||||
from app.models.transaction import Transaction
|
from app.models.transaction import Transaction
|
||||||
@@ -62,7 +61,6 @@ class TransactionService(BaseService):
|
|||||||
'count': len(transactions_data)
|
'count': len(transactions_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return response_data
|
return response_data
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user