use of de.tum.in.www1.artemis.web.rest.dto.GradeDTO in project ArTEMiS by ls1intum.
the class GradeStepIntegrationTest method testGetGradeStepByPercentageForExam.
/**
* Test get request for a single grade by grade percentage
*
* @throws Exception
*/
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetGradeStepByPercentageForExam() throws Exception {
GradeStep gradeStep = new GradeStep();
gradeStep.setGradeName("Test grade");
gradeStep.setLowerBoundPercentage(0);
gradeStep.setUpperBoundPercentage(40);
gradeStep.setIsPassingGrade(false);
gradeStep.setGradingScale(examGradingScale);
gradeSteps = Set.of(gradeStep);
examGradingScale.setGradeSteps(gradeSteps);
examGradingScale.setGradeType(GradeType.BONUS);
gradingScaleRepository.save(examGradingScale);
exam.setPublishResultsDate(ZonedDateTime.now());
examRepository.save(exam);
GradeDTO foundGrade = request.get("/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/grading-scale/match-grade-step?gradePercentage=35", HttpStatus.OK, GradeDTO.class);
assertThat(foundGrade.gradeName).isEqualTo("Test grade");
assertThat(foundGrade.gradeType).isEqualTo(GradeType.BONUS);
assertThat(foundGrade.isPassingGrade).isFalse();
}
use of de.tum.in.www1.artemis.web.rest.dto.GradeDTO in project ArTEMiS by ls1intum.
the class GradeStepResource method getGradeStepByPercentageForExam.
/**
* GET /courses/{courseId}/exams/{examId}/grading-scale/grade-steps/match-grade-step : Find a grade step for the grading scale of a course by grade percentage
*
* @param courseId the course to which the exam belongs
* @param examId the exam to which the grading scale belongs
* @param gradePercentage the grade percentage the has to be mapped to a grade step
* @return ResponseEntity with status 200 (Ok) with body the grade if the grading scale and grade step exist and 404 (Not found) otherwise
*/
@GetMapping("/courses/{courseId}/exams/{examId}/grading-scale/match-grade-step")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<GradeDTO> getGradeStepByPercentageForExam(@PathVariable Long courseId, @PathVariable Long examId, @RequestParam Double gradePercentage) {
log.debug("REST request to get grade step for grade percentage {} for exam: {}", gradePercentage, examId);
User user = userRepository.getUserWithGroupsAndAuthorities();
Course course = courseRepository.findByIdElseThrow(courseId);
Exam exam = examRepository.findByIdElseThrow(examId);
Optional<GradingScale> gradingScale = gradingScaleRepository.findByExamId(examId);
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
boolean isInstructor = authCheckService.isAtLeastInstructorInCourse(course, user);
if (gradingScale.isEmpty()) {
return ResponseEntity.ok(null);
} else if (!isInstructor && !exam.resultsPublished()) {
throw new AccessForbiddenException();
}
GradeStep gradeStep = gradingScaleRepository.matchPercentageToGradeStep(gradePercentage, gradingScale.get().getId());
GradeDTO gradeDTO = new GradeDTO(gradeStep.getGradeName(), gradeStep.getIsPassingGrade(), gradeStep.getGradingScale().getGradeType());
return ResponseEntity.ok(gradeDTO);
}
use of de.tum.in.www1.artemis.web.rest.dto.GradeDTO in project Artemis by ls1intum.
the class GradeStepResource method getGradeStepByPercentageForExam.
/**
* GET /courses/{courseId}/exams/{examId}/grading-scale/grade-steps/match-grade-step : Find a grade step for the grading scale of a course by grade percentage
*
* @param courseId the course to which the exam belongs
* @param examId the exam to which the grading scale belongs
* @param gradePercentage the grade percentage the has to be mapped to a grade step
* @return ResponseEntity with status 200 (Ok) with body the grade if the grading scale and grade step exist and 404 (Not found) otherwise
*/
@GetMapping("/courses/{courseId}/exams/{examId}/grading-scale/match-grade-step")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<GradeDTO> getGradeStepByPercentageForExam(@PathVariable Long courseId, @PathVariable Long examId, @RequestParam Double gradePercentage) {
log.debug("REST request to get grade step for grade percentage {} for exam: {}", gradePercentage, examId);
User user = userRepository.getUserWithGroupsAndAuthorities();
Course course = courseRepository.findByIdElseThrow(courseId);
Exam exam = examRepository.findByIdElseThrow(examId);
Optional<GradingScale> gradingScale = gradingScaleRepository.findByExamId(examId);
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
boolean isInstructor = authCheckService.isAtLeastInstructorInCourse(course, user);
if (gradingScale.isEmpty()) {
return ResponseEntity.ok(null);
} else if (!isInstructor && !exam.resultsPublished()) {
throw new AccessForbiddenException();
}
GradeStep gradeStep = gradingScaleRepository.matchPercentageToGradeStep(gradePercentage, gradingScale.get().getId());
GradeDTO gradeDTO = new GradeDTO(gradeStep.getGradeName(), gradeStep.getIsPassingGrade(), gradeStep.getGradingScale().getGradeType());
return ResponseEntity.ok(gradeDTO);
}
use of de.tum.in.www1.artemis.web.rest.dto.GradeDTO in project Artemis by ls1intum.
the class GradeStepIntegrationTest method testGetGradeStepByPercentageForExam.
/**
* Test get request for a single grade by grade percentage
*
* @throws Exception
*/
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetGradeStepByPercentageForExam() throws Exception {
GradeStep gradeStep = new GradeStep();
gradeStep.setGradeName("Test grade");
gradeStep.setLowerBoundPercentage(0);
gradeStep.setUpperBoundPercentage(40);
gradeStep.setIsPassingGrade(false);
gradeStep.setGradingScale(examGradingScale);
gradeSteps = Set.of(gradeStep);
examGradingScale.setGradeSteps(gradeSteps);
examGradingScale.setGradeType(GradeType.BONUS);
gradingScaleRepository.save(examGradingScale);
exam.setPublishResultsDate(ZonedDateTime.now());
examRepository.save(exam);
GradeDTO foundGrade = request.get("/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/grading-scale/match-grade-step?gradePercentage=35", HttpStatus.OK, GradeDTO.class);
assertThat(foundGrade.gradeName).isEqualTo("Test grade");
assertThat(foundGrade.gradeType).isEqualTo(GradeType.BONUS);
assertThat(foundGrade.isPassingGrade).isFalse();
}
use of de.tum.in.www1.artemis.web.rest.dto.GradeDTO in project ArTEMiS by ls1intum.
the class GradeStepResource method getGradeStepByPercentageForCourse.
/**
* GET /courses/{courseId}/grading-scale/grade-steps/match-grade-step : Find a grade step for the grading scale of a course by grade percentage
*
* @param courseId the course to which the grading scale belongs
* @param gradePercentage the grade percentage the has to be mapped to a grade step
* @return ResponseEntity with status 200 (Ok) with body the grade if the grading scale and grade step exist and 404 (Not found) otherwise
*/
@GetMapping("/courses/{courseId}/grading-scale/match-grade-step")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<GradeDTO> getGradeStepByPercentageForCourse(@PathVariable Long courseId, @RequestParam Double gradePercentage) {
log.debug("REST request to get grade step for grade percentage {} for course: {}", gradePercentage, courseId);
Course course = courseRepository.findByIdElseThrow(courseId);
Optional<GradingScale> gradingScale = gradingScaleRepository.findByCourseId(courseId);
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, null);
if (gradingScale.isEmpty()) {
return ResponseEntity.ok(null);
}
GradeStep gradeStep = gradingScaleRepository.matchPercentageToGradeStep(gradePercentage, gradingScale.get().getId());
GradeDTO gradeDTO = new GradeDTO(gradeStep.getGradeName(), gradeStep.getIsPassingGrade(), gradeStep.getGradingScale().getGradeType());
return ResponseEntity.ok(gradeDTO);
}
Aggregations