use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.
the class GradingScaleIntegrationTest method init.
/**
* Initialize variables
*/
@BeforeEach
public void init() {
database.addUsers(0, 0, 0, 1);
course = database.addEmptyCourse();
exam = database.addExamWithExerciseGroup(course, true);
courseGradingScale = new GradingScale();
courseGradingScale.setCourse(course);
examGradingScale = new GradingScale();
examGradingScale.setExam(exam);
gradeSteps = new HashSet<>();
courseGradingScale.setGradeSteps(gradeSteps);
examGradingScale.setGradeSteps(gradeSteps);
}
use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.
the class GradingScaleIntegrationTest method testSaveGradingScaleForCourse.
/**
* Test post request for grading scale
*
* @throws Exception
*/
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testSaveGradingScaleForCourse() throws Exception {
gradeSteps = database.generateGradeStepSet(courseGradingScale, true);
courseGradingScale.setGradeSteps(gradeSteps);
GradingScale savedGradingScale = request.postWithResponseBody("/api/courses/" + course.getId() + "/grading-scale", courseGradingScale, GradingScale.class, HttpStatus.CREATED);
assertThat(savedGradingScale.getGradeSteps()).hasSameSizeAs(courseGradingScale.getGradeSteps());
assertThat(savedGradingScale.getGradeSteps()).allMatch(gradeStep -> isGradeStepInSet(courseGradingScale.getGradeSteps(), gradeStep));
assertThat(savedGradingScale).usingRecursiveComparison().ignoringFields("id", "exam", "course", "gradeSteps").ignoringCollectionOrder().isEqualTo(courseGradingScale);
}
use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.
the class GradingScaleIntegrationTest method testGetGradingScaleForExam.
/**
* Test get request for grading scale
*
* @throws Exception
*/
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testGetGradingScaleForExam() throws Exception {
examGradingScale.setGradeSteps(Set.of());
gradingScaleRepository.save(examGradingScale);
GradingScale foundGradingScale = request.get("/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/grading-scale", HttpStatus.OK, GradingScale.class);
assertThat(foundGradingScale).usingRecursiveComparison().ignoringFields("id", "course", "exam").isEqualTo(examGradingScale);
}
use of de.tum.in.www1.artemis.domain.GradingScale 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.domain.GradingScale in project ArTEMiS by ls1intum.
the class GradingScaleResource method deleteGradingScaleForExam.
/**
* DELETE /courses/{courseId}/exams/{examId}/grading-scale : Delete grading scale for course
*
* @param courseId the course to which the exam belongs
* @param examId the exam to which the grading scale belongs
* @return ResponseEntity with status 200 (Ok) if the grading scale is successfully deleted and 400 (Bad request) otherwise
*/
@DeleteMapping("/courses/{courseId}/exams/{examId}/grading-scale")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Void> deleteGradingScaleForExam(@PathVariable Long courseId, @PathVariable Long examId) {
log.debug("REST request to delete the grading scale for exam: {}", examId);
Course course = courseRepository.findByIdElseThrow(courseId);
GradingScale gradingScale = gradingScaleRepository.findByExamIdOrElseThrow(examId);
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
gradingScaleRepository.delete(gradingScale);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, "")).build();
}
Aggregations