Search in sources :

Example 6 with GradeStepsDTO

use of de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO in project ArTEMiS by ls1intum.

the class GradeStepResource method getAllGradeStepsForExam.

/**
 * GET /courses/{courseId}/exams/{examId}/grading-scale/grade-steps : Find all grade steps for the grading scale of an exam
 *
 * @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) with body a list of grade steps if the grading scale exists and 404 (Not found) otherwise
 */
@GetMapping("/courses/{courseId}/exams/{examId}/grading-scale/grade-steps")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<GradeStepsDTO> getAllGradeStepsForExam(@PathVariable Long courseId, @PathVariable Long examId) {
    log.debug("REST request to get all grade steps for exam: {}", examId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    Course course = courseRepository.findByIdElseThrow(courseId);
    Exam exam = examRepository.findByIdElseThrow(examId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
    GradingScale gradingScale = gradingScaleRepository.findByExamIdOrElseThrow(examId);
    boolean isInstructor = authCheckService.isAtLeastInstructorInCourse(course, user);
    if (!isInstructor && !exam.resultsPublished()) {
        throw new AccessForbiddenException();
    }
    GradeStepsDTO gradeStepsDTO = prepareGradeStepsDTO(gradingScale, exam.getMaxPoints(), exam.getTitle());
    return ResponseEntity.ok(gradeStepsDTO);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) User(de.tum.in.www1.artemis.domain.User) GradeStepsDTO(de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO) Course(de.tum.in.www1.artemis.domain.Course) Exam(de.tum.in.www1.artemis.domain.exam.Exam) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with GradeStepsDTO

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

the class GradeStepResource method getAllGradeStepsForCourse.

/**
 * GET /courses/{courseId}/grading-scale/grade-steps : Find all grade steps for the grading scale of a course
 *
 * @param courseId the course to which the grading scale belongs
 * @return ResponseEntity with status 200 (Ok) with body a list of grade steps if the grading scale exists and 404 (Not found) otherwise
 */
@GetMapping("/courses/{courseId}/grading-scale/grade-steps")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<GradeStepsDTO> getAllGradeStepsForCourse(@PathVariable Long courseId) {
    log.debug("REST request to get all grade steps for course: {}", courseId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    GradingScale gradingScale = gradingScaleRepository.findByCourseIdOrElseThrow(courseId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, null);
    GradeStepsDTO gradeStepsDTO = prepareGradeStepsDTO(gradingScale, course.getMaxPoints(), course.getTitle());
    return ResponseEntity.ok(gradeStepsDTO);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) GradeStepsDTO(de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 8 with GradeStepsDTO

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

the class GradeStepResource method getAllGradeStepsForExam.

/**
 * GET /courses/{courseId}/exams/{examId}/grading-scale/grade-steps : Find all grade steps for the grading scale of an exam
 *
 * @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) with body a list of grade steps if the grading scale exists and 404 (Not found) otherwise
 */
@GetMapping("/courses/{courseId}/exams/{examId}/grading-scale/grade-steps")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<GradeStepsDTO> getAllGradeStepsForExam(@PathVariable Long courseId, @PathVariable Long examId) {
    log.debug("REST request to get all grade steps for exam: {}", examId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    Course course = courseRepository.findByIdElseThrow(courseId);
    Exam exam = examRepository.findByIdElseThrow(examId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
    GradingScale gradingScale = gradingScaleRepository.findByExamIdOrElseThrow(examId);
    boolean isInstructor = authCheckService.isAtLeastInstructorInCourse(course, user);
    if (!isInstructor && !exam.resultsPublished()) {
        throw new AccessForbiddenException();
    }
    GradeStepsDTO gradeStepsDTO = prepareGradeStepsDTO(gradingScale, exam.getMaxPoints(), exam.getTitle());
    return ResponseEntity.ok(gradeStepsDTO);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) User(de.tum.in.www1.artemis.domain.User) GradeStepsDTO(de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO) Course(de.tum.in.www1.artemis.domain.Course) Exam(de.tum.in.www1.artemis.domain.exam.Exam) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

GradeStepsDTO (de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO)8 Course (de.tum.in.www1.artemis.domain.Course)4 GradingScale (de.tum.in.www1.artemis.domain.GradingScale)4 Test (org.junit.jupiter.api.Test)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 User (de.tum.in.www1.artemis.domain.User)2 Exam (de.tum.in.www1.artemis.domain.exam.Exam)2 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)2