Class CloseEndedAnswerController
java.lang.Object
it.unimib.unimibmodules.controller.DTOMapping<CloseEndedAnswer,CloseEndedAnswerDTO>
it.unimib.unimibmodules.controller.CloseEndedAnswerController
@RestController
@RequestMapping("/api")
public class CloseEndedAnswerController
extends DTOMapping<CloseEndedAnswer,CloseEndedAnswerDTO>
Controller handling HTTP requests related to ClosedEndedAnswer.
- Version:
- 0.4.1
- Author:
- Davide Costantini, Khalil Mohamed Khalil
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CloseEndedAnswerRepository
Instance of CloseEndedAnswerRepository that will be used to access the db.private static final org.apache.logging.log4j.Logger
private final QuestionRepositoryReadOnly
Instance of QuestionRepository that will be used to access the db.Fields inherited from class it.unimib.unimibmodules.controller.DTOMapping
modelMapper
-
Constructor Summary
ConstructorsConstructorDescriptionCloseEndedAnswerController
(CloseEndedAnswerRepository closeEndedAnswerRepository, org.modelmapper.ModelMapper modelMapper, QuestionRepositoryReadOnly questionRepository) -
Method Summary
Modifier and TypeMethodDescriptionconvertToDTO
(CloseEndedAnswer closeEndedAnswer) Converts an instance of CloseEndedAnswerDTO to an instance of AnswerDTOconvertToEntity
(CloseEndedAnswerDTO closeEndedAnswerDTO) Converts an instance of CloseEndedAnswer to an instance of CloseEndedAnswerDTOorg.springframework.http.ResponseEntity<String>
deleteAnswer
(int id) Deletes the close-ended answer associated with the given id.org.springframework.http.ResponseEntity<CloseEndedAnswerDTO>
findCloseEndedAnswer
(int id) Gets the Answer associated with the given id.org.springframework.http.ResponseEntity<String>
modifyCloseEndedAnswer
(CloseEndedAnswerDTO closeEndedAnswerDTO) Modifies the answer of a close-ended question associated with the given id, setting text as the answer.org.springframework.http.ResponseEntity<String>
postCloseEndedAnswer
(CloseEndedAnswerDTO closeEndedAnswerDTO) Creates an answer to a close-ended question.
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger logger -
closeEndedAnswerRepository
Instance of CloseEndedAnswerRepository that will be used to access the db. -
questionRepository
Instance of QuestionRepository that will be used to access the db.
-
-
Constructor Details
-
CloseEndedAnswerController
@Autowired public CloseEndedAnswerController(CloseEndedAnswerRepository closeEndedAnswerRepository, org.modelmapper.ModelMapper modelMapper, QuestionRepositoryReadOnly questionRepository)
-
-
Method Details
-
findCloseEndedAnswer
@GetMapping(path="/findCloseEndedAnswer/{id}") public org.springframework.http.ResponseEntity<CloseEndedAnswerDTO> findCloseEndedAnswer(@PathVariable int id) throws NotFoundException Gets the Answer associated with the given id.- Parameters:
id
- the id of the close-ended answer- Returns:
- an HTTP response with status 200 and the CloseEndedAnswerDTO if the close-ended answer has been found, 500 otherwise
- Throws:
NotFoundException
- if no close-ended answer with identified byid
has been found
-
postCloseEndedAnswer
@PostMapping(path="/addCloseEndedAnswer", produces="application/json") public org.springframework.http.ResponseEntity<String> postCloseEndedAnswer(@RequestBody CloseEndedAnswerDTO closeEndedAnswerDTO) throws EmptyFieldException, NotFoundException Creates an answer to a close-ended question.- Parameters:
closeEndedAnswerDTO
- the serialized object of the close-ended answer- Returns:
- an HTTP response with status 201 if the new close-ended answer has been created, 500 otherwise
- Throws:
EmptyFieldException
- when one of the required field is emptysNotFoundException
- when one of the queries of convertToEntity fails
-
modifyCloseEndedAnswer
@PatchMapping(path="/modifyCloseEndedAnswer") public org.springframework.http.ResponseEntity<String> modifyCloseEndedAnswer(@RequestBody CloseEndedAnswerDTO closeEndedAnswerDTO) throws NotFoundException, EmptyFieldException Modifies the answer of a close-ended question associated with the given id, setting text as the answer.- Parameters:
closeEndedAnswerDTO
- the serialized object of the close-ended answer 500 otherwise- Throws:
NotFoundException
- if no close-ended answer with identified byid
has been foundEmptyFieldException
- iftext
is empty
-
deleteAnswer
@DeleteMapping(path="/deleteCloseEndedAnswer/{id}") public org.springframework.http.ResponseEntity<String> deleteAnswer(@PathVariable int id) throws NotFoundException Deletes the close-ended answer associated with the given id.- Parameters:
id
- the id of the close-ended answer that will be deleted- Returns:
- an HTTP Response with status 200 if the close-ended answer has been deleted, 500 otherwise
- Throws:
NotFoundException
- if no close-ended answer identified byid
has been found
-
convertToDTO
Converts an instance of CloseEndedAnswerDTO to an instance of AnswerDTO- Specified by:
convertToDTO
in classDTOMapping<CloseEndedAnswer,
CloseEndedAnswerDTO> - Parameters:
closeEndedAnswer
- an instance of CloseEndedAnswer- Returns:
- an instance of CloseEndedAnswerDTO, containing the serialized data of closeEndedAnswer
- See Also:
-
convertToEntity
public CloseEndedAnswer convertToEntity(CloseEndedAnswerDTO closeEndedAnswerDTO) throws EmptyFieldException, NotFoundException Converts an instance of CloseEndedAnswer to an instance of CloseEndedAnswerDTO- Specified by:
convertToEntity
in classDTOMapping<CloseEndedAnswer,
CloseEndedAnswerDTO> - Parameters:
closeEndedAnswerDTO
- an instance of CloseEndedAnswerDTO- Returns:
- an instance of CloseEndedAnswer, containing the deserialized data of closeEndedAnswerDTO
- Throws:
EmptyFieldException
- when one of the required field is emptyNotFoundException
- when one of the queries fails- See Also:
-