Skip to content

Commit

Permalink
feat: add quiz_result_id and is_solved fields to quiz/<int:quiz_id> e…
Browse files Browse the repository at this point in the history
…ndpoint
  • Loading branch information
arastasci committed Nov 24, 2024
1 parent d22a807 commit f1c6eda
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
path('', index , name='index_page'),
path('profile/', view_profile, name='view_profile'),
path('profile/update/', update_profile, name='update_profile'),
path('quiz/<int:quiz_id>', quiz_views.get_quiz, name="get_quiz"),
path('quiz/<int:quiz_id>/', quiz_views.get_quiz, name="get_quiz"),
path('feed/quiz/', quiz_views.view_quizzes, name="feed_quiz"),
path('quiz/create/', quiz_views.create_quiz, name="create_quiz"),
path('quiz/question/', quiz_views.get_question, name="get_question"),
Expand Down
6 changes: 4 additions & 2 deletions backend/app/views_directory/quiz_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@ def get_question(request):
def get_quiz(request, quiz_id):
quiz = get_object_or_404(Quiz, id=quiz_id)
serializer = QuizSerializer(quiz, context = {'request': request})

return Response(serializer.data, status=status.HTTP_200_OK)
data = {'quiz': serializer.data}
data['is_solved'] = QuizProgress.objects.filter(quiz=quiz, user=request.user, completed=True).exists()
data['quiz_result_id'] = QuizResults.objects.filter(quiz=quiz, user=request.user).order_by('-id').first().id if data['is_solved'] else None
return Response(data, status=status.HTTP_200_OK)



Expand Down

0 comments on commit f1c6eda

Please sign in to comment.