From: Dana Truempy Date: Mon, 18 May 2020 01:22:36 +0000 (-0500) Subject: Set up JSON endpoint for wishlist entries X-Git-Url: https://git.jacobcasper.com/?a=commitdiff_plain;h=d0194bf3e448f48f1a4a0ecf66d37519a4438121;p=perfect-gift.git Set up JSON endpoint for wishlist entries --- diff --git a/.gitignore b/.gitignore index c4ac289..abd281a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 index 0000000..7008ca2 --- /dev/null +++ b/backend/app.py @@ -0,0 +1,16 @@ +import sqlite3 +from flask import Flask, jsonify +app = Flask(__name__) + +@app.route('/wishlist//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)