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 Details

    • logger

      private static final org.apache.logging.log4j.Logger logger
    • closeEndedAnswerRepository

      private final CloseEndedAnswerRepository closeEndedAnswerRepository
      Instance of CloseEndedAnswerRepository that will be used to access the db.
    • questionRepository

      private final QuestionRepositoryReadOnly questionRepository
      Instance of QuestionRepository that will be used to access the db.
  • Constructor Details

  • 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 by id 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 emptys
      NotFoundException - 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 by id has been found
      EmptyFieldException - if text 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 by id has been found
    • convertToDTO

      public CloseEndedAnswerDTO convertToDTO(CloseEndedAnswer closeEndedAnswer)
      Converts an instance of CloseEndedAnswerDTO to an instance of AnswerDTO
      Specified by:
      convertToDTO in class DTOMapping<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 class DTOMapping<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 empty
      NotFoundException - when one of the queries fails
      See Also: