use of de.tum.in.www1.artemis.domain.Course in project ArTEMiS by ls1intum.
the class CourseResourceIntTest method createCourse.
@Test
@Transactional
public void createCourse() throws Exception {
int databaseSizeBeforeCreate = courseRepository.findAll().size();
// Create the Course
restCourseMockMvc.perform(post("/api/courses").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(course))).andExpect(status().isCreated());
// Validate the Course in the database
List<Course> courseList = courseRepository.findAll();
assertThat(courseList).hasSize(databaseSizeBeforeCreate + 1);
Course testCourse = courseList.get(courseList.size() - 1);
assertThat(testCourse.getTitle()).isEqualTo(DEFAULT_TITLE);
assertThat(testCourse.getStudentGroupName()).isEqualTo(DEFAULT_STUDENT_GROUP_NAME);
assertThat(testCourse.getTeachingAssistantGroupName()).isEqualTo(DEFAULT_TEACHING_ASSISTANT_GROUP_NAME);
assertThat(testCourse.getInstructorGroupName()).isEqualTo(DEFAULT_INSTRUCTOR_GROUP_NAME);
assertThat(testCourse.getStartDate()).isEqualTo(DEFAULT_START_DATE);
assertThat(testCourse.getEndDate()).isEqualTo(DEFAULT_END_DATE);
assertThat(testCourse.isOnlineCourse()).isEqualTo(DEFAULT_ONLINE_COURSE);
}
use of de.tum.in.www1.artemis.domain.Course in project ArTEMiS by ls1intum.
the class CourseResourceIntTest method updateCourse.
@Test
@Transactional
public void updateCourse() throws Exception {
// Initialize the database
courseService.save(course);
int databaseSizeBeforeUpdate = courseRepository.findAll().size();
// Update the course
Course updatedCourse = courseRepository.findOne(course.getId());
updatedCourse.title(UPDATED_TITLE).studentGroupName(UPDATED_STUDENT_GROUP_NAME).teachingAssistantGroupName(UPDATED_TEACHING_ASSISTANT_GROUP_NAME).instructorGroupName(UPDATED_INSTRUCTOR_GROUP_NAME).startDate(UPDATED_START_DATE).endDate(UPDATED_END_DATE).onlineCourse(UPDATED_ONLINE_COURSE);
restCourseMockMvc.perform(put("/api/courses").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedCourse))).andExpect(status().isOk());
// Validate the Course in the database
List<Course> courseList = courseRepository.findAll();
assertThat(courseList).hasSize(databaseSizeBeforeUpdate);
Course testCourse = courseList.get(courseList.size() - 1);
assertThat(testCourse.getTitle()).isEqualTo(UPDATED_TITLE);
assertThat(testCourse.getStudentGroupName()).isEqualTo(UPDATED_STUDENT_GROUP_NAME);
assertThat(testCourse.getTeachingAssistantGroupName()).isEqualTo(UPDATED_TEACHING_ASSISTANT_GROUP_NAME);
assertThat(testCourse.getInstructorGroupName()).isEqualTo(UPDATED_INSTRUCTOR_GROUP_NAME);
assertThat(testCourse.getStartDate()).isEqualTo(UPDATED_START_DATE);
assertThat(testCourse.getEndDate()).isEqualTo(UPDATED_END_DATE);
assertThat(testCourse.isOnlineCourse()).isEqualTo(UPDATED_ONLINE_COURSE);
}
use of de.tum.in.www1.artemis.domain.Course in project ArTEMiS by ls1intum.
the class CourseResource method createCourse.
/**
* POST /courses : Create a new course.
*
* @param course the course to create
* @return the ResponseEntity with status 201 (Created) and with body the new course, or with status 400 (Bad Request) if the course has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/courses")
@PreAuthorize("hasAnyRole('ADMIN')")
@Timed
public ResponseEntity<Course> createCourse(@RequestBody Course course) throws URISyntaxException {
log.debug("REST request to save Course : {}", course);
if (course.getId() != null) {
throw new BadRequestAlertException("A new course cannot already have an ID", ENTITY_NAME, "idexists");
}
Course result = courseService.save(course);
return ResponseEntity.created(new URI("/api/courses/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Course in project ArTEMiS by ls1intum.
the class ParticipationResource method createParticipation.
/**
* POST /participations : Create a new participation.
*
* @param participation the participation to create
* @return the ResponseEntity with status 201 (Created) and with body the new participation, or with status 400 (Bad Request) if the participation has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/participations")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public ResponseEntity<Participation> createParticipation(@RequestBody Participation participation) throws URISyntaxException {
log.debug("REST request to save Participation : {}", participation);
Course course = participation.getExercise().getCourse();
if (!courseService.userHasTAPermissions(course)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
if (participation.getId() != null) {
throw new BadRequestAlertException("A new participation cannot already have an ID", ENTITY_NAME, "idexists");
}
Participation result = participationService.save(participation);
return ResponseEntity.created(new URI("/api/participations/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Course in project ArTEMiS by ls1intum.
the class ProgrammingExerciseResource method getAllProgrammingExercises.
/**
* GET /programming-exercises : get all the programmingExercises.
*
* @return the ResponseEntity with status 200 (OK) and the list of programmingExercises in body
*/
@GetMapping("/programming-exercises")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public List<ProgrammingExercise> getAllProgrammingExercises() {
log.debug("REST request to get all ProgrammingExercises");
List<ProgrammingExercise> exercises = programmingExerciseRepository.findAll();
Stream<ProgrammingExercise> authorizedExercises = exercises.stream().filter(exercise -> {
Course course = exercise.getCourse();
User user = userService.getUserWithGroupsAndAuthorities();
return authCheckService.isTeachingAssistantInCourse(course, user) || authCheckService.isInstructorInCourse(course, user) || authCheckService.isAdmin();
});
return authorizedExercises.collect(Collectors.toList());
}
Aggregations