use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class ProgrammingExerciseSolutionEntryResource method createBehavioralSolutionEntries.
/**
* POST programming-exercises/:exerciseId/behavioral-solution-entries : Create the behavioral solution entries for a programming exercise
*
* @param exerciseId of the exercise
* @return the {@link ResponseEntity} with status {@code 200} and with body the created solution entries,
*/
@PostMapping("programming-exercises/{exerciseId}/behavioral-solution-entries")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<List<ProgrammingExerciseSolutionEntry>> createBehavioralSolutionEntries(@PathVariable Long exerciseId) {
log.debug("REST request to create behavioral solution entries");
ProgrammingExercise exercise = programmingExerciseRepository.findByIdWithTemplateAndSolutionParticipationElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, exercise, null);
try {
var solutionEntries = behavioralTestCaseService.generateBehavioralSolutionEntries(exercise);
return ResponseEntity.ok(solutionEntries);
} catch (BehavioralSolutionEntryGenerationException e) {
log.error("Unable to create behavioral solution entries", e);
throw new InternalServerErrorException(e.getMessage());
}
}
use of de.tum.in.www1.artemis.domain.metis.Post 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);
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class PostResource method getPostsInCourse.
/**
* GET /courses/{courseId}/posts : Get all posts for a course by its id
*
* @param pageable pagination settings to fetch posts in smaller batches
* @param pagingEnabled flag stating whether requesting component has paging enabled or not
* @param postContextFilter request param for filtering posts
* @return ResponseEntity with status 200 (OK) and with body all posts for course, that match the specified context
* or 400 (Bad Request) if the checks on user, course or post validity fail
*/
@GetMapping("courses/{courseId}/posts")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<List<Post>> getPostsInCourse(@ApiParam Pageable pageable, @RequestParam(defaultValue = "false") boolean pagingEnabled, PostContextFilter postContextFilter) {
Page<Post> coursePosts = postService.getPostsInCourse(pagingEnabled, pageable, postContextFilter);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), coursePosts);
return new ResponseEntity<>(coursePosts.getContent(), headers, HttpStatus.OK);
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class AnswerPostService method deleteAnswerPostById.
/**
* Checks course and user validity,
* determines authority to delete post and deletes the post
*
* @param courseId id of the course the answer post belongs to
* @param answerPostId id of the answer post to delete
*/
public void deleteAnswerPostById(Long courseId, Long answerPostId) {
final User user = userRepository.getUserWithGroupsAndAuthorities();
// checks
final Course course = preCheckUserAndCourse(user, courseId);
AnswerPost answerPost = answerPostRepository.findByIdElseThrow(answerPostId);
mayUpdateOrDeletePostingElseThrow(answerPost, user, course);
// delete
answerPostRepository.deleteById(answerPostId);
// we need to explicitly remove the answer post from the answers of the broadcast post to share up-to-date information
Post updatedPost = answerPost.getPost();
updatedPost.removeAnswerPost(answerPost);
broadcastForPost(new MetisPostDTO(updatedPost, MetisPostAction.UPDATE_POST), course);
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class AnswerPostService method createAnswerPost.
/**
* Checks course, user and answer post and associated post validity,
* determines the associated post, the answer post's author,
* sets to approved if author is at least a tutor,
* persists the answer post, and sends a notification to affected user groups
*
* @param courseId id of the course the answer post belongs to
* @param answerPost answer post to create
* @return created answer post that was persisted
*/
public AnswerPost createAnswerPost(Long courseId, AnswerPost answerPost) {
final User user = this.userRepository.getUserWithGroupsAndAuthorities();
// check
if (answerPost.getId() != null) {
throw new BadRequestAlertException("A new answer post cannot already have an ID", METIS_ANSWER_POST_ENTITY_NAME, "idexists");
}
final Course course = preCheckUserAndCourse(user, courseId);
Post post = postRepository.findByIdElseThrow(answerPost.getPost().getId());
// use post from database rather than user input
answerPost.setPost(post);
// set author to current user
answerPost.setAuthor(user);
// on creation of an answer post, we set the resolves_post field to false per default
answerPost.setResolvesPost(false);
AnswerPost savedAnswerPost = answerPostRepository.save(answerPost);
this.preparePostAndBroadcast(savedAnswerPost, course);
sendNotification(post, answerPost, course);
return savedAnswerPost;
}
Aggregations