Set up JSON endpoint for wishlist entries master
authorDana Truempy <dana.truempy@gmail.com>
Mon, 18 May 2020 01:22:36 +0000 (20:22 -0500)
committerDana Truempy <dana.truempy@gmail.com>
Mon, 18 May 2020 01:22:36 +0000 (20:22 -0500)
.gitignore
backend/app.py [new file with mode: 0644]

index c4ac289..abd281a 100644 (file)
@@ -4,6 +4,12 @@ backend/lib*
 backend/Scripts
 backend/pyvenv.cfg
 
+# python
+backend/__pycache__
+
+# backend db
+backend/db.sqlite
+
 # dependencies
 frontend/node_modules
 frontend/.pnp
diff --git a/backend/app.py b/backend/app.py
new file mode 100644 (file)
index 0000000..7008ca2
--- /dev/null
@@ -0,0 +1,16 @@
+import sqlite3
+from flask import Flask, jsonify
+app = Flask(__name__)
+
+@app.route('/wishlist/<string:wishlist_id>/entries')
+def entries(wishlist_id):
+    conn = sqlite3.connect('db.sqlite')
+    curs = conn.cursor()
+
+    data = []
+    for row in curs.execute(
+        'SELECT WISHLIST_ID, ITEM_ID, NAME, DESCRIPTION FROM WISHLIST_ENTRY WHERE WISHLIST_ID = ?',
+        (wishlist_id,)
+    ):
+        data.append({'wishlist_id': row[0], 'item_id': row[1], 'name': row[2], 'description': row[3]})
+    return jsonify(data)