remove from list and delete list functions

This commit is contained in:
Sam Hadow 2024-02-14 13:45:52 +01:00
parent 9214896c75
commit 198de5f116
2 changed files with 58 additions and 1 deletions

View File

@ -80,12 +80,33 @@ def createList():
@app.route('/app/add-to-list', methods=['POST'])
def addToList():
date = request.get_json()
data = request.get_json()
list_uuid = data.get('list_uuid')
item_uuid = data.get('item_uuid')
add_to_list(list_uuid, item_uuid)
return jsonify({'list': list_uuid, 'item': item_uuid}), 200
@app.route('/app/remove-from-list', methods=['POST'])
def removeFromList():
data = request.get_json()
list_uuid = data.get('list_uuid')
item_uuid = data.get('item_uuid')
try:
remove_from_list(list_uuid, item_uuid)
return jsonify({'list': list_uuid, 'item': item_uuid}), 200
except:
return str('item not found in list'), 400
@app.route('/app/delete-list', methods=['POST'])
def deleteList():
data = request.get_json()
list_uuid = data.get('list_uuid')
try:
delete_list(list_uuid)
return jsonify({'list': list_uuid}), 200
except:
return str('item not found in list'), 400
@app.route('/app/datahistory',methods = ['GET'])
def data_history_request():
if request.method == 'GET':

View File

@ -197,6 +197,26 @@ def create_list(name, description):
connection.close()
return result
def delete_list(list_uuid):
'''
delete an itemlist
'''
connection = connect_db()
cursor = connection.cursor()
cursor.execute("""
DELETE
FROM listcontent
WHERE list_uuid = %s
""", (list_uuid,))
cursor.execute("""
DELETE
FROM itemlist
WHERE uuid = %s
""", (uuid,))
cursor.close()
connection.commit()
connection.close()
def add_to_list(list_uuid, item_uuid):
'''
add an item to an itemlist
@ -210,6 +230,22 @@ def add_to_list(list_uuid, item_uuid):
connection.commit()
connection.close()
def remove_from_list(list_uuid, item_uuid):
'''
remove an item from an itemlist
'''
connection = connect_db()
cursor = connection.cursor()
cursor.execute("""
DELETE
FROM listcontent
WHERE list_uuid = %s
AND item_uuid = %s
""", (list_uuid, item_uuid))
cursor.close()
connection.commit()
connection.close()
def export_csv():
'''join item and history data from database and export it in ./output.csv'''
connection = connect_db()