Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Mar 17, 2022 · 2 comments

Comments

@niels-beier
Copy link

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
Copy link
Collaborator

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:

@view(permission='viewOwn')
def get(self):
"""
---
get:
security:
- Bearer: [read]
- Basic: [read]
tags:
- "v1"
summary: "return an exercise for given student"
description: ""
operationId: "exercise_student_get"
produces:
- "application/json"
responses:
200:
description: successfull return of the exercise
schema:
$ref: "#/definitions/ExerciseStudent"
"""
exercise = self.request.context.exercise
user = self.request.context.user
exer_students = exercise.exam.exercise_points.filter(models.ExerciseStudent.student_id == user.id)
exer_student_schema = models.ExerciseStudentSchema(many=True)
result = exer_student_schema.dump(exer_students)
return result

@niels-beier
Copy link
Author

niels-beier commented Feb 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants