Search in sources :

Example 1 with ExerciseHint

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);
}
Also used : ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with ExerciseHint

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();
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) ConflictException(de.tum.in.www1.artemis.web.rest.errors.ConflictException) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) CodeHint(de.tum.in.www1.artemis.domain.hestia.CodeHint) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with ExerciseHint

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");
}
Also used : ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint) CodeHint(de.tum.in.www1.artemis.domain.hestia.CodeHint) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 4 with ExerciseHint

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);
}
Also used : ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint)

Example 5 with ExerciseHint

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);
}
Also used : ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ExerciseHint (de.tum.in.www1.artemis.domain.hestia.ExerciseHint)52 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)38 Test (org.junit.jupiter.api.Test)38 WithMockUser (org.springframework.security.test.context.support.WithMockUser)38 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 CodeHint (de.tum.in.www1.artemis.domain.hestia.CodeHint)10 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)8 ConflictException (de.tum.in.www1.artemis.web.rest.errors.ConflictException)8 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)6 Exercise (de.tum.in.www1.artemis.domain.Exercise)4 Feedback (de.tum.in.www1.artemis.domain.Feedback)2 Submission (de.tum.in.www1.artemis.domain.Submission)2 User (de.tum.in.www1.artemis.domain.User)2 ExerciseHintActivation (de.tum.in.www1.artemis.domain.hestia.ExerciseHintActivation)2 ProgrammingExerciseTask (de.tum.in.www1.artemis.domain.hestia.ProgrammingExerciseTask)2 StudentParticipationRepository (de.tum.in.www1.artemis.repository.StudentParticipationRepository)2 ExerciseHintActivationRepository (de.tum.in.www1.artemis.repository.hestia.ExerciseHintActivationRepository)2 ExerciseHintRepository (de.tum.in.www1.artemis.repository.hestia.ExerciseHintRepository)2 Role (de.tum.in.www1.artemis.security.Role)2