diff --git a/src/main/kotlin/ch/uzh/ifi/access/repository/CourseRepository.kt b/src/main/kotlin/ch/uzh/ifi/access/repository/CourseRepository.kt index 17dcd4c..decbd4f 100644 --- a/src/main/kotlin/ch/uzh/ifi/access/repository/CourseRepository.kt +++ b/src/main/kotlin/ch/uzh/ifi/access/repository/CourseRepository.kt @@ -29,4 +29,23 @@ interface CourseRepository : JpaRepository { fun getTeamMemberName(email: String?): MemberOverview? fun findCourseBySlug(courseSlug: String?): CourseSummary? + @Query( + nativeQuery = true, value = """ + SELECT sum(e.best_score) AS total_points + FROM evaluation e + JOIN task t ON e.task_id = t.id + JOIN assignment a ON t.assignment_id = a.id + JOIN course c ON a.course_id = c.id + WHERE e.id IN ( + SELECT MAX(id) + FROM evaluation + WHERE user_id = :userId + GROUP BY task_id + ) + AND c.slug = :courseSlug + AND e.user_id = :userId + """ + ) + fun getTotalPoints(courseSlug: String, userId: String): Double? + } \ No newline at end of file diff --git a/src/main/kotlin/ch/uzh/ifi/access/service/CourseService.kt b/src/main/kotlin/ch/uzh/ifi/access/service/CourseService.kt index 296bda8..53932ec 100644 --- a/src/main/kotlin/ch/uzh/ifi/access/service/CourseService.kt +++ b/src/main/kotlin/ch/uzh/ifi/access/service/CourseService.kt @@ -47,6 +47,7 @@ import java.util.stream.Stream class CourseServiceForCaching( private val roleService: RoleService, private val courseService: CourseService, + private val courseRepository: CourseRepository, ) { fun getStudents(courseSlug: String): List { @@ -69,9 +70,8 @@ class CourseServiceForCaching( return course.registeredStudents.map { val user = roleService.getUserByUsername(it) if (user != null) { - val studentDTO = courseService.getStudentWithPoints(courseSlug, user) - studentDTO.username = user.username - studentDTO.registrationId = it + val coursePoints = courseRepository.getTotalPoints(courseSlug, user.username) ?: 0.0 + val studentDTO = StudentDTO(user.firstName, user.lastName, user.email, coursePoints, user.username, it) studentDTO } else { StudentDTO(registrationId = it)