Files
digifi-Core/app/app.py
T
CHIEFSOFT\ameye f43c475216 return 200
2025-02-05 13:30:38 -05:00

115 lines
3.6 KiB
Python

# from flask import Flask
from flask_swagger_ui import get_swaggerui_blueprint
import datetime
import jwt
import random
import json
import names
from flask import (
Flask,
jsonify,
send_from_directory,
request,
)
app = Flask(__name__)
SWAGGER_URL = '/api/docs' # URL for exposing Swagger UI (without trailing '/')
API_URL = 'http://petstore.swagger.io/v2/swagger.json' # Our API url (can of course be a local resource)
# Call factory function to create our blueprint
swaggerui_blueprint = get_swaggerui_blueprint(
SWAGGER_URL, # Swagger UI static files will be mapped to '{SWAGGER_URL}/dist/'m
API_URL,
config={ # Swagger UI config overrides
'app_name': "digiFi-Core"
},
# oauth_config={ # OAuth config. See https://github.com/swagger-api/swagger-ui#oauth2-configuration .
# 'clientId': "your-client-id",
# 'clientSecret': "your-client-secret-if-required",
# 'realm': "your-realms",
# 'appName': "your-app-name",
# 'scopeSeparator': " ",
# 'additionalQueryStringParams': {'test': "hello"}
# }
)
app.register_blueprint(swaggerui_blueprint)
@app.route('/')
def hello():
return "Hello World!"
@app.route('/salary/login', methods=["POST"])
def salary_login():
try:
data = request.json
if not data:
return {
"message": "Please provide user details",
"data": None,
"error": "Bad request"
}, 400
# validate input
username = data["username"]
password = data["password"]
if username == 'digifiuser' and password == 'digifipass' :
return {
"message": "Successfully Login",
"data": [
{"uid":"425611f2-c692-4404-b93d-76ca7a5ce70","icon": "icon_user", "name": "Simulator User" , "status": '1', "id": 1}
] }, 201
else:
return {
"message": "Error fetching auth token!, invalid email or password",
"data": None,
"error": "Unauthorized"
}, 404
except Exception as e:
return {
"message": "Something went wrong!",
"error": str(e),
"data": None
}, 500
@app.route('/salary/demousers')
def salary_demousers():
dList = []
for i in range(10):
print(names.get_full_name())
sample_range = random.randint(20, 60)
for x in range(sample_range):
calDate = datetime.datetime.utcnow() + datetime.timedelta(minutes=180 * random.randint(1, 20))
new_l = {
"uid":"425611f2-c692-4404-b93d-76ca7a5ce7"+str(x),
"name": names.get_full_name() ,
"added": calDate, "offers":random.randint(1, 4),
"mobile": '801-000-'+str( random.randint(1000, 9999) ) ,
"bvn": '8315000'+str( random.randint(1000, 9999) ),
"email": 'jerry@example.com' ,
"current_loans" : [],
"salary_account": random.randint(0, 1)
}
dList.append(new_l)
demo_data = {
"last_update": datetime.datetime.utcnow(),
"offers": [
{"cid": "1", "description": "Product Loan 01" },
{"cid": "2", "description": "Product Loan 02" },
{"cid": "3", "description": "Product Loan 03" },
{"cid": "4", "description": "Product Loan 04" },
],
"list" : dList
}
return {
"demo_data": demo_data,
}, 200
# return jsonify(demo_data=demo_data)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)