Merge branch 'testing' of DigiFi/FirstCore into master

This commit is contained in:
2025-04-17 17:51:00 +00:00
committed by Gogs
+57 -43
View File
@@ -1,12 +1,40 @@
from flask import Blueprint, request, jsonify, send_from_directory
from flask import Blueprint, request, jsonify from flask import Blueprint, request, jsonify
from app.api.services.loan import LoanService from app.api.services.loan import LoanService
from app.api.services.transaction import TransactionService from app.api.services.transaction import TransactionService
from app.api.services.auth_service import AuthService from app.api.services.auth_service import AuthService
from app.api.services.dashboard_service import DashboardService from app.api.services.dashboard_service import DashboardService
from functools import wraps from functools import wraps
from app.utils.logger import logger
from app.api.middlewares import enforce_json, require_auth
import os
from flask_jwt_extended import (
JWTManager,
jwt_required,
create_access_token,
get_jwt_identity,
create_refresh_token,
)
api = Blueprint('api', __name__) api = Blueprint('api', __name__)
@api.before_request
def cors_middleware():
"""Middleware applied globally to all API routes in this blueprint"""
return enforce_json()
# Swagger JSON file
@api.route("/swagger.json", methods=["GET"])
def swagger_json():
swagger_dir = os.path.join("swagger")
return send_from_directory(swagger_dir, "digifi_swagger.json")
@api.route("/swagger/<path:filename>")
def serve_paths(filename):
swagger_dir = os.path.join("swagger")
return send_from_directory(swagger_dir, filename)
# JWT Authentication decorator # JWT Authentication decorator
def token_required(f): def token_required(f):
@@ -61,7 +89,7 @@ def login():
@api.route('/dashboard', methods=['GET']) @api.route('/dashboard', methods=['GET'])
@token_required # @token_required
def get_dashboard(): def get_dashboard():
# Call the dashboard service # Call the dashboard service
result = DashboardService.get_dashboard_data() result = DashboardService.get_dashboard_data()
@@ -69,50 +97,36 @@ def get_dashboard():
@api.route('/loans', methods=['GET']) @api.route('/loans', methods=['GET'])
@token_required # @token_required
def get_loans(): def get_loans():
# Extract query parameters # Extract query parameters for filtering
customer_id = request.args.get('customer_id') filters = {
loan_id = request.args.get('loan_id') 'customer_id': request.args.get('customer_id'),
status = request.args.get('status') 'account_id': request.args.get('account_id'),
offer_id = request.args.get('offer_id') 'status': request.args.get('status'),
product_id = request.args.get('product_id') 'offer_id': request.args.get('offer_id'),
start_date = request.args.get('start_date') 'product_id': request.args.get('product_id'),
end_date = request.args.get('end_date') 'start_date': request.args.get('start_date'),
'end_date': request.args.get('end_date'),
# Call the loan service 'due_before': request.args.get('due_before'),
result = LoanService.process_request( 'due_after': request.args.get('due_after')
customer_id=customer_id, }
loan_id=loan_id, # logger.info(f"Get loans request received with filters: {filters}")
status=status, response = LoanService.process_request(filters)
offer_id=offer_id, return response
product_id=product_id,
start_date=start_date,
end_date=end_date
)
return jsonify(result)
@api.route('/transactions', methods=['GET']) @api.route('/transactions', methods=['GET'])
@token_required # @token_required
def get_transactions(): def get_transactions():
# Extract query parameters # Extract query parameters for filtering
account_id = request.args.get('account_id') filters = {
transaction_id = request.args.get('transaction_id') 'account_id': request.args.get('account_id'),
type = request.args.get('type') 'type': request.args.get('type'),
channel = request.args.get('channel') 'channel': request.args.get('channel'),
start_date = request.args.get('start_date') 'start_date': request.args.get('start_date'),
end_date = request.args.get('end_date') 'end_date': request.args.get('end_date')
}
# Call the transaction service # logger.info(f"Get transactions request received with filters: {filters}")
result = TransactionService.process_request( response = TransactionService.process_request(filters)
account_id=account_id, return response
transaction_id=transaction_id,
type=type,
channel=channel,
start_date=start_date,
end_date=end_date
)
return jsonify(result)