Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b0c44db524 | |||
| 8638510458 | |||
| 7f6a6350eb | |||
| dbe46a67ff | |||
| bddce977a1 | |||
| 59fc8439b1 | |||
| e2960d5ba1 | |||
| ac4f06436b | |||
| 52fd523739 | |||
| f4bc554396 | |||
| 4a697f14c8 | |||
| e5df8d92d3 | |||
| 3f59ed7da3 | |||
| 0957c2ea37 |
+12
-5
@@ -19,11 +19,18 @@ APP_PORT=4700
|
|||||||
#DATABASE_PORT=5432
|
#DATABASE_PORT=5432
|
||||||
#DATABASE_NAME=firstadvancedev
|
#DATABASE_NAME=firstadvancedev
|
||||||
|
|
||||||
DATABASE_USER=firstadvance
|
DATABASE_USER=system
|
||||||
DATABASE_PASSWORD=FirstAdvance!
|
DATABASE_PASSWORD=FIRSTADV_PASS
|
||||||
DATABASE_HOST=dev-data.simbrellang.net
|
DATABASE_HOST=10.10.33.65
|
||||||
DATABASE_PORT=10532
|
DATABASE_PORT=1521
|
||||||
DATABASE_NAME=firstadvancedev
|
DATABASE_SID=FREE
|
||||||
|
|
||||||
|
|
||||||
|
# DATABASE_USER=firstadvance
|
||||||
|
# DATABASE_PASSWORD=FirstAdvance!
|
||||||
|
# DATABASE_HOST=dev-data.simbrellang.net
|
||||||
|
# DATABASE_PORT=10532
|
||||||
|
# DATABASE_NAME=firstadvancedev
|
||||||
|
|
||||||
|
|
||||||
#Events if Needed
|
#Events if Needed
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ from flask_jwt_extended import (
|
|||||||
get_jwt_identity,
|
get_jwt_identity,
|
||||||
create_refresh_token,
|
create_refresh_token,
|
||||||
)
|
)
|
||||||
|
from sqlalchemy import text
|
||||||
|
from app.extensions import db
|
||||||
|
from app.config import settings
|
||||||
|
|
||||||
api = Blueprint('api', __name__)
|
api = Blueprint('api', __name__)
|
||||||
|
|
||||||
@@ -108,8 +111,8 @@ def get_dashboard():
|
|||||||
def get_loans():
|
def get_loans():
|
||||||
# Extract query parameters for filtering
|
# Extract query parameters for filtering
|
||||||
filters = {
|
filters = {
|
||||||
'id': request.args.get('id'),
|
'username': request.args.get('id'),
|
||||||
'customer_id': request.args.get('customer_id'),
|
'email': request.args.get('customer_id'),
|
||||||
'account_id': request.args.get('account_id'),
|
'account_id': request.args.get('account_id'),
|
||||||
'status': request.args.get('status'),
|
'status': request.args.get('status'),
|
||||||
'tenor': request.args.get('tenor'),
|
'tenor': request.args.get('tenor'),
|
||||||
@@ -129,6 +132,35 @@ def get_loans():
|
|||||||
response = LoanService.process_request(filters)
|
response = LoanService.process_request(filters)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@api.route('/recent-loans', methods=['GET'])
|
||||||
|
# @token_required
|
||||||
|
def get_recent_loans():
|
||||||
|
# Extract query parameters for filtering
|
||||||
|
filters = {
|
||||||
|
'username': request.args.get('id'),
|
||||||
|
'email': request.args.get('customer_id'),
|
||||||
|
'account_id': request.args.get('account_id'),
|
||||||
|
'status': request.args.get('status'),
|
||||||
|
'tenor': request.args.get('tenor'),
|
||||||
|
'offer_id': request.args.get('offer_id'),
|
||||||
|
'product_id': request.args.get('product_id'),
|
||||||
|
'transaction_id': request.args.get('transaction_id'),
|
||||||
|
'original_transaction': request.args.get('original_transaction'),
|
||||||
|
'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'),
|
||||||
|
'page': request.args.get('page', 1),
|
||||||
|
'limit': request.args.get('limit', 20)
|
||||||
|
}
|
||||||
|
# logger.info(f"Get loans request received with filters: {filters}")
|
||||||
|
|
||||||
|
response = LoanService.process_request(filters, True)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@api.route('/transactions', methods=['GET'])
|
@api.route('/transactions', methods=['GET'])
|
||||||
# @token_required
|
# @token_required
|
||||||
def get_transactions():
|
def get_transactions():
|
||||||
@@ -267,3 +299,44 @@ def get_all_offers():
|
|||||||
# # logger.info(f"Get charges request received with filters: {filters}")
|
# # logger.info(f"Get charges request received with filters: {filters}")
|
||||||
# response = ChargeService.get_all_charges(filters)
|
# response = ChargeService.get_all_charges(filters)
|
||||||
# return jsonify(response)
|
# return jsonify(response)
|
||||||
|
|
||||||
|
|
||||||
|
# Health Check Endpoint
|
||||||
|
@api.route("/health", methods=["GET"])
|
||||||
|
def health_check():
|
||||||
|
SQLALCHEMY_DATABASE_URI = settings.SQLALCHEMY_DATABASE_URI
|
||||||
|
response = {}
|
||||||
|
db_status = "Connection Successful"
|
||||||
|
errors = []
|
||||||
|
status = "ok"
|
||||||
|
|
||||||
|
|
||||||
|
# Extract the database URI
|
||||||
|
try:
|
||||||
|
db_uri = db.engine.url.render_as_string(hide_password=False)
|
||||||
|
db_uri = db_uri
|
||||||
|
except Exception as e:
|
||||||
|
db_uri = "Unavailable"
|
||||||
|
errors.append(f"Database URI Error: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Check database connection
|
||||||
|
try:
|
||||||
|
logger.info(f"Database Health == : {SQLALCHEMY_DATABASE_URI}")
|
||||||
|
db.session.execute(text("SELECT 1"))
|
||||||
|
except Exception as e:
|
||||||
|
db_status = "Connection Failed"
|
||||||
|
errors.append(f"Database Error: {str(e)}")
|
||||||
|
status = "failed"
|
||||||
|
|
||||||
|
response = {
|
||||||
|
"status": status,
|
||||||
|
"db_status": db_status,
|
||||||
|
"db_uri": db_uri,
|
||||||
|
"errors": errors or None
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return jsonify(response), 200 if status == "ok" else 500
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ class LoanRepaymentScheduleService:
|
|||||||
'total_repayment_amount': schedule.total_repayment_amount,
|
'total_repayment_amount': schedule.total_repayment_amount,
|
||||||
'paid': schedule.paid,
|
'paid': schedule.paid,
|
||||||
'paid_at': schedule.paid_at.isoformat() if schedule.paid_at else None,
|
'paid_at': schedule.paid_at.isoformat() if schedule.paid_at else None,
|
||||||
|
'penal_charge': schedule.penal_charge,
|
||||||
|
'penal_count': schedule.penal_count,
|
||||||
|
'last_penal_date': schedule.last_penal_date.isoformat() if schedule.last_penal_date else None,
|
||||||
'created_at': schedule.created_at.isoformat() if schedule.created_at else None,
|
'created_at': schedule.created_at.isoformat() if schedule.created_at else None,
|
||||||
'updated_at': schedule.updated_at.isoformat() if schedule.updated_at else None
|
'updated_at': schedule.updated_at.isoformat() if schedule.updated_at else None
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class LoanService:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_request(filters=None):
|
def process_request(filters=None, recent_only=False):
|
||||||
"""
|
"""
|
||||||
Process the get loans request.
|
Process the get loans request.
|
||||||
|
|
||||||
@@ -78,7 +78,8 @@ class LoanService:
|
|||||||
due_before=due_before,
|
due_before=due_before,
|
||||||
due_after=due_after,
|
due_after=due_after,
|
||||||
page=page,
|
page=page,
|
||||||
limit=limit
|
limit=limit,
|
||||||
|
recent_only=recent_only,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(f"Result from loans model cme back ")
|
logger.info(f"Result from loans model cme back ")
|
||||||
@@ -115,6 +116,8 @@ class LoanService:
|
|||||||
'verifyDescription': loan.verify_description,
|
'verifyDescription': loan.verify_description,
|
||||||
'disburseDate': loan.disburse_date.isoformat() if loan.disburse_date else None,
|
'disburseDate': loan.disburse_date.isoformat() if loan.disburse_date else None,
|
||||||
'disburseVerify': loan.disburse_verify.isoformat() if loan.disburse_verify else None,
|
'disburseVerify': loan.disburse_verify.isoformat() if loan.disburse_verify else None,
|
||||||
|
'totalPenalCharge': loan.total_penal_charge,
|
||||||
|
'lastPenalDate': loan.last_penal_date.isoformat() if loan.last_penal_date else None,
|
||||||
})
|
})
|
||||||
|
|
||||||
# Calculate total pages
|
# Calculate total pages
|
||||||
|
|||||||
+8
-1
@@ -19,8 +19,15 @@ class Config:
|
|||||||
DATABASE_HOST = os.environ.get("DATABASE_HOST")
|
DATABASE_HOST = os.environ.get("DATABASE_HOST")
|
||||||
DATABASE_PORT = os.environ.get("DATABASE_PORT", 10532)
|
DATABASE_PORT = os.environ.get("DATABASE_PORT", 10532)
|
||||||
DATABASE_NAME = os.environ.get("DATABASE_NAME")
|
DATABASE_NAME = os.environ.get("DATABASE_NAME")
|
||||||
|
DATABASE_SID = os.environ.get("DATABASE_SID", "FREE")
|
||||||
|
DNS = f"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={DATABASE_HOST})(PORT={DATABASE_PORT}))(CONNECT_DATA=(SID={DATABASE_SID})))"
|
||||||
|
|
||||||
|
|
||||||
|
# SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DATABASE_USER}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}"
|
||||||
|
SQLALCHEMY_DATABASE_URI_INTERNAL = (f"oracle+oracledb://{DATABASE_USER}:{DATABASE_PASSWORD}@{DNS}")
|
||||||
|
SQLALCHEMY_DATABASE_URI = os.getenv("SQLALCHEMY_DATABASE_URI_FULL", SQLALCHEMY_DATABASE_URI_INTERNAL)
|
||||||
|
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DATABASE_USER}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}"
|
|
||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
SIMBRELLA_BASE_URL = os.getenv("SIMBRELLA_BASE_URL", "http://127.0.0.1:6337")
|
SIMBRELLA_BASE_URL = os.getenv("SIMBRELLA_BASE_URL", "http://127.0.0.1:6337")
|
||||||
|
|
||||||
|
|||||||
+46
-35
@@ -45,6 +45,10 @@ class Loan(db.Model):
|
|||||||
reference = db.Column(db.String(50), nullable=True)
|
reference = db.Column(db.String(50), nullable=True)
|
||||||
balance = db.Column(db.Float, nullable=True, default=0.0)
|
balance = db.Column(db.Float, nullable=True, default=0.0)
|
||||||
|
|
||||||
|
total_penal_charge = db.Column(db.Float, default=0.0)
|
||||||
|
last_penal_date = db.Column(db.DateTime, nullable=True)
|
||||||
|
|
||||||
|
|
||||||
customer = relationship(
|
customer = relationship(
|
||||||
"Customer",
|
"Customer",
|
||||||
primaryjoin="Customer.id == Loan.customer_id",
|
primaryjoin="Customer.id == Loan.customer_id",
|
||||||
@@ -55,7 +59,7 @@ class Loan(db.Model):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_all_loans(cls, id=None, customer_id=None, account_id=None, status=None, tenor=None, offer_id=None,
|
def get_all_loans(cls, id=None, customer_id=None, account_id=None, status=None, tenor=None, offer_id=None,
|
||||||
product_id=None, start_date=None, end_date=None, due_before=None, due_after=None,
|
product_id=None, start_date=None, end_date=None, due_before=None, due_after=None,
|
||||||
transaction_id=None, original_transaction=None, page=1, limit=20):
|
transaction_id=None, original_transaction=None, page=1, limit=20, recent_only= False):
|
||||||
"""
|
"""
|
||||||
Get all loans with optional filtering
|
Get all loans with optional filtering
|
||||||
|
|
||||||
@@ -79,55 +83,60 @@ class Loan(db.Model):
|
|||||||
"""
|
"""
|
||||||
query = cls.query
|
query = cls.query
|
||||||
logger.info(f"Get all loan models from loans model cme back")
|
logger.info(f"Get all loan models from loans model cme back")
|
||||||
# Apply filters if provided
|
if recent_only:
|
||||||
if id:
|
query = query.order_by(cls.created_at.desc()).limit(10)
|
||||||
query = query.filter(cls.id == id)
|
# Get total count before pagination
|
||||||
|
total_count = query.count()
|
||||||
|
else:
|
||||||
|
# Apply filters if provided
|
||||||
|
if id:
|
||||||
|
query = query.filter(cls.id == id)
|
||||||
|
|
||||||
if customer_id:
|
if customer_id:
|
||||||
query = query.filter(cls.customer_id == customer_id)
|
query = query.filter(cls.customer_id == customer_id)
|
||||||
|
|
||||||
if account_id:
|
if account_id:
|
||||||
query = query.filter(cls.account_id == account_id)
|
query = query.filter(cls.account_id == account_id)
|
||||||
|
|
||||||
if status:
|
if status:
|
||||||
query = query.filter(cls.status == status)
|
query = query.filter(cls.status == status)
|
||||||
|
|
||||||
if tenor:
|
if tenor:
|
||||||
query = query.filter(cls.tenor == tenor)
|
query = query.filter(cls.tenor == tenor)
|
||||||
|
|
||||||
if offer_id:
|
if offer_id:
|
||||||
query = query.filter(cls.offer_id == offer_id)
|
query = query.filter(cls.offer_id == offer_id)
|
||||||
|
|
||||||
if product_id:
|
if product_id:
|
||||||
query = query.filter(cls.product_id == product_id)
|
query = query.filter(cls.product_id == product_id)
|
||||||
|
|
||||||
if transaction_id:
|
if transaction_id:
|
||||||
query = query.filter(cls.transaction_id == transaction_id)
|
query = query.filter(cls.transaction_id == transaction_id)
|
||||||
|
|
||||||
if original_transaction:
|
if original_transaction:
|
||||||
query = query.filter(cls.original_transaction == original_transaction)
|
query = query.filter(cls.original_transaction == original_transaction)
|
||||||
|
|
||||||
if start_date:
|
if start_date:
|
||||||
query = query.filter(cls.created_at >= start_date)
|
query = query.filter(cls.created_at >= start_date)
|
||||||
|
|
||||||
if end_date:
|
if end_date:
|
||||||
query = query.filter(cls.created_at <= end_date)
|
query = query.filter(cls.created_at <= end_date)
|
||||||
|
|
||||||
if due_before:
|
if due_before:
|
||||||
query = query.filter(cls.due_date <= due_before)
|
query = query.filter(cls.due_date <= due_before)
|
||||||
|
|
||||||
if due_after:
|
if due_after:
|
||||||
query = query.filter(cls.due_date >= due_after)
|
query = query.filter(cls.due_date >= due_after)
|
||||||
|
|
||||||
# Order by created_at descending (newest first)
|
# Order by created_at descending (newest first)
|
||||||
query = query.order_by(cls.created_at.desc())
|
query = query.order_by(cls.created_at.desc())
|
||||||
|
|
||||||
# Get total count before pagination
|
# Get total count before pagination
|
||||||
total_count = query.count()
|
total_count = query.count()
|
||||||
|
|
||||||
# Apply pagination
|
# Apply pagination
|
||||||
offset = (page - 1) * limit
|
offset = (page - 1) * limit
|
||||||
query = query.limit(limit).offset(offset)
|
query = query.limit(limit).offset(offset)
|
||||||
|
|
||||||
return query.all(), total_count
|
return query.all(), total_count
|
||||||
|
|
||||||
@@ -164,6 +173,8 @@ class Loan(db.Model):
|
|||||||
'disburseVerify': self.disburse_verify.isoformat() if self.disburse_verify else None,
|
'disburseVerify': self.disburse_verify.isoformat() if self.disburse_verify else None,
|
||||||
'reference': self.reference,
|
'reference': self.reference,
|
||||||
'balance': self.balance,
|
'balance': self.balance,
|
||||||
|
'totalPenalCharge': self.total_penal_charge,
|
||||||
|
'lastPenalDate': self.last_penal_date.isoformat() if self.last_penal_date else None,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ class LoanRepaymentSchedule(db.Model):
|
|||||||
created_at = db.Column(db.DateTime, default=datetime.now(timezone.utc))
|
created_at = db.Column(db.DateTime, default=datetime.now(timezone.utc))
|
||||||
updated_at = db.Column(db.DateTime, default=datetime.now(timezone.utc), onupdate=datetime.now(timezone.utc))
|
updated_at = db.Column(db.DateTime, default=datetime.now(timezone.utc), onupdate=datetime.now(timezone.utc))
|
||||||
|
|
||||||
|
|
||||||
|
penal_charge = db.Column(db.Float, default=0.0)
|
||||||
|
penal_count = db.Column(db.Integer, default=0)
|
||||||
|
last_penal_date = db.Column(db.DateTime, nullable=True)
|
||||||
|
|
||||||
|
|
||||||
# loan = relationship(
|
# loan = relationship(
|
||||||
# "Loan",
|
# "Loan",
|
||||||
# primaryjoin="LoanRepaymentSchedule.loan_id == Loan.id",
|
# primaryjoin="LoanRepaymentSchedule.loan_id == Loan.id",
|
||||||
@@ -96,6 +102,9 @@ class LoanRepaymentSchedule(db.Model):
|
|||||||
'total_repayment_amount': self.total_repayment_amount,
|
'total_repayment_amount': self.total_repayment_amount,
|
||||||
'paid': self.paid,
|
'paid': self.paid,
|
||||||
'paid_at': self.paid_at.isoformat() if self.paid_at else None,
|
'paid_at': self.paid_at.isoformat() if self.paid_at else None,
|
||||||
|
'penal_charge': self.penal_charge,
|
||||||
|
'penal_count': self.penal_count,
|
||||||
|
'last_penal_date': self.last_penal_date.isoformat() if self.last_penal_date else None,
|
||||||
'created_at': self.created_at.isoformat() if self.created_at else None,
|
'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||||
'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,14 +33,17 @@
|
|||||||
"url": "http://www.simbrellang.net:14700"
|
"url": "http://www.simbrellang.net:14700"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url" : "http://10.10.11.17:4300"
|
"url": "http://10.10.11.17:4300"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url" : "http://10.10.11.17:4700"
|
"url": "http://10.10.11.17:4700"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://10.2.249.133:4700"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
{
|
{
|
||||||
"name": "Authorize",
|
"name": "Authorize",
|
||||||
"description": "This feature will be used for authorizing customers.",
|
"description": "This feature will be used for authorizing customers.",
|
||||||
"externalDocs": {
|
"externalDocs": {
|
||||||
@@ -103,6 +106,10 @@
|
|||||||
"description": "Find out more",
|
"description": "Find out more",
|
||||||
"url": "https://www.simbrellang.net"
|
"url": "https://www.simbrellang.net"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Health",
|
||||||
|
"description": "System health check including DB status."
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
@@ -138,6 +145,43 @@
|
|||||||
},
|
},
|
||||||
"/transaction-offers": {
|
"/transaction-offers": {
|
||||||
"$ref": "../swagger/paths/TransactionOffers.json"
|
"$ref": "../swagger/paths/TransactionOffers.json"
|
||||||
|
},
|
||||||
|
"/health": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Health"
|
||||||
|
],
|
||||||
|
"summary": "Health Check",
|
||||||
|
"description": "Returns service health information including DB connection status.",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Health check successful",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"example": {
|
||||||
|
"status": "ok",
|
||||||
|
"db_status": "Connection Successful",
|
||||||
|
"error": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Health check failed",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"example": {
|
||||||
|
"status": "ok",
|
||||||
|
"db_status": "Connection Failed",
|
||||||
|
"error": [
|
||||||
|
"could not connect to server: Connection refused"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ flask-sqlalchemy
|
|||||||
flask-migrate
|
flask-migrate
|
||||||
psycopg2-binary
|
psycopg2-binary
|
||||||
alembic
|
alembic
|
||||||
|
oracledb
|
||||||
|
|
||||||
# Schema for validations
|
# Schema for validations
|
||||||
Flask-Marshmallow==0.15.0
|
Flask-Marshmallow==0.15.0
|
||||||
|
|||||||
Reference in New Issue
Block a user