summaryrefslogtreecommitdiff
path: root/app/routes/api.py
diff options
context:
space:
mode:
authorstilbruch <stilbruch@protonmail.com>2022-04-23 14:26:59 -0500
committerstilbruch <stilbruch@protonmail.com>2022-04-23 14:26:59 -0500
commit316edff9e6b90ab310978c10adbeffa87d18e746 (patch)
tree2c36e998122e39911bfb458ed1671d6f6e3ae041 /app/routes/api.py
parent404bba9d518271533d5e4c83dabd8541726bf248 (diff)
downloadStrengthy-316edff9e6b90ab310978c10adbeffa87d18e746.tar.xz
Strengthy-316edff9e6b90ab310978c10adbeffa87d18e746.zip
Fix workout deleting option
Diffstat (limited to 'app/routes/api.py')
-rw-r--r--app/routes/api.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/routes/api.py b/app/routes/api.py
new file mode 100644
index 0000000..58b4732
--- /dev/null
+++ b/app/routes/api.py
@@ -0,0 +1,17 @@
+from app import app, db
+from flask import redirect, request
+from flask_login import current_user, login_required
+from tables import Workout
+
+@app.route("/api/workout/delete", methods=['GET'])
+@login_required
+def api_workout_delete():
+ if 'id' not in request.args:
+ return redirect('/home');
+
+ workout = Workout.query.filter_by(id=int(request.args['id']), user_id=current_user.id).first()
+ if workout:
+ db.session.delete(workout)
+ db.session.commit()
+
+ return redirect('/home')