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);
}
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);
}
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);
}
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));
}
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();
}
Aggregations