Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b48ccacd7c | |||
| c0f1845c5d | |||
| cfc40b89dc | |||
| eb7c0f6221 | |||
| d69bcd11ea |
@@ -1,4 +1,5 @@
|
|||||||
from flask import Flask, Blueprint, request, jsonify, send_from_directory
|
from flask import Flask, Blueprint, request, jsonify, send_from_directory
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
from app.api.services import (
|
from app.api.services import (
|
||||||
RACCheckService,
|
RACCheckService,
|
||||||
@@ -16,6 +17,7 @@ from app.utils.logger import logger
|
|||||||
from app.api.middlewares import require_api_key, require_app_id, enforce_json
|
from app.api.middlewares import require_api_key, require_app_id, enforce_json
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
api = Blueprint("api", __name__)
|
api = Blueprint("api", __name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -162,7 +164,34 @@ def new_transaction_check():
|
|||||||
response = NewTransactionCheckService.process_request(data)
|
response = NewTransactionCheckService.process_request(data)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
# Health Check Endpoint
|
# Health Check Endpoint
|
||||||
@api.route('/health', methods=['GET'])
|
@api.route('/system-health-check', methods=['GET'])
|
||||||
def health_check():
|
def health_check():
|
||||||
return {"status": "ok"} , 200
|
"""Basic system health check"""
|
||||||
|
try:
|
||||||
|
checks = {
|
||||||
|
"python_version": sys.version_info >= (3, 6),
|
||||||
|
"disk_space": os.statvfs('/').f_bavail * os.statvfs('/').f_frsize > 500 * 1024 * 1024,
|
||||||
|
"system_operational": True
|
||||||
|
}
|
||||||
|
|
||||||
|
if all(checks.values()):
|
||||||
|
return jsonify({
|
||||||
|
"status": "Active",
|
||||||
|
"responseCode": "00",
|
||||||
|
"responseMessage": "Successful"
|
||||||
|
}), 200
|
||||||
|
else:
|
||||||
|
return jsonify({
|
||||||
|
"status": "Degraded",
|
||||||
|
"responseCode": "01",
|
||||||
|
"responseMessage": "System check failed"
|
||||||
|
}), 200
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({
|
||||||
|
"status": "Error",
|
||||||
|
"responseCode": "99",
|
||||||
|
"responseMessage": f"Health check failed: {str(e)}"
|
||||||
|
}), 500
|
||||||
|
|||||||
@@ -16,15 +16,20 @@ class CollectLoanSchema(Schema):
|
|||||||
comment = fields.Str(allow_none=True)
|
comment = fields.Str(allow_none=True)
|
||||||
|
|
||||||
class CollectLoanResponseSchema(Schema):
|
class CollectLoanResponseSchema(Schema):
|
||||||
responseCode = fields.Str(allow_none=True)
|
|
||||||
responseDescr = fields.Str(allow_none=True)
|
|
||||||
fullDescription = fields.Str(allow_none=True)
|
|
||||||
transactionId = fields.Str(allow_none=True)
|
transactionId = fields.Str(allow_none=True)
|
||||||
|
fbnTransactionId = fields.Str(allow_none=True)
|
||||||
debtId = fields.Str(allow_none=True)
|
debtId = fields.Str(allow_none=True)
|
||||||
customerId = fields.Str(allow_none=True)
|
customerId = fields.Str(allow_none=True)
|
||||||
accountId = fields.Str(allow_none=True)
|
accountId = fields.Str(allow_none=True)
|
||||||
productId = fields.Str(allow_none=True)
|
productId = fields.Str(allow_none=True)
|
||||||
amountCollected = fields.Float(required=True)
|
amountCollected = fields.Float(required=True)
|
||||||
|
interestCollected = fields.Float(required=True)
|
||||||
|
penalChargeCollected = fields.Float(required=True)
|
||||||
|
lienAmount = fields.Float(required=True)
|
||||||
countryId = fields.Str(allow_none=True)
|
countryId = fields.Str(allow_none=True)
|
||||||
comment = fields.Str(allow_none=True)
|
comment = fields.Str(allow_none=True)
|
||||||
|
responseCode = fields.Str(allow_none=True)
|
||||||
responseMessage = fields.Str(allow_none=True)
|
responseMessage = fields.Str(allow_none=True)
|
||||||
|
responseDescr = fields.Str(allow_none=True)
|
||||||
|
fullDescription = fields.Str(allow_none=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import random
|
||||||
from flask import request, jsonify
|
from flask import request, jsonify
|
||||||
from marshmallow import ValidationError
|
from marshmallow import ValidationError
|
||||||
from app.utils.logger import logger
|
from app.utils.logger import logger
|
||||||
from app.api.helpers.response_helper import ResponseHelper
|
from app.api.helpers.response_helper import ResponseHelper
|
||||||
from app.api.schemas.collect_loan import CollectLoanSchema, CollectLoanResponseSchema
|
from app.api.schemas.collect_loan import CollectLoanSchema, CollectLoanResponseSchema
|
||||||
|
from app.config import Config
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Process the CollectLoan request.
|
Process the CollectLoan request.
|
||||||
@@ -24,51 +26,62 @@ class CollectLoanService:
|
|||||||
validated_data = schema.load(data)
|
validated_data = schema.load(data)
|
||||||
|
|
||||||
amountForCollection = validated_data.get("collectAmount")
|
amountForCollection = validated_data.get("collectAmount")
|
||||||
|
productId = validated_data.get("productId")
|
||||||
|
customerId = validated_data.get("customerId")
|
||||||
amountCollected = amountForCollection
|
amountCollected = amountForCollection
|
||||||
responseDescr= "Loan Collection Successful EMULATOR"
|
responseDescr= "Loan Collection Successful EMULATOR"
|
||||||
fullDescription= "Loan collection completed successfully EMULATOR"
|
fullDescription= "Loan collection completed successfully EMULATOR"
|
||||||
responseMessage= "Loan collection completed successfully EMULATOR"
|
responseMessage= "Loan collection completed successfully EMULATOR"
|
||||||
|
interestCollected = amountForCollection * 0.03
|
||||||
|
lienAmount = validated_data.get("lienAmount", 0)
|
||||||
|
|
||||||
|
isValid = not (
|
||||||
if amountForCollection in [5555.0, 6666.0, 7777.0, 8888.0 , 9999.0, 22222.0] :
|
int(customerId[-1]) in [2, 7, 9]
|
||||||
amountCollected = amountForCollection * 0.85
|
)
|
||||||
|
if Config.MIN_AMOUNT_FOR_COLLECTION <= amountForCollection <= Config.MAX_AMOUNT_FOR_COLLECTION:
|
||||||
|
amountCollected = amountForCollection if lienAmount >= amountForCollection else 0
|
||||||
responseDescr = "Partial Loan Collection Successful EMULATOR"
|
responseDescr = "Partial Loan Collection Successful EMULATOR"
|
||||||
fullDescription = "Partial Loan collection completed successfully EMULATOR"
|
fullDescription = "Partial Loan collection completed successfully EMULATOR"
|
||||||
responseMessage = "Partial Loan collection completed successfully EMULATOR"
|
responseMessage = "Partial Loan collection completed successfully EMULATOR"
|
||||||
|
|
||||||
# Simulated processing logic
|
response_data = {
|
||||||
response_data = {
|
"transactionId": validated_data.get("transactionId"),
|
||||||
"transactionId": validated_data.get("transactionId"),
|
"fbnTransactionId": validated_data.get("fbnTransactionId"),
|
||||||
"debtId": validated_data.get("debtId"),
|
"debtId": validated_data.get("debtId"),
|
||||||
"customerId": validated_data.get("customerId"),
|
"customerId": validated_data.get("customerId"),
|
||||||
"accountId": validated_data.get("accountId"),
|
"accountId": validated_data.get("accountId"),
|
||||||
"productId": validated_data.get("productId"),
|
"productId": validated_data.get("productId"),
|
||||||
"amountCollected": amountCollected,
|
"amountCollected": amountCollected,
|
||||||
"countryId": validated_data.get("countryId"),
|
"interestCollected": interestCollected,
|
||||||
"comment": validated_data.get("comment", "Testing CollectionLoanRequest EMULATOR"),
|
"penalChargeCollected": 0,
|
||||||
"responseCode": "00",
|
"lienAmount": lienAmount if amountCollected == 0 else 0,
|
||||||
"responseDescr": responseDescr,
|
"countryId": validated_data.get("countryId"),
|
||||||
"fullDescription": fullDescription,
|
"comment": validated_data.get("comment", "Testing CollectionLoanRequest EMULATOR"),
|
||||||
"responseMessage": responseMessage
|
"responseCode": "00",
|
||||||
}
|
"responseDescr": responseDescr,
|
||||||
|
"fullDescription": fullDescription,
|
||||||
|
"responseMessage": responseMessage
|
||||||
|
}
|
||||||
|
|
||||||
# # Simulated processing logic
|
else:
|
||||||
# response_data = {
|
response_data = {
|
||||||
# "transactionId": validated_data.get("transactionId", "T002"),
|
"transactionId": validated_data.get("transactionId"),
|
||||||
# "debtId": validated_data.get("debtId", "273194670"),
|
"fbnTransactionId": validated_data.get("fbnTransactionId"),
|
||||||
# "customerId": validated_data.get("customerId", "CN621868"),
|
"debtId": validated_data.get("debtId"),
|
||||||
# "accountId": validated_data.get("accountId", "2017821799"),
|
"customerId": validated_data.get("customerId"),
|
||||||
# "productId": validated_data.get("productId", "101"),
|
"accountId": validated_data.get("accountId"),
|
||||||
# "amountCollected": validated_data.get("collectAmount", 60000.00),
|
"productId": validated_data.get("productId"),
|
||||||
# "countryId": validated_data.get("countryId", "01"),
|
"amountCollected": amountCollected,
|
||||||
# "comment": validated_data.get("comment", "Testing CollectionLoanRequest"),
|
"interestCollected": interestCollected,
|
||||||
# "responseCode": "00",
|
"penalChargeCollected": 0,
|
||||||
# "responseDescr": "Loan Collection Successful",
|
"amountCollected": amountCollected,
|
||||||
# "fullDescription": "Loan collection completed successfully",
|
"countryId": validated_data.get("countryId"),
|
||||||
# "responseMessage": "Loan collection completed successfully"
|
"comment": validated_data.get("comment", "Testing CollectionLoanRequest EMULATOR"),
|
||||||
# }
|
"responseCode": "00",
|
||||||
#
|
"responseDescr": responseDescr,
|
||||||
|
"fullDescription": fullDescription,
|
||||||
|
"responseMessage": responseMessage
|
||||||
|
}
|
||||||
|
|
||||||
# Validate and serialize the response data
|
# Validate and serialize the response data
|
||||||
response_schema = CollectLoanResponseSchema()
|
response_schema = CollectLoanResponseSchema()
|
||||||
|
|||||||
@@ -26,9 +26,7 @@ class RACCheckService:
|
|||||||
validated_data = schema.load(data)
|
validated_data = schema.load(data)
|
||||||
|
|
||||||
customer_id = validated_data["customerId"]
|
customer_id = validated_data["customerId"]
|
||||||
is_valid = not (
|
is_valid = True
|
||||||
int(customer_id[-1]) in [2, 7, 9]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -42,7 +40,7 @@ class RACCheckService:
|
|||||||
total_salary = 0
|
total_salary = 0
|
||||||
|
|
||||||
for i in range(1, salary_count + 1):
|
for i in range(1, salary_count + 1):
|
||||||
salary = ((salary_count + i ) * 7919) % 200000 + 10000
|
salary = (((salary_count + i) * 7919) % 200000 + 10000) * 5
|
||||||
salary_payments[f"salarypaymenT_{i}"] = salary
|
salary_payments[f"salarypaymenT_{i}"] = salary
|
||||||
total_salary += salary
|
total_salary += salary
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
from re import M
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@@ -10,6 +11,8 @@ class Config:
|
|||||||
DEBUG = True
|
DEBUG = True
|
||||||
VALID_APP_ID = os.getenv("VALID_APP_ID", "app1")
|
VALID_APP_ID = os.getenv("VALID_APP_ID", "app1")
|
||||||
VALID_API_KEY = os.getenv("VALID_API_KEY", "test-api-key-12345")
|
VALID_API_KEY = os.getenv("VALID_API_KEY", "test-api-key-12345")
|
||||||
|
MIN_AMOUNT_FOR_COLLECTION = int(os.getenv("MIN_AMOUNT_FOR_COLLECTION", 10000))
|
||||||
|
MAX_AMOUNT_FOR_COLLECTION = int(os.getenv("MAX_AMOUNT_FOR_COLLECTION", 25000))
|
||||||
|
|
||||||
# SQLALCHEMY_DATABASE_URI =os.environ.get("DATABASE_URL", "database_url")
|
# SQLALCHEMY_DATABASE_URI =os.environ.get("DATABASE_URL", "database_url")
|
||||||
# SQLALCHEMY_TRACK_MODIFICATIONS = False
|
# SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
|
|||||||
@@ -110,6 +110,9 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"/api/system-health-check": {
|
||||||
|
"$ref": "swagger/paths/HealthCheck.json"
|
||||||
|
},
|
||||||
"/api/rac-check": {
|
"/api/rac-check": {
|
||||||
"$ref": "swagger/paths/RACCheck.json"
|
"$ref": "swagger/paths/RACCheck.json"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"get": {
|
||||||
|
"tags": ["System"],
|
||||||
|
"summary": "System Health Check",
|
||||||
|
"description": "Returns the current health status of the system",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Successful operation",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "../schemas/HealthCheckResponse.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"status": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Active"
|
||||||
|
},
|
||||||
|
"responseCode": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "00"
|
||||||
|
},
|
||||||
|
"responseMessage": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Successful"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"status": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Active"
|
||||||
|
},
|
||||||
|
"responseCode": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "00"
|
||||||
|
},
|
||||||
|
"responseMessage": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "Successful"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user