diff --git a/application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerController.java b/application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerController.java index ebdc9cd6e97752ea388ec0755f44f74b6f857bd4..696c370354ea121b8f76fff0fc02773a0378f63d 100644 --- a/application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerController.java +++ b/application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerController.java @@ -8,15 +8,16 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import org.fuseri.model.dto.exercise.AnswerCreateDto; import org.fuseri.model.dto.exercise.AnswerDto; -import org.fuseri.model.dto.exercise.AnswersCreateDto; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; -import java.util.List; - /** * Represent a REST API controller for answers * Handle HTTP requests related to answers @@ -32,27 +33,6 @@ public class AnswerController { this.facade = facade; } - /** - * Create a new answer for the given question ID - * - * @param dto the AnswerCreateDto object containing information about the answer to create - * @return a ResponseEntity containing an AnswerDto object representing the newly created answer, or a 404 Not Found response - * if the question with the specified ID in dto was not found - */ - @Operation(summary = "Create new answers for question", description = "Creates new answers for question.") - @ApiResponses(value = { - @ApiResponse(responseCode = "201", description = "Answers created successfully."), - @ApiResponse(responseCode = "400", description = "Invalid input.") - }) - @PostMapping - public ResponseEntity<List<AnswerDto>> createMultiple(@Valid @RequestBody AnswersCreateDto dto) { - try { - return ResponseEntity.status(HttpStatus.CREATED).body(facade.createMultiple(dto)); - } catch (EntityNotFoundException e) { - return ResponseEntity.notFound().build(); - } - } - /** * Update an answer * diff --git a/application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerFacade.java b/application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerFacade.java index d0f88ecbfb63561d3ee8f742c3e7cd4a627b9006..38165ddb1f9614cf1d0ff302335f1c589c746177 100644 --- a/application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerFacade.java +++ b/application/module-exercise/src/main/java/org/fuseri/moduleexercise/answer/AnswerFacade.java @@ -3,15 +3,10 @@ package org.fuseri.moduleexercise.answer; import jakarta.transaction.Transactional; import org.fuseri.model.dto.exercise.AnswerCreateDto; import org.fuseri.model.dto.exercise.AnswerDto; -import org.fuseri.model.dto.exercise.AnswersCreateDto; import org.fuseri.moduleexercise.question.Question; import org.fuseri.moduleexercise.question.QuestionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.List; /** * Represent facade for managing answers @@ -39,28 +34,6 @@ public class AnswerFacade { this.mapper = mapper; } - /** - * Create a new answer for the given question ID - * - * @param dto the AnswerCreateDto object containing information about the answer to create - * @return an AnswerDto object representing the newly created answer - */ - public List<AnswerDto> createMultiple(@RequestBody AnswersCreateDto dto) { - List<Answer> createdAnswers = new ArrayList<>(); - for (var answerDto : dto.getAnswers()) { - Question question; - question = questionService.find(dto.getQuestionId()); - - Answer answer = mapper.fromCreateDto(answerDto); - answer.setQuestion(question); - var createdAnswer = answerService.create(answer); - question.getAnswers().add(answer); - createdAnswers.add(createdAnswer); - } - - return mapper.toDtoList(createdAnswers); - } - /** * Update an answer *