muesli-hd / muesli

Mathematisches Übungsgruppen- und Scheinlisten-Interface
GNU General Public License v3.0
26 stars 13 forks source link

Requesting exercise via API returns result of all exercises of an exam instead of returning only the result of the exercise requested with its unique id #157

Open niels-beier opened 2 years ago

niels-beier commented 2 years ago

If you request an exercise via the API (https://muesli.mathi.uni-heidelberg.de/api/v1/exercises/"exercise-id"/"user-id"/) you get a list of all exercise results of an exam instead of only getting the exercise results of the exercise with its unique id mentioned in the request url.

christian-heusel commented 2 years ago

Can confirm the issue! Unfortunately due to a problem with my development setup I currently am not able to fix the issue. If you want to, you can have a look at the code:

https://github.com/muesli-hd/muesli/blob/f6981e54ff46982fbaae0ce197feb353cdaa3611/muesli/web/api/v1/exerciseEndpoint.py#L78-L104

niels-beier commented 1 year ago

I think this happens because the exercise_points are only filtered by the id of the user. Since all exercises of the exam should have entries for the given user and its ID all exercises are filtered out. I think a fix would be to add another filter like this:

exer_students = exercise.exam.exercise_points.filter(models.ExerciseStudent.student_id == user.id).filter(models.Exam.id == exercise.id)

This should filter the exercise points of the given user by the ID of the given exercise.