use of de.tum.in.www1.artemis.domain.Feedback in project ArTEMiS by ls1intum.
the class ResultResource method createResult.
/**
* POST /results : Create a new manual result.
*
* @param result the result to create
* @return the ResponseEntity with status 201 (Created) and with body the new result, or with status 400 (Bad Request) if the result has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/results")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public ResponseEntity<Result> createResult(@RequestBody Result result) throws URISyntaxException {
log.debug("REST request to save Result : {}", result);
Participation participation = result.getParticipation();
Course course = participation.getExercise().getCourse();
User user = userService.getUserWithGroupsAndAuthorities();
if (!authCheckService.isTeachingAssistantInCourse(course, user) && !authCheckService.isInstructorInCourse(course, user) && !authCheckService.isAdmin()) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
if (result.getId() != null) {
throw new BadRequestAlertException("A new result cannot already have an ID.", ENTITY_NAME, "idexists");
} else if (result.getResultString() == null) {
throw new BadRequestAlertException("Result string is required.", ENTITY_NAME, "resultStringNull");
} else if (result.getScore() == null) {
throw new BadRequestAlertException("Score is required.", ENTITY_NAME, "scoreNull");
} else if (result.getScore() != 100 && result.isSuccessful()) {
throw new BadRequestAlertException("Only result with score 100% can be successful.", ENTITY_NAME, "scoreAndSuccessfulNotMatching");
} else if (!result.getFeedbacks().isEmpty() && result.getFeedbacks().stream().filter(feedback -> feedback.getText() == null).count() != 0) {
throw new BadRequestAlertException("In case feedback is present, feedback text and detail text are mandatory.", ENTITY_NAME, "feedbackTextOrDetailTextNull");
}
if (!result.getFeedbacks().isEmpty()) {
result.setHasFeedback(true);
}
Result savedResult = resultRepository.save(result);
result.getFeedbacks().forEach(feedback -> {
feedback.setResult(savedResult);
feedbackService.save(feedback);
});
ltiService.ifPresent(ltiService -> ltiService.onNewBuildResult(savedResult.getParticipation()));
return ResponseEntity.created(new URI("/api/results/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Feedback in project ArTEMiS by ls1intum.
the class FeedbackResourceIntTest method updateFeedback.
@Test
@Transactional
public void updateFeedback() throws Exception {
// Initialize the database
feedbackRepository.saveAndFlush(feedback);
int databaseSizeBeforeUpdate = feedbackRepository.findAll().size();
// Update the feedback
Feedback updatedFeedback = feedbackRepository.findOne(feedback.getId());
updatedFeedback.text(UPDATED_TEXT).detailText(UPDATED_DETAIL_TEXT).positive(UPDATED_POSITIVE).type(UPDATED_TYPE);
restFeedbackMockMvc.perform(put("/api/feedbacks").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedFeedback))).andExpect(status().isOk());
// Validate the Feedback in the database
List<Feedback> feedbackList = feedbackRepository.findAll();
assertThat(feedbackList).hasSize(databaseSizeBeforeUpdate);
Feedback testFeedback = feedbackList.get(feedbackList.size() - 1);
assertThat(testFeedback.getText()).isEqualTo(UPDATED_TEXT);
assertThat(testFeedback.getDetailText()).isEqualTo(UPDATED_DETAIL_TEXT);
assertThat(testFeedback.isPositive()).isEqualTo(UPDATED_POSITIVE);
assertThat(testFeedback.getType()).isEqualTo(UPDATED_TYPE);
}
Aggregations