use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class ModelingSubmissionResource method updateModelingSubmission.
/**
* PUT /modeling-submissions : Updates an existing modelingSubmission.
*
* @param modelingSubmission the modelingSubmission to update
* @return the ResponseEntity with status 200 (OK) and with body the updated modelingSubmission,
* or with status 400 (Bad Request) if the modelingSubmission is not valid,
* or with status 500 (Internal Server Error) if the modelingSubmission couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/modeling-submissions")
@Timed
public ResponseEntity<ModelingSubmission> updateModelingSubmission(@RequestBody ModelingSubmission modelingSubmission) throws URISyntaxException {
log.debug("REST request to update ModelingSubmission : {}", modelingSubmission);
if (modelingSubmission.getId() == null) {
return createModelingSubmission(modelingSubmission);
}
ModelingSubmission result = modelingSubmissionRepository.save(modelingSubmission);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, modelingSubmission.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class ModelingSubmissionResource method createModelingSubmission.
/**
* POST /modeling-submissions : Create a new modelingSubmission.
*
* @param modelingSubmission the modelingSubmission to create
* @return the ResponseEntity with status 201 (Created) and with body the new modelingSubmission, or with status 400 (Bad Request) if the modelingSubmission has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/modeling-submissions")
@Timed
public ResponseEntity<ModelingSubmission> createModelingSubmission(@RequestBody ModelingSubmission modelingSubmission) throws URISyntaxException {
log.debug("REST request to save ModelingSubmission : {}", modelingSubmission);
if (modelingSubmission.getId() != null) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new modelingSubmission cannot already have an ID")).body(null);
}
ModelingSubmission result = modelingSubmissionRepository.save(modelingSubmission);
return ResponseEntity.created(new URI("/api/modeling-submissions/" + 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 ParticipationResource method getParticipationRepositoryWebUrl.
@GetMapping(value = "/participations/{id}/repositoryWebUrl")
@PreAuthorize("hasAnyRole('USER', 'TA', 'INSTRUCTOR', 'ADMIN')")
public ResponseEntity<String> getParticipationRepositoryWebUrl(@PathVariable Long id, Authentication authentication) {
log.debug("REST request to get Participation : {}", id);
Participation participation = participationService.findOne(id);
Course course = participation.getExercise().getCourse();
if (!authCheckService.isOwnerOfParticipation(participation)) {
if (!courseService.userHasTAPermissions(course)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
}
URL url = versionControlService.get().getRepositoryWebUrl(participation);
return Optional.ofNullable(url).map(result -> new ResponseEntity<>(url.toString(), HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class ParticipationResource method getParticipationBuildPlanWebUrl.
@GetMapping(value = "/participations/{id}/buildPlanWebUrl")
@PreAuthorize("hasAnyRole('USER', 'TA', 'INSTRUCTOR', 'ADMIN')")
public ResponseEntity<String> getParticipationBuildPlanWebUrl(@PathVariable Long id) {
log.debug("REST request to get Participation : {}", id);
Participation participation = participationService.findOne(id);
Course course = participation.getExercise().getCourse();
if (!authCheckService.isOwnerOfParticipation(participation)) {
if (!courseService.userHasTAPermissions(course)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
}
URL url = continuousIntegrationService.get().getBuildPlanWebUrl(participation);
return Optional.ofNullable(url).map(result -> new ResponseEntity<>(url.toString(), HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class ProgrammingExerciseResource method createProgrammingExercise.
/**
* POST /programming-exercises : Create a new programmingExercise.
*
* @param programmingExercise the programmingExercise to create
* @return the ResponseEntity with status 201 (Created) and with body the new programmingExercise, or with status 400 (Bad Request) if the programmingExercise has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/programming-exercises")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public ResponseEntity<ProgrammingExercise> createProgrammingExercise(@RequestBody ProgrammingExercise programmingExercise) throws URISyntaxException {
log.debug("REST request to save ProgrammingExercise : {}", programmingExercise);
if (programmingExercise.getId() != null) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new programmingExercise cannot already have an ID")).body(null);
}
// 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.created(new URI("/api/programming-exercises/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Aggregations