use of de.tum.in.www1.artemis.domain.lecture 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.domain.lecture 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);
}
use of de.tum.in.www1.artemis.domain.lecture in project ArTEMiS by ls1intum.
the class LectureUnitResource method deleteLectureUnit.
/**
* DELETE lectures/:lectureId/lecture-units/:lectureUnitId
*
* @param lectureId the id of the lecture to which the unit belongs
* @param lectureUnitId the id of the lecture unit to remove
* @return the ResponseEntity with status 200 (OK)
*/
@DeleteMapping("/lectures/{lectureId}/lecture-units/{lectureUnitId}")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Void> deleteLectureUnit(@PathVariable Long lectureUnitId, @PathVariable Long lectureId) {
log.info("REST request to delete lecture unit: {}", lectureUnitId);
LectureUnit lectureUnit = lectureUnitRepository.findByIdWithLearningGoalsBidirectionalElseThrow(lectureUnitId);
if (lectureUnit.getLecture() == null || lectureUnit.getLecture().getCourse() == null) {
throw new ConflictException("Lecture unit must be associated to a lecture of a course", "LectureUnit", "lectureOrCourseMissing");
}
if (!lectureUnit.getLecture().getId().equals(lectureId)) {
throw new ConflictException("Requested lecture unit is not part of the specified lecture", "LectureUnit", "lectureIdMismatch");
}
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, lectureUnit.getLecture().getCourse(), null);
String lectureUnitName;
if (lectureUnit instanceof ExerciseUnit && ((ExerciseUnit) lectureUnit).getExercise() != null) {
lectureUnitName = ((ExerciseUnit) lectureUnit).getExercise().getTitle();
} else if (lectureUnit instanceof AttachmentUnit && ((AttachmentUnit) lectureUnit).getAttachment() != null) {
lectureUnitName = ((AttachmentUnit) lectureUnit).getAttachment().getName();
} else {
lectureUnitName = lectureUnit.getName();
}
if (Objects.isNull(lectureUnitName)) {
lectureUnitName = "lectureUnitWithoutName";
}
lectureUnitService.removeLectureUnit(lectureUnit);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, lectureUnitName)).build();
}
use of de.tum.in.www1.artemis.domain.lecture in project ArTEMiS by ls1intum.
the class TextUnitResource method getTextUnit.
/**
* GET lectures/:lectureId/text-units/:textUnitId : gets the text unit with the specified id
*
* @param textUnitId the id of the textUnit 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 text unit, or with status 404 (Not Found)
*/
@GetMapping("lectures/{lectureId}/text-units/{textUnitId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<TextUnit> getTextUnit(@PathVariable Long textUnitId, @PathVariable Long lectureId) {
log.debug("REST request to get TextUnit : {}", textUnitId);
Optional<TextUnit> optionalTextUnit = textUnitRepository.findById(textUnitId);
if (optionalTextUnit.isEmpty()) {
throw new EntityNotFoundException("TextUnit");
}
TextUnit textUnit = optionalTextUnit.get();
if (textUnit.getLecture() == null || textUnit.getLecture().getCourse() == null || !textUnit.getLecture().getId().equals(lectureId)) {
throw new ConflictException("Input data not valid", ENTITY_NAME, "inputInvalid");
}
authorizationCheckService.checkHasAtLeastRoleForLectureElseThrow(Role.EDITOR, textUnit.getLecture(), null);
return ResponseEntity.ok().body(textUnit);
}
use of de.tum.in.www1.artemis.domain.lecture in project ArTEMiS by ls1intum.
the class VideoUnitResource method createVideoUnit.
/**
* POST /lectures/:lectureId/video-units : creates a new video unit.
*
* @param lectureId the id of the lecture to which the video unit should be added
* @param videoUnit the video unit that should be created
* @return the ResponseEntity with status 201 (Created) and with body the new video unit
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/lectures/{lectureId}/video-units")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<VideoUnit> createVideoUnit(@PathVariable Long lectureId, @RequestBody VideoUnit videoUnit) throws URISyntaxException {
log.debug("REST request to create VideoUnit : {}", videoUnit);
if (videoUnit.getId() != null) {
throw new BadRequestException();
}
normalizeVideoUrl(videoUnit);
validateVideoUrl(videoUnit);
Lecture lecture = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoalsElseThrow(lectureId);
if (lecture.getCourse() == null) {
throw new ConflictException("Specified lecture is not part of a course", "VideoUnit", "courseMissing");
}
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, lecture.getCourse(), null);
// persist lecture unit before lecture to prevent "null index column for collection" error
videoUnit.setLecture(null);
videoUnit = videoUnitRepository.saveAndFlush(videoUnit);
videoUnit.setLecture(lecture);
lecture.addLectureUnit(videoUnit);
Lecture updatedLecture = lectureRepository.save(lecture);
VideoUnit persistedVideoUnit = (VideoUnit) updatedLecture.getLectureUnits().get(updatedLecture.getLectureUnits().size() - 1);
return ResponseEntity.created(new URI("/api/video-units/" + persistedVideoUnit.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, "")).body(persistedVideoUnit);
}
Aggregations