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 b6a2a0d..fe6ef42 100644 Binary files a/main.sqlite and b/main.sqlite differ diff --git a/setup.py b/setup.py index 0b41742..18d3fbe 100755 --- a/setup.py +++ b/setup.py @@ -29,5 +29,16 @@ db.execute("CREATE TABLE IF NOT EXISTS token(" + "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.close() diff --git a/test.py b/test.py old mode 100644 new mode 100755 index f61ddbc..3d7fd0c --- a/test.py +++ b/test.py @@ -1,7 +1,18 @@ -from os import urandom -from base64 import b64encode +#!/usr/bin/env python3 +import sqlite3 -rnd=urandom(16) -rnd_bytes=b64encode(rnd).decode('utf-8') +db = sqlite3.connect("main.sqlite") -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()