added database lookup now need frontend
This commit is contained in:
parent
0647edf54a
commit
8f69bec6ca
33
main.py
33
main.py
|
@ -11,14 +11,6 @@ def get_db():
|
||||||
db = sqlite3.connect("main.sqlite")
|
db = sqlite3.connect("main.sqlite")
|
||||||
return db
|
return db
|
||||||
|
|
||||||
@app.route("/users", methods=["GET"])
|
|
||||||
def get_users():
|
|
||||||
db = get_db()
|
|
||||||
cursor = db.cursor()
|
|
||||||
cursor.execute("SELECT * FROM users")
|
|
||||||
users = cursor.fetchall()
|
|
||||||
return jsonify(users)
|
|
||||||
|
|
||||||
@app.route("/users", methods=["POST"])
|
@app.route("/users", methods=["POST"])
|
||||||
def create_user():
|
def create_user():
|
||||||
db = get_db()
|
db = get_db()
|
||||||
|
@ -69,31 +61,14 @@ def login():
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@app.route("/users/<int:user_id>", methods=["GET"])
|
@app.route("/products.json")
|
||||||
def get_user(user_id):
|
def products():
|
||||||
db = get_db()
|
db = get_db()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))
|
cursor.execute("SELECT * FROM products;")
|
||||||
user = cursor.fetchone()
|
|
||||||
return jsonify(user)
|
|
||||||
|
|
||||||
@app.route("/users/<int:user_id>", methods=["PUT"])
|
return jsonify(cursor.fetchall())
|
||||||
def update_user(user_id):
|
|
||||||
db = get_db()
|
|
||||||
cursor = db.cursor()
|
|
||||||
name = request.form["name"]
|
|
||||||
email = request.form["email"]
|
|
||||||
cursor.execute("UPDATE users SET name = ?, email = ? WHERE id = ?", (name, email, user_id))
|
|
||||||
db.commit()
|
|
||||||
return jsonify({"message": "User updated successfully"})
|
|
||||||
|
|
||||||
@app.route("/users/<int:user_id>", methods=["DELETE"])
|
|
||||||
def delete_user(user_id):
|
|
||||||
db = get_db()
|
|
||||||
cursor = db.cursor()
|
|
||||||
cursor.execute("DELETE FROM users WHERE id = ?", (user_id,))
|
|
||||||
db.commit()
|
|
||||||
return jsonify({"message": "User deleted successfully"})
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
|
BIN
main.sqlite
BIN
main.sqlite
Binary file not shown.
11
setup.py
11
setup.py
|
@ -29,5 +29,16 @@ db.execute("CREATE TABLE IF NOT EXISTS token(" +
|
||||||
"expiry INTEGER NOT NULL " +
|
"expiry INTEGER NOT NULL " +
|
||||||
");")
|
");")
|
||||||
|
|
||||||
|
db.execute("CREATE TABLE IF NOT EXISTS products(\
|
||||||
|
name STRING NOT NULL,\
|
||||||
|
category STRING,\
|
||||||
|
price REAL NOT NULL,\
|
||||||
|
specs STRING NOT NULL,\
|
||||||
|
value REAL DEFAULT 0,\
|
||||||
|
price REAL DEFAULT 0,\
|
||||||
|
review REAL DEFAULT 0,\
|
||||||
|
votes REAL DEFAULT 0\
|
||||||
|
)")
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
|
@ -1,7 +1,18 @@
|
||||||
from os import urandom
|
#!/usr/bin/env python3
|
||||||
from base64 import b64encode
|
import sqlite3
|
||||||
|
|
||||||
rnd=urandom(16)
|
db = sqlite3.connect("main.sqlite")
|
||||||
rnd_bytes=b64encode(rnd).decode('utf-8')
|
|
||||||
|
|
||||||
print(rnd_bytes)
|
db.execute('INSERT INTO products VALUES (\
|
||||||
|
"Yuxin Little Magic", \
|
||||||
|
"Rubiks Cube", \
|
||||||
|
5.00, \
|
||||||
|
"Really fast", \
|
||||||
|
0.8, \
|
||||||
|
0.8, \
|
||||||
|
0, \
|
||||||
|
0\
|
||||||
|
)')
|
||||||
|
|
||||||
|
db.commit()
|
||||||
|
db.close()
|
||||||
|
|
Loading…
Reference in New Issue