Merge branch 'testing' of DigiFi/FirstCore into master
This commit is contained in:
+57
-43
@@ -1,12 +1,40 @@
|
||||
from flask import Blueprint, request, jsonify, send_from_directory
|
||||
from flask import Blueprint, request, jsonify
|
||||
from app.api.services.loan import LoanService
|
||||
from app.api.services.transaction import TransactionService
|
||||
from app.api.services.auth_service import AuthService
|
||||
from app.api.services.dashboard_service import DashboardService
|
||||
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.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
|
||||
def token_required(f):
|
||||
@@ -61,7 +89,7 @@ def login():
|
||||
|
||||
|
||||
@api.route('/dashboard', methods=['GET'])
|
||||
@token_required
|
||||
# @token_required
|
||||
def get_dashboard():
|
||||
# Call the dashboard service
|
||||
result = DashboardService.get_dashboard_data()
|
||||
@@ -69,50 +97,36 @@ def get_dashboard():
|
||||
|
||||
|
||||
@api.route('/loans', methods=['GET'])
|
||||
@token_required
|
||||
# @token_required
|
||||
def get_loans():
|
||||
# Extract query parameters
|
||||
customer_id = request.args.get('customer_id')
|
||||
loan_id = request.args.get('loan_id')
|
||||
status = request.args.get('status')
|
||||
offer_id = request.args.get('offer_id')
|
||||
product_id = request.args.get('product_id')
|
||||
start_date = request.args.get('start_date')
|
||||
end_date = request.args.get('end_date')
|
||||
|
||||
# Call the loan service
|
||||
result = LoanService.process_request(
|
||||
customer_id=customer_id,
|
||||
loan_id=loan_id,
|
||||
status=status,
|
||||
offer_id=offer_id,
|
||||
product_id=product_id,
|
||||
start_date=start_date,
|
||||
end_date=end_date
|
||||
)
|
||||
|
||||
return jsonify(result)
|
||||
# Extract query parameters for filtering
|
||||
filters = {
|
||||
'customer_id': request.args.get('customer_id'),
|
||||
'account_id': request.args.get('account_id'),
|
||||
'status': request.args.get('status'),
|
||||
'offer_id': request.args.get('offer_id'),
|
||||
'product_id': request.args.get('product_id'),
|
||||
'start_date': request.args.get('start_date'),
|
||||
'end_date': request.args.get('end_date'),
|
||||
'due_before': request.args.get('due_before'),
|
||||
'due_after': request.args.get('due_after')
|
||||
}
|
||||
# logger.info(f"Get loans request received with filters: {filters}")
|
||||
response = LoanService.process_request(filters)
|
||||
return response
|
||||
|
||||
|
||||
@api.route('/transactions', methods=['GET'])
|
||||
@token_required
|
||||
# @token_required
|
||||
def get_transactions():
|
||||
# Extract query parameters
|
||||
account_id = request.args.get('account_id')
|
||||
transaction_id = request.args.get('transaction_id')
|
||||
type = request.args.get('type')
|
||||
channel = request.args.get('channel')
|
||||
start_date = request.args.get('start_date')
|
||||
end_date = request.args.get('end_date')
|
||||
|
||||
# Call the transaction service
|
||||
result = TransactionService.process_request(
|
||||
account_id=account_id,
|
||||
transaction_id=transaction_id,
|
||||
type=type,
|
||||
channel=channel,
|
||||
start_date=start_date,
|
||||
end_date=end_date
|
||||
)
|
||||
|
||||
return jsonify(result)
|
||||
# Extract query parameters for filtering
|
||||
filters = {
|
||||
'account_id': request.args.get('account_id'),
|
||||
'type': request.args.get('type'),
|
||||
'channel': request.args.get('channel'),
|
||||
'start_date': request.args.get('start_date'),
|
||||
'end_date': request.args.get('end_date')
|
||||
}
|
||||
# logger.info(f"Get transactions request received with filters: {filters}")
|
||||
response = TransactionService.process_request(filters)
|
||||
return response
|
||||
Reference in New Issue
Block a user