fis path
This commit is contained in:
@@ -2,6 +2,8 @@ from flask import Blueprint, request, jsonify, send_from_directory
|
||||
from app.api.services import (
|
||||
LoginService,
|
||||
RegisterService,
|
||||
AccountService,
|
||||
ProductsService,
|
||||
EligibilityCheckService,
|
||||
SelectOfferService,
|
||||
ProvideLoanService,
|
||||
@@ -31,7 +33,6 @@ 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():
|
||||
@@ -59,6 +60,35 @@ def merms_register():
|
||||
response = RegisterService.process_request(data)
|
||||
return response
|
||||
|
||||
@api.route("/panel/RegisterVerify", methods=["POST"])
|
||||
@jwt_required()
|
||||
def merms_register_verify():
|
||||
data = request.get_json()
|
||||
response = RegisterService.process_request(data)
|
||||
return response
|
||||
|
||||
@api.route("/panel/RegisterComplete", methods=["POST"])
|
||||
@jwt_required()
|
||||
def merms_register_complete():
|
||||
data = request.get_json()
|
||||
response = RegisterService.process_request(data)
|
||||
return response
|
||||
|
||||
@api.route("/panel/Account", methods=["GET"])
|
||||
@jwt_required()
|
||||
def merms_account():
|
||||
data = request.get_json()
|
||||
response = AccountService.process_request(data)
|
||||
return response
|
||||
|
||||
@api.route("/panel/Products", methods=["GET"])
|
||||
@jwt_required()
|
||||
def merms_products():
|
||||
data = request.get_json()
|
||||
response = ProductsService.process_request(data)
|
||||
return response
|
||||
|
||||
|
||||
# EligibilityCheck Endpoint
|
||||
@api.route("/EligibilityCheck", methods=["POST"])
|
||||
@jwt_required()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
from marshmallow import Schema, fields
|
||||
|
||||
class ProductsSchema(Schema):
|
||||
email = fields.Str(required=True)
|
||||
firstname = fields.Str(required=True)
|
||||
lastname = fields.Str(required=True)
|
||||
isChecked = fields.Str(required=True)
|
||||
@@ -0,0 +1,5 @@
|
||||
from marshmallow import Schema, fields
|
||||
|
||||
class UserSchema(Schema):
|
||||
token = fields.Str(required=True)
|
||||
uid = fields.Str(required=True)
|
||||
@@ -8,4 +8,6 @@ from app.api.services.notification_callback import NotificationCallbackService
|
||||
from app.api.services.authorization import AuthorizationService
|
||||
from app.api.services.offer_analysis import OfferAnalysis
|
||||
from app.api.services.login import LoginService
|
||||
from app.api.services.register import RegisterService
|
||||
from app.api.services.register import RegisterService
|
||||
from app.api.services.products import ProductsService
|
||||
from app.api.services.account import AccountService
|
||||
@@ -0,0 +1,59 @@
|
||||
from flask import session, jsonify
|
||||
from app.models.loan import Loan
|
||||
from app.utils.logger import logger
|
||||
from app.api.services.base_service import BaseService
|
||||
from app.api.schemas.eligibility_check import EligibilityCheckSchema
|
||||
from marshmallow import ValidationError
|
||||
from app.api.enums import TransactionType
|
||||
from app.api.integrations import SimbrellaIntegration
|
||||
from app.extensions import db
|
||||
from app.models import Offer, RACCheck, Members
|
||||
from app.api.services.offer_analysis import OfferAnalysis
|
||||
from app.api.helpers.response_helper import ResponseHelper
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from app.api.schemas.user import UserSchema
|
||||
|
||||
import datetime
|
||||
import jwt
|
||||
import random
|
||||
from app.config import Config
|
||||
|
||||
|
||||
class AccountService(BaseService):
|
||||
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
|
||||
try:
|
||||
with db.session.begin():
|
||||
|
||||
validated_data = RegisterService.validate_data(data, UserSchema())
|
||||
# username = validated_data.get('username')
|
||||
# password = validated_data.get('password')
|
||||
|
||||
|
||||
# Simulate processing
|
||||
response_data = {
|
||||
"member_id": 0,
|
||||
"uid": 0,
|
||||
}
|
||||
|
||||
return ResponseHelper.success(data=response_data)
|
||||
|
||||
except ValidationError as err:
|
||||
|
||||
logger.error(f"Validation Error: {getattr(err, 'messages', str(err))}")
|
||||
db.session.rollback()
|
||||
return ResponseHelper.unprocessable_entity(result_description="Validation exception")
|
||||
|
||||
except ValueError as err:
|
||||
logger.error(f"{getattr(err, 'messages', str(err))}")
|
||||
db.session.rollback()
|
||||
return ResponseHelper.error(result_description=str(err))
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
db.session.rollback()
|
||||
return ResponseHelper.internal_server_error()
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
from flask import session, jsonify
|
||||
from app.models.loan import Loan
|
||||
from app.utils.logger import logger
|
||||
from app.api.services.base_service import BaseService
|
||||
from app.api.schemas.eligibility_check import EligibilityCheckSchema
|
||||
from marshmallow import ValidationError
|
||||
from app.api.enums import TransactionType
|
||||
from app.api.integrations import SimbrellaIntegration
|
||||
from app.extensions import db
|
||||
from app.models import Offer, RACCheck, Members
|
||||
from app.api.services.offer_analysis import OfferAnalysis
|
||||
from app.api.helpers.response_helper import ResponseHelper
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from app.api.schemas.register import RegisterSchema
|
||||
from app.api.schemas.products import ProductsSchema
|
||||
|
||||
import datetime
|
||||
import jwt
|
||||
import random
|
||||
from app.config import Config
|
||||
|
||||
|
||||
class ProductsService(BaseService):
|
||||
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process the Login request.
|
||||
|
||||
Args:
|
||||
data (dict): The request data.
|
||||
|
||||
Returns:
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
|
||||
user_id = 1 # current_user["user"]["id"]
|
||||
PRODUCT_LIST = f"""SELECT p.id,p.uid,p.product_id,p.name,p.description,p.status,p.banner,
|
||||
mp.status AS prov_status,
|
||||
(CASE WHEN mp.status =6 THEN 'Preparing' WHEN mp.status=7 THEN 'Active' ELSE 'Activate Now' END) AS status_text
|
||||
FROM products p
|
||||
LEFT JOIN members_products mp ON mp.product_id = p.product_id
|
||||
AND mp.member_id ={user_id}
|
||||
ORDER BY p.id ASC"""
|
||||
print(PRODUCT_LIST)
|
||||
|
||||
with db.session.begin():
|
||||
|
||||
validated_data = RegisterService.validate_data(data, ProductsSchema())
|
||||
# username = validated_data.get('username')
|
||||
# password = validated_data.get('password')
|
||||
|
||||
|
||||
# Simulate processing
|
||||
response_data = {
|
||||
"member_id": 0,
|
||||
"uid": 0,
|
||||
}
|
||||
|
||||
return ResponseHelper.success(data=response_data)
|
||||
|
||||
except ValidationError as err:
|
||||
|
||||
logger.error(f"Validation Error: {getattr(err, 'messages', str(err))}")
|
||||
db.session.rollback()
|
||||
return ResponseHelper.unprocessable_entity(result_description="Validation exception")
|
||||
|
||||
except ValueError as err:
|
||||
logger.error(f"{getattr(err, 'messages', str(err))}")
|
||||
db.session.rollback()
|
||||
return ResponseHelper.error(result_description=str(err))
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
db.session.rollback()
|
||||
return ResponseHelper.internal_server_error()
|
||||
|
||||
@staticmethod
|
||||
def check_loan_limits(customer_id):
|
||||
"""
|
||||
Checks if a customer has exceeded the loan limits for given offer.
|
||||
"""
|
||||
loan = Loan.get_customer_last_loan(customer_id)
|
||||
|
||||
if not loan:
|
||||
return True
|
||||
|
||||
offer_id = loan.offer_id[:5]
|
||||
|
||||
offer = Offer.get_offer_by_id(offer_id)
|
||||
if not offer:
|
||||
logger.error(f"Offer not found for offer_id: {offer_id} (customer_id: {customer_id})")
|
||||
return False
|
||||
|
||||
daily_count = Loan.get_daily_loan_count(customer_id, offer.product_id)
|
||||
|
||||
logger.info(f"daily_count: {daily_count}, Max: {offer.max_daily_loans}")
|
||||
|
||||
if offer.max_daily_loans is not None and daily_count >= offer.max_daily_loans:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
# {
|
||||
# "email": "ameye@chiefsoft.com",
|
||||
# "firstname": "Olusesan",
|
||||
# "lastname": "Ameye",
|
||||
# "isChecked": true
|
||||
# }
|
||||
Reference in New Issue
Block a user