diff --git a/SQL/salaryloan.sql b/SQL/salaryloan.sql index 28a677e..8e898cd 100644 --- a/SQL/salaryloan.sql +++ b/SQL/salaryloan.sql @@ -19,3 +19,58 @@ ALTER TABLE ONLY demo_bank_accounts ADD CONSTRAINT demo_bank_accounts_id_key UNIQUE (id); + +CREATE TABLE loan_offers ( + id SERIAL, + uid uuid DEFAULT uuid_generate_v4(), + loan VARCHAR(25) UNIQUE NOT NULL, + amount INT DEFAULT 0, + description VARCHAR(125), + days_duration INT DEFAULT 0, + active INT DEFAULT 1, + lorder INT DEFAULT 0, + score INT DEFAULT 0, + added timestamp without time zone DEFAULT now() +); +ALTER TABLE ONLY loan_offers + ADD CONSTRAINT loan_offers_id_key UNIQUE (id); + +INSERT INTO loan_offers ( + loan, amount, description, days_duration +) VALUES ( + 'LOAN001', + 100000, + '100,000 Naira for 30 Days', + 30 +); + +INSERT INTO loan_offers ( + loan, amount, description, days_duration +) VALUES ( + 'LOAN002', + 300000, + '300,000 Naira for 60 Days', + 60 +); + + +INSERT INTO loan_offers ( + loan, amount, description, days_duration +) VALUES ( + 'LOAN003', + 900000, + '900,000 Naira for 90 Days', + 90 +); + + + +{"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 }, +] + + +{"cid": "1", "description": "Product Loan 01" , "active" : 0 }, +{"cid": "2", "description": "Product Loan 02" , "active" : 0 }, +{"cid": "3", "description": "First Advance" , "active" : 1 }, \ No newline at end of file diff --git a/app/app.py b/app/app.py index 99492ae..c9de7b5 100644 --- a/app/app.py +++ b/app/app.py @@ -239,12 +239,21 @@ def products(): 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 + OFFER_QUERY = "SELECT uid AS cid,loan,amount,description,days_duration,active FROM loan_offers ORDER BY amount ASC" + with connection: + with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: + cursor.execute(OFFER_QUERY) + select_demoS = cursor.fetchall() + + demo_data = json.dumps( [dict(ix) for ix in select_demoS] ) + return json.loads( demo_data) +# +# 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):