Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f59ed7da3 | |||
| 0957c2ea37 | |||
| 2d6ff1adc2 | |||
| 6bed4d2dfa | |||
| bbb919d933 | |||
| 2c46a4390c | |||
| fac6a80284 |
+32
-17
@@ -1,26 +1,41 @@
|
||||
VALID_APP_ID=**********
|
||||
VALID_API_KEY=*************
|
||||
BASIC_AUTH_USERNAME=******
|
||||
BASIC_AUTH_PASSWORD=******
|
||||
|
||||
SIMBRELLA_BASE_URL=***************
|
||||
|
||||
# Environment Variables
|
||||
BASIC_AUTH_USERNAME=user
|
||||
BASIC_AUTH_PASSWORD=password
|
||||
SWAGGER_URL="/documentation"
|
||||
API_URL="/swagger.json"
|
||||
|
||||
JWT_SECRET_KEY=******
|
||||
JWT_ACCESS_TOKEN_EXPIRES=******
|
||||
JWT_REFRESH_TOKEN_EXPIRES=******
|
||||
|
||||
|
||||
DATABASE_USER=*****
|
||||
DATABASE_PASSWORD=*****
|
||||
DATABASE_HOST=******
|
||||
DATABASE_PORT=******
|
||||
DATABASE_NAME=*****
|
||||
|
||||
# Flask Configuration
|
||||
FLASK_APP=wsgi.py
|
||||
FLASK_ENV=development
|
||||
APP_PORT=4500
|
||||
APP_PORT=4700
|
||||
|
||||
#Database Configuration
|
||||
#DATABASE_USER=firstadvance
|
||||
#DATABASE_PASSWORD=FirstAdvance!
|
||||
#DATABASE_HOST=10.20.30.60
|
||||
#DATABASE_PORT=5432
|
||||
#DATABASE_NAME=firstadvancedev
|
||||
|
||||
DATABASE_USER=system
|
||||
DATABASE_PASSWORD=FIRSTADV_PASS
|
||||
DATABASE_HOST=10.10.33.65
|
||||
DATABASE_PORT=1521
|
||||
DATABASE_SID=FREE
|
||||
|
||||
|
||||
# DATABASE_USER=firstadvance
|
||||
# DATABASE_PASSWORD=FirstAdvance!
|
||||
# DATABASE_HOST=dev-data.simbrellang.net
|
||||
# DATABASE_PORT=10532
|
||||
# DATABASE_NAME=firstadvancedev
|
||||
|
||||
|
||||
#Events if Needed
|
||||
KAFKA_TIMEOUT=45000.0
|
||||
KAFKA_BROKER="10.20.30.50:9092"
|
||||
|
||||
|
||||
|
||||
SIMBRELLA_BASE_URL=***************
|
||||
+6
-3
@@ -18,7 +18,10 @@ ENV FLASK_APP=app.py
|
||||
ENV FLASK_RUN_HOST=0.0.0.0
|
||||
|
||||
#COPY scripts/enterypointone.sh scripts/enterypointone.sh
|
||||
#RUN chmod +x scripts/entry.sh
|
||||
#ENTRYPOINT ["scripts/entry.sh"]
|
||||
|
||||
RUN chmod +x scripts/enterypointone.sh
|
||||
|
||||
ENTRYPOINT ["scripts/enterypointone.sh"]
|
||||
# Run the application
|
||||
CMD [ "sh", "-c", \
|
||||
"echo 'Starting Gunicorn server...' && \
|
||||
exec gunicorn -w 4 -b 0.0.0.0:5000 wsgi:wsgi_app"]
|
||||
|
||||
@@ -123,7 +123,8 @@ def get_loans():
|
||||
'page': request.args.get('page', 1),
|
||||
'limit': request.args.get('limit', 20)
|
||||
}
|
||||
# logger.info(f"Get loans request received with filters: {filters}")
|
||||
#logger.info(f"Get loans request received with filters: {filters}")
|
||||
|
||||
response = LoanService.process_request(filters)
|
||||
return response
|
||||
|
||||
|
||||
@@ -4,34 +4,30 @@ from app.api.services.base_service import BaseService
|
||||
from app.models.transaction import Transaction
|
||||
from app.models.loan import Loan
|
||||
from sqlalchemy import func, desc
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from app.extensions import db
|
||||
from app.api.enums.transaction_type import TransactionType
|
||||
|
||||
|
||||
class DashboardService(BaseService):
|
||||
@staticmethod
|
||||
def get_dashboard_data():
|
||||
"""
|
||||
Get dashboard summary data.
|
||||
|
||||
Returns:
|
||||
dict: A standardized response with dashboard data.
|
||||
"""
|
||||
try:
|
||||
# Get current date and start of the week
|
||||
now = datetime.now()
|
||||
start_of_week = now - timedelta(days=now.weekday())
|
||||
start_of_week = start_of_week.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
||||
# Get loans data for the current week
|
||||
# Calculate 24 hours ago
|
||||
last_24_hours = datetime.now(timezone.utc) - timedelta(hours=24)
|
||||
|
||||
# Loans this week
|
||||
loans_this_week = db.session.query(
|
||||
func.sum(Loan.initial_loan_amount)
|
||||
).filter(
|
||||
Loan.created_at >= start_of_week
|
||||
).scalar() or 0
|
||||
|
||||
# Get payments data for the current week
|
||||
# Assuming payments are transactions with type 'PAYMENT'
|
||||
# Payments this week
|
||||
payments_this_week = db.session.query(
|
||||
func.count(Transaction.id)
|
||||
).filter(
|
||||
@@ -39,51 +35,53 @@ class DashboardService(BaseService):
|
||||
Transaction.type == 'PAYMENT'
|
||||
).scalar() or 0
|
||||
|
||||
# Get request summary counts
|
||||
# These are placeholders - needed to adjust based on your actual data model
|
||||
|
||||
# Request summary for the last 24 hours
|
||||
eligibility_check_count = db.session.query(
|
||||
func.count(Transaction.id)
|
||||
).filter(
|
||||
Transaction.type == 'ELIGIBILITY_CHECK'
|
||||
Transaction.type == TransactionType.ELIGIBILITY_CHECK.value,
|
||||
Transaction.created_at >= last_24_hours
|
||||
).scalar() or 0
|
||||
|
||||
select_offer_count = db.session.query(
|
||||
func.count(Transaction.id)
|
||||
).filter(
|
||||
Transaction.type == 'SELECT_OFFER'
|
||||
Transaction.type == TransactionType.SELECT_OFFER.value,
|
||||
Transaction.created_at >= last_24_hours
|
||||
).scalar() or 0
|
||||
|
||||
provide_loan_count = db.session.query(
|
||||
func.count(Transaction.id)
|
||||
).filter(
|
||||
Transaction.type == 'PROVIDE_LOAN'
|
||||
Transaction.type == TransactionType.PROVIDE_LOAN.value,
|
||||
Transaction.created_at >= last_24_hours
|
||||
).scalar() or 0
|
||||
|
||||
repayment_count = db.session.query(
|
||||
func.count(Transaction.id)
|
||||
).filter(
|
||||
Transaction.type == 'REPAYMENT'
|
||||
Transaction.type == TransactionType.REPAYMENT.value,
|
||||
Transaction.created_at >= last_24_hours
|
||||
).scalar() or 0
|
||||
|
||||
|
||||
# Get recent transactions
|
||||
# Recent transactions (not limited to 24 hrs, just latest 15)
|
||||
recent_transactions = Transaction.query.order_by(
|
||||
Transaction.id.desc()
|
||||
).limit(15).all()
|
||||
|
||||
# Format recent transactions
|
||||
recent_transactions_data = []
|
||||
for transaction in recent_transactions:
|
||||
recent_transactions_data.append({
|
||||
'id': transaction.id,
|
||||
'transaction_id': transaction.transaction_id,
|
||||
'account_id': transaction.account_id,
|
||||
'type': transaction.type,
|
||||
'channel': transaction.channel,
|
||||
'created_at': transaction.created_at.isoformat() if transaction.created_at else None,
|
||||
'updated_at': transaction.updated_at.isoformat() if transaction.updated_at else None
|
||||
})
|
||||
recent_transactions_data = [{
|
||||
'id': t.id,
|
||||
'transaction_id': t.transaction_id,
|
||||
'account_id': t.account_id,
|
||||
'type': t.type,
|
||||
'channel': t.channel,
|
||||
'created_at': t.created_at.isoformat() if t.created_at else None,
|
||||
'updated_at': t.updated_at.isoformat() if t.updated_at else None
|
||||
} for t in recent_transactions]
|
||||
|
||||
# Prepare response data
|
||||
# Final response
|
||||
dashboard_data = {
|
||||
"loans": {
|
||||
"value": float(loans_this_week),
|
||||
@@ -110,6 +108,4 @@ class DashboardService(BaseService):
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred while getting dashboard data: {str(e)}", exc_info=True)
|
||||
return jsonify({
|
||||
"message": "Internal Server Error"
|
||||
}), 500
|
||||
return jsonify({"message": "Internal Server Error"}), 500
|
||||
|
||||
@@ -81,7 +81,7 @@ class LoanService:
|
||||
limit=limit
|
||||
)
|
||||
|
||||
logger.info(f"Result from loans model cme back")
|
||||
logger.info(f"Result from loans model cme back ")
|
||||
|
||||
# Convert loans to dictionary format
|
||||
loans_data = []
|
||||
@@ -98,6 +98,8 @@ class LoanService:
|
||||
'current_loan_amount': loan.current_loan_amount,
|
||||
'status': loan.status,
|
||||
'tenor': loan.tenor,
|
||||
'balance': loan.balance,
|
||||
'reference': loan.reference,
|
||||
'product_id': loan.product_id,
|
||||
'default_penalty_fee': loan.default_penalty_fee,
|
||||
'continuous_fee': loan.continuous_fee,
|
||||
@@ -106,7 +108,13 @@ class LoanService:
|
||||
'installment_amount': loan.installment_amount,
|
||||
'due_date': loan.due_date.isoformat() if loan.due_date else None,
|
||||
'created_at': loan.created_at.isoformat() if loan.created_at else None,
|
||||
'updated_at': loan.updated_at.isoformat() if loan.updated_at else None
|
||||
'updated_at': loan.updated_at.isoformat() if loan.updated_at else None,
|
||||
'disburseResult': loan.disburse_result,
|
||||
'disburseDescription': loan.disburse_description,
|
||||
'verifyResult': loan.verify_result,
|
||||
'verifyDescription': loan.verify_description,
|
||||
'disburseDate': loan.disburse_date.isoformat() if loan.disburse_date else None,
|
||||
'disburseVerify': loan.disburse_verify.isoformat() if loan.disburse_verify else None,
|
||||
})
|
||||
|
||||
# Calculate total pages
|
||||
|
||||
@@ -69,7 +69,15 @@ class RepaymentService:
|
||||
'product_id': repayment.product_id,
|
||||
'transaction_id': repayment.transaction_id,
|
||||
'created_at': repayment.created_at.isoformat() if repayment.created_at else None,
|
||||
'updated_at': repayment.updated_at.isoformat() if repayment.updated_at else None
|
||||
'updated_at': repayment.updated_at.isoformat() if repayment.updated_at else None,
|
||||
'repay_date': repayment.repay_date.isoformat() if repayment.repay_date else None,
|
||||
'initiated_by': repayment.initiated_by,
|
||||
'salary_amount': repayment.salary_amount,
|
||||
'verify_date': repayment.verify_date.isoformat() if repayment.verify_date else None,
|
||||
'repay_result': repayment.repay_result,
|
||||
'repay_description': repayment.repay_description,
|
||||
'verify_result': repayment.verify_result,
|
||||
'verify_description': repayment.verify_description
|
||||
})
|
||||
|
||||
# Calculate total pages
|
||||
|
||||
@@ -72,6 +72,7 @@ class TransactionService:
|
||||
'transaction_id': transaction.transaction_id,
|
||||
'account_id': transaction.account_id,
|
||||
'type': transaction.type,
|
||||
'customer_id': transaction.customer_id,
|
||||
'channel': transaction.channel,
|
||||
'created_at': transaction.created_at.isoformat(),
|
||||
'updated_at': transaction.updated_at.isoformat()
|
||||
|
||||
+6
-1
@@ -19,8 +19,13 @@ class Config:
|
||||
DATABASE_HOST = os.environ.get("DATABASE_HOST")
|
||||
DATABASE_PORT = os.environ.get("DATABASE_PORT", 10532)
|
||||
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 = (f"oracle+oracledb://{DATABASE_USER}:{DATABASE_PASSWORD}@{DNS}")
|
||||
|
||||
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DATABASE_USER}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}"
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
SIMBRELLA_BASE_URL = os.getenv("SIMBRELLA_BASE_URL", "http://127.0.0.1:6337")
|
||||
|
||||
|
||||
+17
-1
@@ -36,6 +36,14 @@ class Loan(db.Model):
|
||||
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))
|
||||
eligible_amount = db.Column(db.Float, nullable=True, default=0.0)
|
||||
disburse_date = db.Column(db.DateTime, nullable=True)
|
||||
disburse_verify = db.Column(db.DateTime, nullable=True)
|
||||
disburse_result = db.Column(db.String(10), nullable=True)
|
||||
disburse_description = db.Column(db.String(100), nullable=True)
|
||||
verify_result = db.Column(db.String(10), nullable=True)
|
||||
verify_description = db.Column(db.String(100), nullable=True)
|
||||
reference = db.Column(db.String(50), nullable=True)
|
||||
balance = db.Column(db.Float, nullable=True, default=0.0)
|
||||
|
||||
customer = relationship(
|
||||
"Customer",
|
||||
@@ -147,7 +155,15 @@ class Loan(db.Model):
|
||||
'installment_amount': self.installment_amount,
|
||||
'due_date': self.due_date.isoformat() if self.due_date 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,
|
||||
'disburseResult': self.disburse_result,
|
||||
'disburseDescription': self.disburse_description,
|
||||
'verifyResult': self.verify_result,
|
||||
'verifyDescription': self.verify_description,
|
||||
'disburseDate': self.disburse_date.isoformat() if self.disburse_date else None,
|
||||
'disburseVerify': self.disburse_verify.isoformat() if self.disburse_verify else None,
|
||||
'reference': self.reference,
|
||||
'balance': self.balance,
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
+18
-1
@@ -12,6 +12,14 @@ class Repayment(db.Model):
|
||||
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))
|
||||
transaction_id = db.Column(db.String(50))
|
||||
repay_date = db.Column(db.DateTime, nullable=True)
|
||||
initiated_by = db.Column(db.String(50), nullable=True)
|
||||
salary_amount = db.Column(db.Float, nullable=True, default=0.0)
|
||||
verify_date = db.Column(db.DateTime, nullable=True)
|
||||
repay_result = db.Column(db.String(10), nullable=True)
|
||||
repay_description = db.Column(db.String(100), nullable=True)
|
||||
verify_result = db.Column(db.String(10), nullable=True)
|
||||
verify_description = db.Column(db.String(100), nullable=True)
|
||||
|
||||
@classmethod
|
||||
def get_all_repayments(cls, loan_id=None, customer_id=None, product_id=None,
|
||||
@@ -71,7 +79,16 @@ class Repayment(db.Model):
|
||||
'product_id': self.product_id,
|
||||
'transaction_id': self.transaction_id,
|
||||
'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,
|
||||
'repay_date': self.repay_date.isoformat() if self.repay_date else None,
|
||||
'initiated_by': self.initiated_by,
|
||||
'salary_amount': self.salary_amount,
|
||||
'verify_date': self.verify_date.isoformat() if self.verify_date else None,
|
||||
'repay_result': self.repay_result,
|
||||
'repay_description': self.repay_description,
|
||||
'verify_result': self.verify_result,
|
||||
'verify_description': self.verify_description
|
||||
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@@ -76,6 +76,17 @@
|
||||
"example": 10500.0,
|
||||
"nullable": true
|
||||
},
|
||||
"balance": {
|
||||
"type": "number",
|
||||
"format": "float",
|
||||
"example": 5000.0,
|
||||
"nullable": true
|
||||
},
|
||||
"reference": {
|
||||
"type": "string",
|
||||
"example": "REF12345",
|
||||
"nullable": true
|
||||
},
|
||||
"installment_amount": {
|
||||
"type": "number",
|
||||
"format": "float",
|
||||
|
||||
@@ -23,6 +23,50 @@
|
||||
"example": "TRX123456",
|
||||
"nullable": true
|
||||
},
|
||||
"initiated_by": {
|
||||
"type": "string",
|
||||
"example": "system",
|
||||
"nullable": true
|
||||
},
|
||||
"salary_amount": {
|
||||
"type": "number",
|
||||
"format": "float",
|
||||
"example": 1000.0,
|
||||
"nullable": true
|
||||
},
|
||||
"repay_date": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"example": "2025-04-10T16:45:47.879552Z",
|
||||
"nullable": true
|
||||
},
|
||||
"verify_date": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"example": "2025-04-10T16:45:47.879552Z",
|
||||
"nullable": true
|
||||
},
|
||||
"repay_result": {
|
||||
"type": "string",
|
||||
"example": "success",
|
||||
"nullable": true
|
||||
},
|
||||
"repay_description": {
|
||||
"type": "string",
|
||||
"example": "Repayment processed successfully",
|
||||
"nullable": true
|
||||
},
|
||||
"verify_result": {
|
||||
"type": "string",
|
||||
"example": "verified",
|
||||
"nullable": true
|
||||
},
|
||||
"verify_description": {
|
||||
"type": "string",
|
||||
"example": "Verification completed successfully",
|
||||
"nullable": true
|
||||
},
|
||||
|
||||
"created_at": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
|
||||
@@ -6,6 +6,7 @@ flask-sqlalchemy
|
||||
flask-migrate
|
||||
psycopg2-binary
|
||||
alembic
|
||||
oracledb
|
||||
|
||||
# Schema for validations
|
||||
Flask-Marshmallow==0.15.0
|
||||
|
||||
Reference in New Issue
Block a user