added query support
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
CREATE DATABASE salaryloan;
|
||||
CREATE user salaryloan with encrypted password 'salaryloan';
|
||||
GRANT all privileges on database salaryloan to salaryloan;
|
||||
|
||||
CREATE TABLE demo_bank_accounts (
|
||||
id SERIAL,
|
||||
uid uuid DEFAULT uuid_generate_v4(),
|
||||
name VARCHAR(125),
|
||||
offers INT DEFAULT 0,
|
||||
salary_account INT DEFAULT 0,
|
||||
current_loans INT DEFAULT 0,
|
||||
mobile VARCHAR(25) UNIQUE NOT NULL,
|
||||
bvn VARCHAR(12) UNIQUE NOT NULL,
|
||||
email VARCHAR(125),
|
||||
pin VARCHAR(6),
|
||||
added timestamp without time zone DEFAULT now()
|
||||
);
|
||||
ALTER TABLE ONLY demo_bank_accounts
|
||||
ADD CONSTRAINT demo_bank_accounts_id_key UNIQUE (id);
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ FLASK_APP=project/__init__.py
|
||||
FLASK_DEBUG=1
|
||||
SOCKET_URL=https://dev-socket.mermsemr.com
|
||||
PANEL_URL=https://dev-panel.mermsemr.com
|
||||
DATABASE_URL=postgresql://merms_panel:merms_panel@10.20.30.60:5432/merms_panel
|
||||
DATABASE_URL=postgresql://salaryloan:salaryloan@10.20.30.60:5432/salaryloan
|
||||
SQL_HOST=10.20.30.60
|
||||
SQL_PORT=5432
|
||||
DATABASE=postgres
|
||||
+92
-6
@@ -1,4 +1,7 @@
|
||||
# from flask import Flask
|
||||
import os
|
||||
import psycopg2
|
||||
from dotenv import load_dotenv
|
||||
from flask_swagger_ui import get_swaggerui_blueprint
|
||||
import datetime
|
||||
import jwt
|
||||
@@ -13,12 +16,26 @@ from flask import (
|
||||
)
|
||||
from flask_cors import CORS, cross_origin
|
||||
|
||||
from functools import wraps
|
||||
import json
|
||||
import psycopg2.extras
|
||||
import pandas as pd
|
||||
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
# import socket
|
||||
#import SQLAlchemy
|
||||
#from werkzeug.utils import secure_filename
|
||||
|
||||
load_dotenv()
|
||||
|
||||
app = Flask(__name__)
|
||||
cors = CORS(app) # allow CORS for all domains on all routes.
|
||||
|
||||
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)
|
||||
|
||||
#API_URL = 'http://petstore.swagger.io/v2/swagger.json' # Our API url (can of course be a local resource)
|
||||
API_URL = 'http://localhost:6335/docs/digifi_swagger.json'
|
||||
# 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
|
||||
@@ -38,6 +55,8 @@ swaggerui_blueprint = get_swaggerui_blueprint(
|
||||
|
||||
app.register_blueprint(swaggerui_blueprint)
|
||||
|
||||
dataUrl = os.getenv("DATABASE_URL")
|
||||
connection = psycopg2.connect(dataUrl)
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
@@ -80,10 +99,47 @@ def salary_login():
|
||||
@app.route('/salary/demousers')
|
||||
def salary_demousers():
|
||||
dList = []
|
||||
for i in range(10):
|
||||
print(names.get_full_name())
|
||||
|
||||
sample_range = random.randint(20, 60)
|
||||
# VARCHAR(125),
|
||||
# offers INT DEFAULT 0,
|
||||
# INT DEFAULT 0,
|
||||
# current_loans INT DEFAULT 0,
|
||||
# VARCHAR(25),
|
||||
# VARCHAR(12),
|
||||
# VARCHAR(125),
|
||||
# VARCHAR(6),
|
||||
|
||||
SQL_INSERT = "INSERT INTO demo_bank_accounts (name, salary_account, mobile, bvn, email, pin) VALUES(%s,%s,%s,%s,%s,%s)"
|
||||
|
||||
# for i in range(900):
|
||||
# new_data = (
|
||||
# names.get_full_name() ,
|
||||
# random.randint(0, 1),
|
||||
# '801-000-'+str( random.randint(1000, 9999) ) ,
|
||||
# '8315000'+str( random.randint(1000, 9999) ),
|
||||
# 'demo+'+ names.get_first_name() +'@chiefsoft.net',
|
||||
# random.randint(1100, 9999)
|
||||
# )
|
||||
#
|
||||
# print(new_data)
|
||||
# with connection:
|
||||
# with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor:
|
||||
# cursor.execute(SQL_INSERT, new_data)
|
||||
#
|
||||
# print(names.get_full_name())
|
||||
|
||||
SELECT_DEMO_ENTRY = f"SELECT id,uid, name,offers,salary_account,current_loans,mobile,bvn, email, pin, added::text FROM demo_bank_accounts ORDER BY id ASC"
|
||||
print(SELECT_DEMO_ENTRY)
|
||||
with connection:
|
||||
with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor:
|
||||
cursor.execute(SELECT_DEMO_ENTRY)
|
||||
select_demoS = cursor.fetchall()
|
||||
|
||||
print(select_demoS)
|
||||
demo_data = json.dumps( [dict(ix) for ix in select_demoS] )
|
||||
print(demo_data)
|
||||
|
||||
sample_range = random.randint(2, 5)
|
||||
for x in range(sample_range):
|
||||
calDate = datetime.datetime.utcnow() + datetime.timedelta(minutes=180 * random.randint(1, 20))
|
||||
new_l = {
|
||||
@@ -103,7 +159,8 @@ def salary_demousers():
|
||||
demo_data = {
|
||||
"last_update": datetime.datetime.utcnow(),
|
||||
"offers":products(),
|
||||
"list" : dList
|
||||
"list_old" : dList,
|
||||
"list" : json.loads( demo_data)
|
||||
}
|
||||
return {
|
||||
"demo_data": demo_data,
|
||||
@@ -120,6 +177,16 @@ def salary_products():
|
||||
"product_data": product_data,
|
||||
}, 200
|
||||
|
||||
@app.route('/salary/loanoffers')
|
||||
def salary_loanoffers():
|
||||
offers_data = {
|
||||
"offers": offers() ,
|
||||
"extra" : []
|
||||
}
|
||||
return {
|
||||
"product_data": offers_data,
|
||||
}, 200
|
||||
|
||||
def products():
|
||||
product_data = [
|
||||
{"cid": "1", "description": "Product Loan 01" , "active" : 0 },
|
||||
@@ -128,5 +195,24 @@ def products():
|
||||
]
|
||||
return product_data
|
||||
|
||||
|
||||
def offers():
|
||||
offers_data = [
|
||||
{"cid": "425611f2-c692-4404-b93d-76ca7a5ce00", "description": "100,000 Naira for 30 Days" , "active" : 1 },
|
||||
{"cid": "425611f2-c692-4404-b93d-76ca7a5ce01", "description": "300,000 Naira for 60 Days" , "active" : 1 },
|
||||
{"cid": "425611f2-c692-4404-b93d-76ca7a5ce02", "description": "900,000 Naira for 90 Days" , "active" : 1 },
|
||||
]
|
||||
return offers_data
|
||||
|
||||
|
||||
def offers_detail(offer_id):
|
||||
offer_detail = [
|
||||
{"cid": "425611f2-c692-4404-b93d-76ca7a5ce00", "description": "100,000 Naira for 30 Days" , "active" : 1 },
|
||||
{"cid": "425611f2-c692-4404-b93d-76ca7a5ce01", "description": "300,000 Naira for 60 Days" , "active" : 1 },
|
||||
{"cid": "425611f2-c692-4404-b93d-76ca7a5ce02", "description": "900,000 Naira for 90 Days" , "active" : 1 },
|
||||
]
|
||||
return offer_detail
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=8000)
|
||||
Reference in New Issue
Block a user