use of de.tum.in.www1.artemis.web.rest.errors.ConflictException in project Artemis by ls1intum.
the class ExerciseHintResource method deleteExerciseHint.
/**
* {@code DELETE exercises/:exerciseId/exercise-hints/:exerciseHintId} : delete the exerciseHint with given id.
*
* @param exerciseHintId the id of the exerciseHint to delete
* @param exerciseId the exercise id of which to delete the exercise hint
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)},
* or with status {@code 400 (Bad Request)} if the exerciseHint is a codeHint,
* or with status {@code 409 (Conflict)} if the exerciseId is not valid.
*/
@DeleteMapping("exercises/{exerciseId}/exercise-hints/{exerciseHintId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Void> deleteExerciseHint(@PathVariable Long exerciseId, @PathVariable Long exerciseHintId) {
log.debug("REST request to delete ExerciseHint : {}", exerciseHintId);
ProgrammingExercise exercise = programmingExerciseRepository.findByIdElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, exercise, null);
var exerciseHint = exerciseHintRepository.findByIdElseThrow(exerciseHintId);
if (exerciseHint instanceof CodeHint) {
throw new BadRequestAlertException("A code hint cannot be deleted manually.", CODE_HINT_ENTITY_NAME, "manualCodeHintOperation");
}
if (!exerciseHint.getExercise().getId().equals(exerciseId)) {
throw new ConflictException("An exercise hint can only be deleted if the exerciseIds match.", EXERCISE_HINT_ENTITY_NAME, "exerciseIdsMismatch");
}
exerciseHintRepository.deleteById(exerciseHintId);
return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, EXERCISE_HINT_ENTITY_NAME, exerciseHintId.toString())).build();
}
use of de.tum.in.www1.artemis.web.rest.errors.ConflictException in project ArTEMiS by ls1intum.
the class ExerciseHintResource method deleteExerciseHint.
/**
* {@code DELETE exercises/:exerciseId/exercise-hints/:exerciseHintId} : delete the exerciseHint with given id.
*
* @param exerciseHintId the id of the exerciseHint to delete
* @param exerciseId the exercise id of which to delete the exercise hint
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)},
* or with status {@code 400 (Bad Request)} if the exerciseHint is a codeHint,
* or with status {@code 409 (Conflict)} if the exerciseId is not valid.
*/
@DeleteMapping("exercises/{exerciseId}/exercise-hints/{exerciseHintId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Void> deleteExerciseHint(@PathVariable Long exerciseId, @PathVariable Long exerciseHintId) {
log.debug("REST request to delete ExerciseHint : {}", exerciseHintId);
ProgrammingExercise exercise = programmingExerciseRepository.findByIdElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, exercise, null);
var exerciseHint = exerciseHintRepository.findByIdElseThrow(exerciseHintId);
if (exerciseHint instanceof CodeHint) {
throw new BadRequestAlertException("A code hint cannot be deleted manually.", CODE_HINT_ENTITY_NAME, "manualCodeHintOperation");
}
if (!exerciseHint.getExercise().getId().equals(exerciseId)) {
throw new ConflictException("An exercise hint can only be deleted if the exerciseIds match.", EXERCISE_HINT_ENTITY_NAME, "exerciseIdsMismatch");
}
exerciseHintRepository.deleteById(exerciseHintId);
return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, EXERCISE_HINT_ENTITY_NAME, exerciseHintId.toString())).build();
}
use of de.tum.in.www1.artemis.web.rest.errors.ConflictException in project ArTEMiS by ls1intum.
the class ApollonDiagramResource method updateApollonDiagram.
/**
* PUT /course/{courseId}/apollon-diagrams : Updates an existing apollonDiagram.
*
* @param apollonDiagram the apollonDiagram to update
* @param courseId the id of the current course
* @return the ResponseEntity with status 200 (OK) and with body the updated apollonDiagram, or with status 201 (CREATED) if the apollonDiagram has not been created before, or with status
* 500 (Internal Server Error) if the apollonDiagram couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/course/{courseId}/apollon-diagrams")
@PreAuthorize("hasRole('TA')")
public ResponseEntity<ApollonDiagram> updateApollonDiagram(@RequestBody ApollonDiagram apollonDiagram, @PathVariable Long courseId) throws URISyntaxException {
log.debug("REST request to update ApollonDiagram : {}", apollonDiagram);
if (apollonDiagram.getId() == null) {
return createApollonDiagram(apollonDiagram, courseId);
}
if (!Objects.equals(apollonDiagram.getCourseId(), courseId)) {
throw new ConflictException("Specified course id does not match request payload", "ApollonDiagram", "courseMismatch");
}
Course course = courseRepository.findByIdElseThrow(courseId);
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.TEACHING_ASSISTANT, course, null);
ApollonDiagram result = apollonDiagramRepository.save(apollonDiagram);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, apollonDiagram.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.web.rest.errors.ConflictException in project ArTEMiS by ls1intum.
the class AttachmentUnitResource method getAttachmentUnit.
/**
* GET /lectures/:lectureId/attachment-units/:attachmentUnitId : gets the attachment unit with the specified id
*
* @param attachmentUnitId the id of the attachmentUnit to retrieve
* @param lectureId the id of the lecture to which the unit belongs
* @return the ResponseEntity with status 200 (OK) and with body the attachment unit, or with status 404 (Not Found)
*/
@GetMapping("/lectures/{lectureId}/attachment-units/{attachmentUnitId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<AttachmentUnit> getAttachmentUnit(@PathVariable Long attachmentUnitId, @PathVariable Long lectureId) {
log.debug("REST request to get AttachmentUnit : {}", attachmentUnitId);
AttachmentUnit attachmentUnit = attachmentUnitRepository.findByIdElseThrow(attachmentUnitId);
if (attachmentUnit.getLecture() == null || attachmentUnit.getLecture().getCourse() == null) {
throw new ConflictException("Lecture unit must be associated to a lecture of a course", "AttachmentUnit", "lectureOrCourseMissing");
}
if (!attachmentUnit.getLecture().getId().equals(lectureId)) {
throw new ConflictException("Requested lecture unit is not part of the specified lecture", "AttachmentUnit", "lectureIdMismatch");
}
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, attachmentUnit.getLecture().getCourse(), null);
return ResponseEntity.ok().body(attachmentUnit);
}
use of de.tum.in.www1.artemis.web.rest.errors.ConflictException in project ArTEMiS by ls1intum.
the class ExerciseUnitResource method getAllExerciseUnitsOfLecture.
/**
* GET /lectures/:lectureId/exercise-units : gets the exercise units associated with a lecture
*
* @param lectureId the id of the lecture to get the exercise-units for
* @return the ResponseEntity with status 200 (OK) and with body the found exercise units
*/
@GetMapping("/lectures/{lectureId}/exercise-units")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<List<ExerciseUnit>> getAllExerciseUnitsOfLecture(@PathVariable Long lectureId) {
log.debug("REST request to get all exercise units for lecture : {}", lectureId);
Lecture lecture = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoalsElseThrow(lectureId);
if (lecture.getCourse() == null) {
throw new ConflictException("Specified lecture is not part of a course", "ExerciseUnit", "courseMissing");
}
authorizationCheckService.checkHasAtLeastRoleForLectureElseThrow(Role.EDITOR, lecture, null);
List<ExerciseUnit> exerciseUnitsOfLecture = exerciseUnitRepository.findByLectureId(lectureId);
return ResponseEntity.ok().body(exerciseUnitsOfLecture);
}
Aggregations