use of de.tum.in.www1.artemis.domain.hestia.ExerciseHint in project Artemis by ls1intum.
the class ExerciseHintResource method getExerciseHintsForExercise.
/**
* {@code GET exercises/:exerciseId/exercise-hints} : get the exerciseHints of a provided exercise.
*
* @param exerciseId the exercise id of which to retrieve the exercise hints.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the exerciseHint,
* or with status {@code 404 (Not Found)},
* or with status {@code 409 (Conflict)} if the exerciseId is not valid.
*/
@GetMapping("exercises/{exerciseId}/exercise-hints")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Set<ExerciseHint>> getExerciseHintsForExercise(@PathVariable Long exerciseId) {
log.debug("REST request to get ExerciseHint : {}", exerciseId);
ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.STUDENT, programmingExercise, null);
Set<ExerciseHint> exerciseHints = exerciseHintRepository.findByExerciseId(exerciseId);
return ResponseEntity.ok(exerciseHints);
}
use of de.tum.in.www1.artemis.domain.hestia.ExerciseHint in project Artemis by ls1intum.
the class ExerciseHintResource method deleteExerciseHint.
/**
* {@code DELETE exercises/:exerciseId/exercise-hints/:exerciseHintId} : delete the exerciseHint with given id.
*
* @param exerciseHintId the id of the exerciseHint to delete
* @param exerciseId the exercise id of which to delete the exercise hint
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)},
* or with status {@code 400 (Bad Request)} if the exerciseHint is a codeHint,
* or with status {@code 409 (Conflict)} if the exerciseId is not valid.
*/
@DeleteMapping("exercises/{exerciseId}/exercise-hints/{exerciseHintId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Void> deleteExerciseHint(@PathVariable Long exerciseId, @PathVariable Long exerciseHintId) {
log.debug("REST request to delete ExerciseHint : {}", exerciseHintId);
ProgrammingExercise exercise = programmingExerciseRepository.findByIdElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.EDITOR, exercise, null);
var exerciseHint = exerciseHintRepository.findByIdElseThrow(exerciseHintId);
if (exerciseHint instanceof CodeHint) {
throw new BadRequestAlertException("A code hint cannot be deleted manually.", CODE_HINT_ENTITY_NAME, "manualCodeHintOperation");
}
if (!exerciseHint.getExercise().getId().equals(exerciseId)) {
throw new ConflictException("An exercise hint can only be deleted if the exerciseIds match.", EXERCISE_HINT_ENTITY_NAME, "exerciseIdsMismatch");
}
exerciseHintRepository.deleteById(exerciseHintId);
return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, EXERCISE_HINT_ENTITY_NAME, exerciseHintId.toString())).build();
}
use of de.tum.in.www1.artemis.domain.hestia.ExerciseHint in project Artemis by ls1intum.
the class ExerciseHintIntegrationTest method updateCodeHintShouldFail.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void updateCodeHintShouldFail() throws Exception {
CodeHint codeHint = new CodeHint();
codeHint.setTitle("Hint 1");
codeHint.setExercise(exercise);
exerciseHintRepository.save(codeHint);
codeHint.setTitle("New Title");
request.put("/api/exercises/" + codeHint.getExercise().getId() + "/exercise-hints/" + codeHint.getId(), codeHint, HttpStatus.BAD_REQUEST);
Optional<ExerciseHint> hintAfterSave = exerciseHintRepository.findById(codeHint.getId());
assertThat(hintAfterSave).isPresent();
assertThat(hintAfterSave.get()).isInstanceOf(CodeHint.class);
assertThat((hintAfterSave.get()).getTitle()).isEqualTo("Hint 1");
}
use of de.tum.in.www1.artemis.domain.hestia.ExerciseHint in project Artemis by ls1intum.
the class DatabaseUtilService method addHintsToExercise.
public void addHintsToExercise(Exercise exercise) {
ExerciseHint exerciseHint1 = new ExerciseHint().content("content 1").exercise(exercise).title("title 1");
ExerciseHint exerciseHint2 = new ExerciseHint().content("content 2").exercise(exercise).title("title 2");
ExerciseHint exerciseHint3 = new ExerciseHint().content("content 3").exercise(exercise).title("title 3");
Set<ExerciseHint> hints = new HashSet<>();
hints.add(exerciseHint1);
hints.add(exerciseHint2);
hints.add(exerciseHint3);
exercise.setExerciseHints(hints);
exerciseHintRepository.saveAll(hints);
}
use of de.tum.in.www1.artemis.domain.hestia.ExerciseHint in project ArTEMiS by ls1intum.
the class ExerciseHintResource method getExerciseHintsForExercise.
/**
* {@code GET exercises/:exerciseId/exercise-hints} : get the exerciseHints of a provided exercise.
*
* @param exerciseId the exercise id of which to retrieve the exercise hints.
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the exerciseHint,
* or with status {@code 404 (Not Found)},
* or with status {@code 409 (Conflict)} if the exerciseId is not valid.
*/
@GetMapping("exercises/{exerciseId}/exercise-hints")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Set<ExerciseHint>> getExerciseHintsForExercise(@PathVariable Long exerciseId) {
log.debug("REST request to get ExerciseHint : {}", exerciseId);
ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.STUDENT, programmingExercise, null);
Set<ExerciseHint> exerciseHints = exerciseHintRepository.findByExerciseId(exerciseId);
return ResponseEntity.ok(exerciseHints);
}
Aggregations