Search in sources :

Example 6 with ExerciseScoresDTO

use of de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO in project Artemis by ls1intum.

the class ExerciseScoresChartResource method getCourseExerciseScores.

/**
 * GET /courses/:courseId/charts/exercise-scores
 * <p>
 * This call returns the information used for the exercise-scores-chart. It will get the score of
 * the requesting user,the average score and the best score in course exercises
 * <p>
 * Note: Only released course exercises with assessment due date over are considered!
 * <p>
 *
 * @param courseId id of the course for which to get the exercise scores
 * @return the ResponseEntity with status 200 (OK) and with the exercise scores in the body
 */
@GetMapping("courses/{courseId}/charts/exercise-scores")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<List<ExerciseScoresDTO>> getCourseExerciseScores(@PathVariable Long courseId) {
    log.debug("REST request to get exercise scores for course with id: {}", courseId);
    Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
    // we only consider exercises in which the student had a chance to earn a score (released and due date over)
    List<ExerciseScoresDTO> exerciseScoresDTOList = exerciseScoresChartService.getExerciseScores(filterExercises(course.getExercises()), user);
    return ResponseEntity.ok(exerciseScoresDTOList);
}
Also used : User(de.tum.in.www1.artemis.domain.User) ExerciseScoresDTO(de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO) Course(de.tum.in.www1.artemis.domain.Course) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ExerciseScoresDTO (de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresDTO)6 Course (de.tum.in.www1.artemis.domain.Course)2 User (de.tum.in.www1.artemis.domain.User)2 ParticipantScore (de.tum.in.www1.artemis.domain.scores.ParticipantScore)2 ExerciseScoresAggregatedInformation (de.tum.in.www1.artemis.web.rest.dto.ExerciseScoresAggregatedInformation)2 Test (org.junit.jupiter.api.Test)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2