diff --git a/src/app.py b/src/app.py index 58b1fcd..e8e0d27 100644 --- a/src/app.py +++ b/src/app.py @@ -119,5 +119,11 @@ def data_item_request(): print("fetching data item") return jsonify(get_item()) +@app.route('/app/datalist',methods = ['GET']) +def data_list_request(): + if request.method == 'GET': + print("fetching data item") + return jsonify(get_lists()) + if __name__ == '__main__': app.run(debug = True) diff --git a/src/db.py b/src/db.py index b83623a..b836f97 100644 --- a/src/db.py +++ b/src/db.py @@ -91,6 +91,35 @@ def get_item(): connection.close() return results +def get_item_filtered(lists_uuid): + ''' + return items in a every specified lists (list of itemlist uuid) + every items if filter is empty + ''' + n_filters = len(lists_uuid) + if n_filters > 0: + sql_request = """ + SELECT uuid, itemid, skuid, choice, attributes, image, show + FROM item i + """ + for i in range(n_filters): + sql_request += f', content c{str(i)}' + sql_request += ' WHERE ' + for i,uuid in enumerate(lists_uuid): + sql_request += f' i.uuid = c{str(i)}.item_uuid and c{str(i)}.list_uuid = {str(uuid)} and' + + sql_request = sql_request[:-3] # remove last 'and' + + connection = connect_db() + cursor = connection.cursor() + cursor.execute(sql_request) + results = cursor.fetchall() + cursor.close() + connection.close() + else: + results = get_item() + return results + def get_item_keys(): '''return items id and attributes from database''' connection = connect_db() @@ -246,6 +275,18 @@ def remove_from_list(list_uuid, item_uuid): connection.commit() connection.close() +def get_lists(): + connection = connect_db() + cursor = connection.cursor() + cursor.execute(""" + SELECT uuid, name, description + FROM itemlist + """) + results = cursor.fetchall() + cursor.close() + connection.close() + return results + def export_csv(): '''join item and history data from database and export it in ./output.csv''' connection = connect_db() diff --git a/web/app.html b/web/app.html index 7b7d96b..6ec76fd 100644 --- a/web/app.html +++ b/web/app.html @@ -11,15 +11,46 @@ + + + + +
+ + +