-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ππ«₯ β Set up endpoint for creating users from frontend POST request
- Loading branch information
1 parent
fd0c790
commit 9bd1990
Showing
4 changed files
with
129 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FLASK_APP=app | ||
FLASK_DEBUG=True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,49 @@ | ||
from flask import Flask, jsonify, request, make_response | ||
import lightkurve as lk | ||
import os | ||
from flask import Flask, request#, jsonify, make_response | ||
from dotenv import load_dotenv | ||
import psycopg2 | ||
#import lightkurve as lk | ||
#from thirdweb import ThirdwebSDK | ||
|
||
load_dotenv() | ||
app = Flask(__name__) | ||
url = os.getenv("DATABASE_URL") | ||
connection = psycopg2.connect(url) | ||
#proposalsSDK = ThirdwebSDK('goerli') | ||
|
||
# PostgreSQL queries | ||
CREATE_USERS_TABLE = ( | ||
'CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, address TEXT);' | ||
) | ||
CREATE_PLANETS_TABLE = ( | ||
"""CREATE TABLE IF NOT EXISTS planets (user_id INTEGER, temperature REAL, date TIMESTAMP, FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE);""" | ||
) | ||
INSERT_USER_RETURN_ID = 'INSERT INTO users (address) VALUES (%s) RETURNING id;' | ||
INSERT_PLANET = ( | ||
'INSERT INTO planets (user_id, temperature, date) VALUES (%s, %s, %s);' | ||
) | ||
|
||
@app.route('/') | ||
def index(): | ||
return "Hello World" | ||
|
||
@app.route('/createPlanet', methods=["GET", "POST"]) | ||
def createPlanet(): | ||
return "Hi" | ||
# User Management | ||
@app.post('/api/user') | ||
def addUser(): | ||
data = request.get_json() | ||
address = data['address'] | ||
|
||
# Connect to the database | ||
with connection: | ||
with connection.cursor() as cursor: | ||
cursor.execute(CREATE_USERS_TABLE) | ||
cursor.execute(INSERT_USER_RETURN_ID, (address,)) | ||
user_id = cursor.fetchone()[0] | ||
|
||
return {'id': user_id, 'message': f"User {address} created"}, 201 | ||
|
||
#@app.route('/proposals') | ||
#def getProposals(): | ||
#contract = proposalsSDK.get_contract('0xCcaA1ABA77Bae6296D386C2F130c46FEc3E5A004') | ||
#proposals = contract.call("getProposals") | ||
|
||
#return proposals""" | ||
#return proposals""" |
9bd1990
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signal-K/sytizen#1