Skip to content

Commit

Permalink
Load submission of last rated result instead of a general participati…
Browse files Browse the repository at this point in the history
…on submission
  • Loading branch information
Hialus committed Oct 23, 2024
1 parent c17b2c4 commit 13a5d8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public interface QuizSubmissionRepository extends ArtemisJpaRepository<QuizSubmi
@EntityGraph(type = LOAD, attributePaths = { "submittedAnswers" })
Optional<QuizSubmission> findWithEagerSubmittedAnswersByParticipationId(long participationId);

@Query("""
SELECT submission
FROM QuizSubmission submission
LEFT JOIN FETCH submission.submittedAnswers
JOIN submission.results r
WHERE r.id = :resultId
""")
Optional<QuizSubmission> findWithEagerSubmittedAnswersByResultId(@Param("resultId") long resultId);

/**
* Retrieve QuizSubmission for given quiz batch and studentLogin
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ public ResponseEntity<MappingJacksonValue> startParticipation(@PathVariable Long

// NOTE: starting exercise prevents that two participation will exist, but ensures that a submission is created
var result = resultRepository.findFirstByParticipationIdAndRatedOrderByCompletionDateDesc(participation.getId(), true).orElse(new Result());
result.setSubmission(quizSubmissionRepository.findWithEagerSubmittedAnswersByParticipationId(participation.getId()).orElseThrow());
if (result.getId() == null) {
// Load the live submission of the participation
result.setSubmission(quizSubmissionRepository.findWithEagerSubmittedAnswersByParticipationId(participation.getId()).orElseThrow());
}
else {
// Load the actual submission of the result
result.setSubmission(quizSubmissionRepository.findWithEagerSubmittedAnswersByResultId(result.getId()).orElseThrow());
}

participation.setResults(Set.of(result));
participation.setExercise(exercise);
Expand Down

0 comments on commit 13a5d8c

Please sign in to comment.