Search in sources :

Example 11 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleResource method createGradingScaleForCourse.

/**
 * POST /courses/{courseId}/grading-scale : Create grading scale for course
 *
 * @param courseId the course to which the grading scale belongs
 * @param gradingScale the grading scale which will be created
 * @return ResponseEntity with status 201 (Created) with body the new grading scale if no such exists for the course
 *         and if it is correctly formatted and 400 (Bad request) otherwise
 */
@PostMapping("/courses/{courseId}/grading-scale")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<GradingScale> createGradingScaleForCourse(@PathVariable Long courseId, @RequestBody GradingScale gradingScale) throws URISyntaxException {
    log.debug("REST request to create a grading scale for course: {}", courseId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    Optional<GradingScale> existingGradingScale = gradingScaleRepository.findByCourseId(courseId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    validateGradingScale(existingGradingScale, gradingScale);
    if (!Objects.equals(gradingScale.getCourse().getMaxPoints(), course.getMaxPoints())) {
        course.setMaxPoints(gradingScale.getCourse().getMaxPoints());
        courseRepository.save(course);
    }
    gradingScale.setCourse(course);
    GradingScale savedGradingScale = gradingScaleService.saveGradingScale(gradingScale);
    return ResponseEntity.created(new URI("/api/courses/" + courseId + "/grading-scale/")).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, "")).body(savedGradingScale);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) Course(de.tum.in.www1.artemis.domain.Course) URI(java.net.URI) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 12 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleResource method createGradingScaleForExam.

/**
 * POST /courses/{courseId}/exams/{examId}grading-scale : Create grading scale for exam
 *
 * @param courseId the course to which the exam belongs
 * @param examId the exam to which the grading scale belongs
 * @param gradingScale the grading scale which will be created
 * @return ResponseEntity with status 201 (Created) with body the new grading scale if no such exists for the course
 *         and if it is correctly formatted and 400 (Bad request) otherwise
 */
@PostMapping("/courses/{courseId}/exams/{examId}/grading-scale")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<GradingScale> createGradingScaleForExam(@PathVariable Long courseId, @PathVariable Long examId, @RequestBody GradingScale gradingScale) throws URISyntaxException {
    log.debug("REST request to create a grading scale for exam: {}", examId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    Optional<GradingScale> existingGradingScale = gradingScaleRepository.findByExamId(examId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    validateGradingScale(existingGradingScale, gradingScale);
    Exam exam = examRepository.findByIdElseThrow(examId);
    if (gradingScale.getExam().getMaxPoints() != exam.getMaxPoints()) {
        exam.setMaxPoints(gradingScale.getExam().getMaxPoints());
        examRepository.save(exam);
    }
    gradingScale.setExam(exam);
    GradingScale savedGradingScale = gradingScaleService.saveGradingScale(gradingScale);
    return ResponseEntity.created(new URI("/api/courses/" + courseId + "/exams/" + examId + "/grading-scale/")).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, "")).body(savedGradingScale);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) Course(de.tum.in.www1.artemis.domain.Course) URI(java.net.URI) Exam(de.tum.in.www1.artemis.domain.exam.Exam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 13 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleResource method updateGradingScaleForCourse.

/**
 * PUT /courses/{courseId}/grading-scale : Update grading scale for course
 *
 * @param courseId the course to which the grading scale belongs
 * @param gradingScale the grading scale which will be updated
 * @return ResponseEntity with status 200 (Ok) with body the newly updated grading scale if it is correctly formatted and 400 (Bad request) otherwise
 */
@PutMapping("/courses/{courseId}/grading-scale")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<GradingScale> updateGradingScaleForCourse(@PathVariable Long courseId, @RequestBody GradingScale gradingScale) {
    log.debug("REST request to update a grading scale for course: {}", courseId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    GradingScale oldGradingScale = gradingScaleRepository.findByCourseIdOrElseThrow(courseId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    gradingScale.setId(oldGradingScale.getId());
    if (!Objects.equals(gradingScale.getCourse().getMaxPoints(), course.getMaxPoints())) {
        course.setMaxPoints(gradingScale.getCourse().getMaxPoints());
        courseRepository.save(course);
    }
    gradingScale.setCourse(course);
    GradingScale savedGradingScale = gradingScaleService.saveGradingScale(gradingScale);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, "")).body(savedGradingScale);
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 14 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleResource method getGradingScaleForCourse.

/**
 * GET /courses/{courseId}/grading-scale : Find grading scale for course
 *
 * @param courseId the course to which the grading scale belongs
 * @return ResponseEntity with status 200 (Ok) with body the grading scale if it exists and 404 (Not found) otherwise
 */
@GetMapping("/courses/{courseId}/grading-scale")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<GradingScale> getGradingScaleForCourse(@PathVariable Long courseId) {
    log.debug("REST request to get grading scale for course: {}", courseId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    Optional<GradingScale> gradingScale = gradingScaleRepository.findByCourseId(courseId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    return gradingScale.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.ok(null));
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 15 with GradingScale

use of de.tum.in.www1.artemis.domain.GradingScale in project ArTEMiS by ls1intum.

the class GradingScaleResource method deleteGradingScaleForCourse.

/**
 * DELETE /courses/{courseId}/grading-scale : Delete grading scale for course
 *
 * @param courseId the course 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}/grading-scale")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Void> deleteGradingScaleForCourse(@PathVariable Long courseId) {
    log.debug("REST request to delete the grading scale for course: {}", courseId);
    Course course = courseRepository.findByIdElseThrow(courseId);
    GradingScale gradingScale = gradingScaleRepository.findByCourseIdOrElseThrow(courseId);
    authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, course, null);
    gradingScaleRepository.delete(gradingScale);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, "")).build();
}
Also used : GradingScale(de.tum.in.www1.artemis.domain.GradingScale) Course(de.tum.in.www1.artemis.domain.Course) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

GradingScale (de.tum.in.www1.artemis.domain.GradingScale)72 WithMockUser (org.springframework.security.test.context.support.WithMockUser)62 Test (org.junit.jupiter.api.Test)60 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)44 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)42 GradeStep (de.tum.in.www1.artemis.domain.GradeStep)38 Course (de.tum.in.www1.artemis.domain.Course)28 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)24 Exam (de.tum.in.www1.artemis.domain.exam.Exam)14 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)10 GradeStepsDTO (de.tum.in.www1.artemis.web.rest.dto.GradeStepsDTO)8 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)4 User (de.tum.in.www1.artemis.domain.User)4 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)4 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)4 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)4 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)4 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)4