Class QuestionController


@RestController @RequestMapping("/api") public class QuestionController extends DTOListMapping<Question,QuestionDTO>
Controller handling HTTP requests related to Question.
Version:
0.4.1
Author:
Khalil
  • Field Details

    • logger

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

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

      private final UserRepositoryReadOnly userRepository
      Instance of UserRepository that will be used to access the db.
    • categoryRepository

      private final CategoryRepositoryReadOnly categoryRepository
      Instance of CategoryRepository that will be used to access the db.
    • awsToken

      private final AWSToken awsToken
      Instance of AWSToken that will be used to acces the aws services.
  • Constructor Details

  • Method Details

    • getQuestion

      @GetMapping(path="/getQuestion/{id}") public org.springframework.http.ResponseEntity<QuestionDTO> getQuestion(@PathVariable int id) throws NotFoundException
      Gets the Question associated with the given id.
      Parameters:
      id - the id of the question
      Returns:
      an HTTP response with status 200 and the QuestionDTO if the question has been found, 500 otherwise
      Throws:
      NotFoundException - if 404 no question with identified by id has been found
    • getQuestions

      @GetMapping(path="/getQuestion") public org.springframework.http.ResponseEntity<List<QuestionDTO>> getQuestions() throws NotFoundException
      Gets all the questions
      Returns:
      an HTTP response with status 200, 500 otherwise
      Throws:
      NotFoundException - if 404 no question has been found
    • getQuestionsLazy

      @GetMapping(path="/getQuestionLazy") public org.springframework.http.ResponseEntity<List<QuestionDTO>> getQuestionsLazy(@RequestParam int offset, @RequestParam int limit) throws NotFoundException
      Gets all the questions with Lazy Loading
      Parameters:
      id - user id
      offset -
      limit -
      Returns:
      an HTTP response with status 200, 404 otherwise
      Throws:
      NotFoundException
    • getQuestionsByUser

      @GetMapping(path="/getQuestionByUser/{id}") public org.springframework.http.ResponseEntity<List<QuestionDTO>> getQuestionsByUser(@PathVariable int id) throws NotFoundException
      Gets all the questions of the user
      Returns:
      an HTTP response with status 200, 500 otherwise
      Throws:
      NotFoundException
    • getQuestionsByUserLazy

      @GetMapping(path="/getQuestionByUserLazy") public org.springframework.http.ResponseEntity<List<QuestionDTO>> getQuestionsByUserLazy(@RequestParam int id, @RequestParam int offset, @RequestParam int limit) throws NotFoundException
      Gets all the questions of the user with Lazy Loading
      Parameters:
      id - user id
      offset -
      limit -
      Returns:
      an HTTP response with status 200, 500 otherwise
      Throws:
      NotFoundException
    • getQuestionsByCategory

      @GetMapping(path="/getQuestionByCategory/{id}") public org.springframework.http.ResponseEntity<List<QuestionDTO>> getQuestionsByCategory(@PathVariable int id) throws NotFoundException
      Gets all the questions associated with the given id of category
      Returns:
      an HTTP response with status 200, 500 otherwise
      Throws:
      NotFoundException
    • getQuestionsByCategoryLazy

      @GetMapping(path="/getQuestionByCategoryLazy") public org.springframework.http.ResponseEntity<List<QuestionDTO>> getQuestionsByCategoryLazy(@RequestParam int id, @RequestParam int offset, @RequestParam int limit) throws NotFoundException
      Gets all the questions associated with the given id of category with Lazy Loading
      Parameters:
      offset -
      limit -
      Returns:
      an HTTP response with status 200, 500 otherwise
      Throws:
      NotFoundException
    • findQuestionsByText

      @GetMapping(path="/findQuestionsByText/{text}") public org.springframework.http.ResponseEntity<List<QuestionDTO>> findQuestionsByText(@PathVariable String text) throws NotFoundException
      Gets the question in the database where text is contained in the text of the question
      Parameters:
      text - the text of the question to be found
      Returns:
      an HTTP response with status 200 and the QuestionDTO if the question has been found, 500 otherwise
      Throws:
      NotFoundException - if 404 no question with identified by id has been found
    • findQuestionsByTextLazy

      @GetMapping(path="/findQuestionsByTextLazy") public org.springframework.http.ResponseEntity<List<QuestionDTO>> findQuestionsByTextLazy(@RequestParam String text, @RequestParam int offset, @RequestParam int limit) throws NotFoundException
      Gets the question in the database where text is contained in the text of the question with Lazy Loading
      Parameters:
      text - the text of the question to be found
      offset -
      limit -
      Returns:
      an HTTP response with status 200 and the QuestionDTO if the question has been found, 500 otherwise
      Throws:
      NotFoundException - if 404 no question with identified by id has been found
    • findQuestionsForSurvey

      @GetMapping(path="/findQuestionForSurvey/{id}") public org.springframework.http.ResponseEntity<List<QuestionDTO>> findQuestionsForSurvey(@PathVariable int id) throws NotFoundException
      Gets the Question associated with the given id.
      Parameters:
      id - the id of the question
      Returns:
      an HTTP response with status 200 and the QuestionDTO if the question has been found, 500 otherwise
      Throws:
      NotFoundException - if 404 no question with identified by id has been found
    • getToken

      @GetMapping(path="/getToken/{id}") public org.springframework.http.ResponseEntity<String> getToken(@PathVariable int id)
    • addQuestion

      @PostMapping(path="/addQuestion") public org.springframework.http.ResponseEntity<String> addQuestion(@RequestBody QuestionDTO questionDTO) throws NotFoundException
      Creates a question, with the given text and id
      Parameters:
      questionDTO - the serialized object of the question
      Returns:
      an HTTP response with status 200 if the question has been modified, 500 otherwise
      Throws:
      NotFoundException - if no user or category identified by id has been found
    • modifyQuestion

      @PatchMapping(path="/modifyQuestion") public org.springframework.http.ResponseEntity<String> modifyQuestion(@RequestBody QuestionDTO questionDTO) throws NotFoundException
      Modifies the question's text associated with the given id.
      Parameters:
      questionDTO - the serialized object of the question
      Returns:
      an HTTP response with status 200 if the question has been modified, 500 otherwise
      Throws:
      NotFoundException - if no question with identified by id has been found
    • deleteQuestion

      @DeleteMapping(path="/deleteQuestion/{id}") public org.springframework.http.ResponseEntity<String> deleteQuestion(@PathVariable int id) throws NotFoundException
      Deletes the question associated with the given id.
      Parameters:
      id - the id of the question that will be deleted
      Returns:
      an HTTP Response with status 200 if the question has been deleted, 500 otherwise
      Throws:
      NotFoundException - if no question identified by id has been found
    • convertToDTO

      public QuestionDTO convertToDTO(Question question)
      Converts an instance of Question to an instance of questionDTO
      Specified by:
      convertToDTO in class DTOMapping<Question,QuestionDTO>
      Parameters:
      question - an instance of Question
      Returns:
      an instance of QuestionDTO, containing the serialized data of question
      See Also:
    • convertListToDTO

      public List<QuestionDTO> convertListToDTO(Iterable<Question> questions)
      Converts a list of Question to a list of questionDTO
      Specified by:
      convertListToDTO in class DTOListMapping<Question,QuestionDTO>
      Parameters:
      questions - the list of Questions
      Returns:
      a list of QuestionDTO, containing the serialized data of questions
      See Also:
    • convertToEntity

      public Question convertToEntity(QuestionDTO questionDTO) throws NotFoundException
      Converts an instance of QuestionDTO to an instance of Question
      Specified by:
      convertToEntity in class DTOMapping<Question,QuestionDTO>
      Parameters:
      questionDTO - an instance of QuestionDTO
      Returns:
      an instance of Question, containing the deserialized data of questionDTO
      Throws:
      NotFoundException - if no user or category identified by id has been found
      See Also: