use of de.tum.in.www1.artemis.domain.Result 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.Result in project ArTEMiS by ls1intum.
the class ModelingExerciseResource method updateModelingExercise.
/**
* PUT /modeling-exercises : Updates an existing modelingExercise.
*
* @param modelingExercise the modelingExercise to update
* @return the ResponseEntity with status 200 (OK) and with body the updated modelingExercise,
* or with status 400 (Bad Request) if the modelingExercise is not valid,
* or with status 500 (Internal Server Error) if the modelingExercise couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/modeling-exercises")
@Timed
public ResponseEntity<ModelingExercise> updateModelingExercise(@RequestBody ModelingExercise modelingExercise) throws URISyntaxException {
log.debug("REST request to update ModelingExercise : {}", modelingExercise);
if (modelingExercise.getId() == null) {
return createModelingExercise(modelingExercise);
}
ModelingExercise result = modelingExerciseRepository.save(modelingExercise);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, modelingExercise.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Result 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.Result in project ArTEMiS by ls1intum.
the class ProgrammingExerciseResource method updateProgrammingExercise.
/**
* PUT /programming-exercises : Updates an existing programmingExercise.
*
* @param programmingExercise the programmingExercise to update
* @return the ResponseEntity with status 200 (OK) and with body the updated programmingExercise,
* or with status 400 (Bad Request) if the programmingExercise is not valid,
* or with status 500 (Internal Server Error) if the programmingExercise couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/programming-exercises")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public ResponseEntity<ProgrammingExercise> updateProgrammingExercise(@RequestBody ProgrammingExercise programmingExercise) throws URISyntaxException {
log.debug("REST request to update ProgrammingExercise : {}", programmingExercise);
if (programmingExercise.getId() == null) {
return createProgrammingExercise(programmingExercise);
}
// fetch course from database to make sure client didn't change groups
Course course = courseService.findOne(programmingExercise.getCourse().getId());
if (course == null) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "courseNotFound", "The course belonging to this programming exercise does not exist")).body(null);
}
User user = userService.getUserWithGroupsAndAuthorities();
if (!authCheckService.isTeachingAssistantInCourse(course, user) && !authCheckService.isInstructorInCourse(course, user) && !authCheckService.isAdmin()) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
ResponseEntity<ProgrammingExercise> errorResponse = checkProgrammingExerciseForError(programmingExercise);
if (errorResponse != null) {
return errorResponse;
}
ProgrammingExercise result = programmingExerciseRepository.save(programmingExercise);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, programmingExercise.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class ExceptionTranslator method handleMethodArgumentNotValid.
@Override
public ResponseEntity<Problem> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, @Nonnull NativeWebRequest request) {
BindingResult result = ex.getBindingResult();
List<FieldErrorVM> fieldErrors = result.getFieldErrors().stream().map(f -> new FieldErrorVM(f.getObjectName(), f.getField(), f.getCode())).collect(Collectors.toList());
Problem problem = Problem.builder().withType(ErrorConstants.CONSTRAINT_VIOLATION_TYPE).withTitle("Method argument not valid").withStatus(defaultConstraintViolationStatus()).with("message", ErrorConstants.ERR_VALIDATION).with("fieldErrors", fieldErrors).build();
return create(ex, problem, request);
}
Aggregations