Skip to content

Commit

Permalink
Merge pull request #760 from bounswe/BACKEND-758
Browse files Browse the repository at this point in the history
feat(backend): implement quiz canceling
  • Loading branch information
arastasci authored Dec 12, 2024
2 parents c88f4b0 + ebe235b commit 53b4305
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
path('quiz/review/<int:quiz_result_id>/', quiz_views.get_quiz_review, name="review_quiz"),
path('quiz/recommend/<int:quiz_id>/', quiz_views.get_quiz_recommendations, name="recommend_quiz"),
path('quiz/review_latest/<int:quiz_id>/', quiz_views.get_latest_quiz_review, name="review_latest_quiz"),
path('quiz/cancel/', quiz_views.cancel_quiz, name="cancel_quiz"),

path('word/bookmark/<str:word>/', bookmark_word, name='bookmark_word'),
path('word/unbookmark/<str:word>/', unbookmark_word, name='unbookmark_word'),
Expand Down
15 changes: 15 additions & 0 deletions backend/app/views_directory/quiz_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ def submit_quiz(request):
return Response({'result_url': result_url}, status=status.HTTP_200_OK)


@api_view(['POST'])
@permission_classes([IsAuthenticated])
def cancel_quiz(request):
# check if quiz progress is completed
quiz_progress = get_object_or_404(QuizProgress, id=request.data['quiz_progress_id'])
if quiz_progress.completed:
return Response({'error': 'Quiz already submitted.'}, status=status.HTTP_400_BAD_REQUEST)
# check if quiz progress is user's
if quiz_progress.user != request.user:
return Response({'error': 'Unauthorized'}, status=status.HTTP_401_UNAUTHORIZED)

quiz_progress.delete()
return Response({'message': 'Quiz progress deleted'}, status=status.HTTP_200_OK)


@api_view(['GET'])
@permission_classes([IsAuthenticated])
def get_quiz_results(request):
Expand Down

0 comments on commit 53b4305

Please sign in to comment.