use of de.tum.in.www1.artemis.domain.lecture in project ArTEMiS by ls1intum.
the class LectureResource method getLectureWithDetails.
/**
* GET /lectures/:lectureId/details : get the "lectureId" lecture.
*
* @param lectureId the lectureId of the lecture to retrieve
* @return the ResponseEntity with status 200 (OK) and with body the lecture including posts, lecture units and learning goals, or with status 404 (Not Found)
*/
@GetMapping("/lectures/{lectureId}/details")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Lecture> getLectureWithDetails(@PathVariable Long lectureId) {
log.debug("REST request to get lecture {} with details", lectureId);
Lecture lecture = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoalsElseThrow(lectureId);
Course course = lecture.getCourse();
if (course == null) {
return ResponseEntity.badRequest().build();
}
User user = userRepository.getUserWithGroupsAndAuthorities();
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, user);
lecture = filterLectureContentForUser(lecture, user);
return ResponseEntity.ok(lecture);
}
use of de.tum.in.www1.artemis.domain.lecture in project ArTEMiS by ls1intum.
the class LectureResource method createLecture.
/**
* POST /lectures : Create a new lecture.
*
* @param lecture the lecture to create
* @return the ResponseEntity with status 201 (Created) and with body the new lecture, or with status 400 (Bad Request) if the lecture has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/lectures")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Lecture> createLecture(@RequestBody Lecture lecture) throws URISyntaxException {
log.debug("REST request to save Lecture : {}", lecture);
if (lecture.getId() != null) {
throw new BadRequestAlertException("A new lecture cannot already have an ID", ENTITY_NAME, "idexists");
}
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, lecture.getCourse(), null);
Lecture result = lectureRepository.save(lecture);
return ResponseEntity.created(new URI("/api/lectures/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.lecture in project ArTEMiS by ls1intum.
the class LearningGoalIntegrationTest method creatingLectureUnitsOfLectureOne.
private void creatingLectureUnitsOfLectureOne() {
// creating lecture units for lecture one
TextUnit textUnit = new TextUnit();
textUnit.setName("TextUnitOfLectureOne");
textUnit = textUnitRepository.save(textUnit);
idOfTextUnitOfLectureOne = textUnit.getId();
Exercise textExercise = exerciseRepository.findById(idOfTextExercise).get();
ExerciseUnit textExerciseUnit = new ExerciseUnit();
textExerciseUnit.setExercise(textExercise);
textExerciseUnit = exerciseUnitRepository.save(textExerciseUnit);
idOfExerciseUnitTextOfLectureOne = textExerciseUnit.getId();
Exercise modelingExercise = exerciseRepository.findById(idOfModelingExercise).get();
ExerciseUnit modelingExerciseUnit = new ExerciseUnit();
modelingExerciseUnit.setExercise(modelingExercise);
modelingExerciseUnit = exerciseUnitRepository.save(modelingExerciseUnit);
idOfExerciseUnitModelingOfLectureOne = modelingExerciseUnit.getId();
Exercise textTeamExercise = exerciseRepository.findById(idOfTeamTextExercise).get();
ExerciseUnit teamTextExerciseUnit = new ExerciseUnit();
teamTextExerciseUnit.setExercise(textTeamExercise);
teamTextExerciseUnit = exerciseUnitRepository.save(teamTextExerciseUnit);
List<LectureUnit> lectureUnitsOfLectureOne = List.of(textUnit, textExerciseUnit, modelingExerciseUnit, teamTextExerciseUnit);
Lecture lectureOne = lectureRepository.findByIdWithPostsAndLectureUnitsAndLearningGoals(idOfLectureOne).get();
for (LectureUnit lectureUnit : lectureUnitsOfLectureOne) {
lectureOne.addLectureUnit(lectureUnit);
}
lectureRepository.save(lectureOne);
}
use of de.tum.in.www1.artemis.domain.lecture in project ArTEMiS by ls1intum.
the class TextUnitIntegrationTest method updateTextUnit_asEditor_shouldKeepOrdering.
@Test
@WithMockUser(username = "editor1", roles = "EDITOR")
public void updateTextUnit_asEditor_shouldKeepOrdering() throws Exception {
persistTextUnitWithLecture();
// Add a second lecture unit
TextUnit textUnit = database.createTextUnit();
lecture.addLectureUnit(textUnit);
lecture = lectureRepository.save(lecture);
List<LectureUnit> orderedUnits = lecture.getLectureUnits();
// Updating the lecture unit should not change order attribute
request.putWithResponseBody("/api/lectures/" + lecture.getId() + "/text-units", textUnit, TextUnit.class, HttpStatus.OK);
List<LectureUnit> updatedOrderedUnits = lectureRepository.findByIdWithLectureUnits(lecture.getId()).get().getLectureUnits();
assertThat(updatedOrderedUnits).containsExactlyElementsOf(orderedUnits);
}
use of de.tum.in.www1.artemis.domain.lecture in project ArTEMiS by ls1intum.
the class LectureImportServiceTest method testImportLectureToCourse.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testImportLectureToCourse() {
int lectureCount = this.course2.getLectures().size();
lectureImportService.importLecture(this.lecture1, this.course2);
assertThat(this.course2.getLectures().size()).isEqualTo(lectureCount + 1);
// Find the imported lecture and fetch it with lecture units
Long lecture2Id = this.course2.getLectures().stream().skip(lectureCount).findFirst().get().getId();
Lecture lecture2 = this.lectureRepository.findByIdWithLectureUnitsElseThrow(lecture2Id);
assertThat(lecture2.getTitle()).isEqualTo(this.lecture1.getTitle());
// Assert that all lecture units (except exercise units) were copied
assertThat(lecture2.getLectureUnits().stream().map(LectureUnit::getName).toList()).containsExactlyElementsOf(this.lecture1.getLectureUnits().stream().filter(lectureUnit -> !(lectureUnit instanceof ExerciseUnit)).map(LectureUnit::getName).toList());
assertThat(lecture2.getAttachments().stream().map(Attachment::getName).toList()).containsExactlyElementsOf(this.lecture1.getAttachments().stream().map(Attachment::getName).toList());
lectureRepository.delete(lecture2);
}
Aggregations