Refactor get topset database call

This commit is contained in:
Peter Stockings
2023-12-09 16:35:10 +11:00
parent 8bbbfecbf9
commit 1ff616f4e0
2 changed files with 18 additions and 31 deletions

39
db.py
View File

@@ -227,37 +227,24 @@ class DataBase():
'Note': note
}
def get_topset(self, person_id, workout_id, topset_id):
def get_topset(self, topset_id):
topset = self.execute("""
SELECT
P.person_id AS "PersonId",
P.name AS "PersonName",
W.workout_id AS "WorkoutId",
W.start_date AS "StartDate",
T.topset_id AS "TopSetId",
E.exercise_id AS "ExerciseId",
E.name AS "ExerciseName",
T.repetitions AS "Repetitions",
T.weight AS "Weight"
FROM Person P
INNER JOIN Workout W ON P.person_id=W.person_id
INNER JOIN TopSet T ON W.workout_id=T.workout_id
T.topset_id,
E.exercise_id,
E.name AS "exercise_name",
T.repetitions,
T.weight
FROM TopSet T
INNER JOIN Exercise E ON T.exercise_id=E.exercise_id
WHERE P.person_id=%s
AND W.workout_id = %s
AND T.topset_id = %s""", [person_id, workout_id, topset_id], one=True)
WHERE T.topset_id = %s""", [topset_id], one=True)
return {
'PersonId': topset['PersonId'],
'PersonName': topset['PersonName'],
'WorkoutId': workout_id,
'StartDate': topset['StartDate'],
'Exercises': self.get_all_exercises(),
"TopSetId": topset['TopSetId'],
"ExerciseId": topset['ExerciseId'],
"ExerciseName": topset['ExerciseName'],
"Weight": topset['Weight'],
"Repetitions": topset['Repetitions']
"topset_id": topset['topset_id'],
"exercise_id": topset['exercise_id'],
"exercise_name": topset['exercise_name'],
"weight": topset['weight'],
"repetitions": topset['repetitions']
}
def get_all_topsets(self):