use of de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO in project ArTEMiS by ls1intum.
the class ParticipantScoreResource method getParticipantScoresOfCourse.
/**
* GET /courses/:courseId/participant-scores gets the participant scores of the course
*
* @param courseId the id of the course for which to get the participant score
* @param pageable pageable object
* @param getUnpaged if set all participant scores of the course will be loaded (paging deactivated)
* @return the ResponseEntity with status 200 (OK) and with the participant scores in the body
*/
@GetMapping("/courses/{courseId}/participant-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreDTO>> getParticipantScoresOfCourse(@PathVariable Long courseId, Pageable pageable, @RequestParam(value = "getUnpaged", required = false, defaultValue = "false") boolean getUnpaged) {
long start = System.currentTimeMillis();
log.debug("REST request to get participant scores for course : {}", courseId);
Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
Set<Exercise> exercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).collect(toSet());
List<ParticipantScoreDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreDTOs(getUnpaged ? Pageable.unpaged() : pageable, exercisesOfCourse);
log.info("getParticipantScoresOfCourse took {}ms", System.currentTimeMillis() - start);
return ResponseEntity.ok().body(resultsOfAllExercises);
}
use of de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO in project ArTEMiS by ls1intum.
the class ParticipantScoreDTO method generateFromParticipantScore.
/**
* Generates a {@link ParticipantScoreDTO} from a {@link ParticipantScore}
*
* @param participantScore ParticipantScore input
* @return {@link ParticipantScoreDTO}
*/
public static ParticipantScoreDTO generateFromParticipantScore(ParticipantScore participantScore) {
String userName = null;
Long userId = null;
String teamName = null;
Long teamId = null;
if (participantScore.getClass().equals(StudentScore.class)) {
StudentScore studentScore = (StudentScore) participantScore;
if (studentScore.getUser() != null) {
userName = studentScore.getUser().getLogin();
userId = studentScore.getUser().getId();
}
} else {
TeamScore teamScore = (TeamScore) participantScore;
if (teamScore.getTeam() != null) {
teamName = teamScore.getTeam().getName();
teamId = teamScore.getTeam().getId();
}
}
Long id = participantScore.getId();
String exerciseTitle = participantScore.getExercise() != null && participantScore.getExercise().getTitle() != null ? participantScore.getExercise().getTitle() : null;
Long exerciseId = participantScore.getExercise() != null ? participantScore.getExercise().getId() : null;
Long lastResultId = participantScore.getLastResult() != null ? participantScore.getLastResult().getId() : null;
Double lastResultScore = participantScore.getLastScore();
Long lastRatedResultId = participantScore.getLastRatedResult() != null ? participantScore.getLastRatedResult().getId() : null;
Double lastRatedResultScore = participantScore.getLastRatedScore();
Double lastPoints = participantScore.getLastPoints();
Double lastRatedPoints = participantScore.getLastRatedPoints();
return new ParticipantScoreDTO(id, userId, userName, teamId, teamName, exerciseId, exerciseTitle, lastResultId, lastResultScore, lastRatedResultId, lastRatedResultScore, lastPoints, lastRatedPoints);
}
use of de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO in project ArTEMiS by ls1intum.
the class ParticipantScoreIntegrationTest method getParticipantScoresOfExam_asInstructorOfCourse_shouldReturnParticipantScores.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void getParticipantScoresOfExam_asInstructorOfCourse_shouldReturnParticipantScores() throws Exception {
List<ParticipantScoreDTO> participantScoresOfExam = request.getList("/api/exams/" + idOfExam + "/participant-scores", HttpStatus.OK, ParticipantScoreDTO.class);
assertThat(participantScoresOfExam).hasSize(1);
ParticipantScoreDTO student1Result = participantScoresOfExam.stream().filter(participantScoreDTO -> participantScoreDTO.userId != null).findFirst().get();
assertParticipantScoreDTOStructure(student1Result, idOfStudent1, null, getIdOfIndividualTextExerciseOfExam, 50D, 50D, 5.0, 5.0);
}
use of de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO in project Artemis by ls1intum.
the class ParticipantScoreResource method getParticipantScoresOfExam.
/**
* GET /exams/:examId/participant-scores gets the participant scores of the exam
*
* @param examId the id of the exam for which to get the participant score
* @param pageable pageable object
* @param getUnpaged if set all participant scores of the exam will be loaded (paging deactivated)
* @return the ResponseEntity with status 200 (OK) and with the participant scores in the body
*/
@GetMapping("/exams/{examId}/participant-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreDTO>> getParticipantScoresOfExam(@PathVariable Long examId, Pageable pageable, @RequestParam(value = "getUnpaged", required = false, defaultValue = "false") boolean getUnpaged) {
long start = System.currentTimeMillis();
log.debug("REST request to get participant scores for exam : {}", examId);
Set<Exercise> exercisesOfExam = getExercisesOfExam(examId);
Pageable page;
if (getUnpaged) {
page = Pageable.unpaged();
} else {
page = pageable;
}
List<ParticipantScoreDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreDTOs(page, exercisesOfExam);
log.info("getParticipantScoresOfExam took {}ms", System.currentTimeMillis() - start);
return ResponseEntity.ok().body(resultsOfAllExercises);
}
use of de.tum.in.www1.artemis.web.rest.dto.ParticipantScoreDTO in project Artemis by ls1intum.
the class ParticipantScoreResource method getParticipantScoresOfCourse.
/**
* GET /courses/:courseId/participant-scores gets the participant scores of the course
*
* @param courseId the id of the course for which to get the participant score
* @param pageable pageable object
* @param getUnpaged if set all participant scores of the course will be loaded (paging deactivated)
* @return the ResponseEntity with status 200 (OK) and with the participant scores in the body
*/
@GetMapping("/courses/{courseId}/participant-scores")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<List<ParticipantScoreDTO>> getParticipantScoresOfCourse(@PathVariable Long courseId, Pageable pageable, @RequestParam(value = "getUnpaged", required = false, defaultValue = "false") boolean getUnpaged) {
long start = System.currentTimeMillis();
log.debug("REST request to get participant scores for course : {}", courseId);
Course course = courseRepository.findByIdWithEagerExercisesElseThrow(courseId);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
Set<Exercise> exercisesOfCourse = course.getExercises().stream().filter(Exercise::isCourseExercise).collect(toSet());
List<ParticipantScoreDTO> resultsOfAllExercises = participantScoreService.getParticipantScoreDTOs(getUnpaged ? Pageable.unpaged() : pageable, exercisesOfCourse);
log.info("getParticipantScoresOfCourse took {}ms", System.currentTimeMillis() - start);
return ResponseEntity.ok().body(resultsOfAllExercises);
}
Aggregations