From 8f69bec6ca99a136ee61f37a19a1cc0cc0329cdc Mon Sep 17 00:00:00 2001 From: spikey Date: Sat, 24 Feb 2024 17:21:23 -0500 Subject: [PATCH] added database lookup now need frontend --- main.py | 33 ++++----------------------------- main.sqlite | Bin 24576 -> 24576 bytes setup.py | 11 +++++++++++ test.py | 21 ++++++++++++++++----- 4 files changed, 31 insertions(+), 34 deletions(-) mode change 100644 => 100755 test.py diff --git a/main.py b/main.py index b32e930..f47954d 100755 --- a/main.py +++ b/main.py @@ -11,14 +11,6 @@ def get_db(): db = sqlite3.connect("main.sqlite") 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"]) def create_user(): db = get_db() @@ -69,31 +61,14 @@ def login(): return response -@app.route("/users/", methods=["GET"]) -def get_user(user_id): +@app.route("/products.json") +def products(): db = get_db() cursor = db.cursor() - cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,)) - user = cursor.fetchone() - return jsonify(user) + cursor.execute("SELECT * FROM products;") -@app.route("/users/", methods=["PUT"]) -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"}) + return jsonify(cursor.fetchall()) -@app.route("/users/", 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("/") def index(): diff --git a/main.sqlite b/main.sqlite index b6a2a0d44209b01b21ce3d545a712f43f947ed19..fe6ef429c114f15ef68d2e834390dd8aab0bdd88 100644 GIT binary patch delta 103 zcmZoTz}Rqrae_1>>qHr6M%Il9OZ3?o`S&pJ@7XM%S0JxMwX2UOY}FhIQ-#X