delete in db
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
2024-02-01 16:43:31 +01:00
parent 5c8f057843
commit ce38d6cf24
3 changed files with 52 additions and 9 deletions

View File

@ -175,8 +175,30 @@ def get_database_entries():
if conn:
conn.close()
@app.route('/delete_nutrition', methods=['POST'])
@oidc.accept_token(['openid'])
def delete_nutrition():
data = request.get_json()
foodNames = data['foodNames']
if not foodNames:
return jsonify({'error': 'Keine Lebensmittel zum Löschen angegeben'}), 400
try:
conn = psycopg2.connect()
with conn.cursor() as cursor:
query = "DELETE FROM nutrition_table WHERE name = ANY(%s)"
cursor.execute(query, (foodNames,))
conn.commit()
return jsonify({'message': 'Erfolgreich gelöscht'}), 200
except Exception as e:
return jsonify({'error': str(e)}), 500
finally:
if conn:
conn.close()
exposed_app = ProxyFix(app, x_for=1, x_host=1)