Class QuestionController
java.lang.Object
it.unimib.unimibmodules.controller.DTOMapping<M,T>
it.unimib.unimibmodules.controller.DTOListMapping<Question,QuestionDTO>
it.unimib.unimibmodules.controller.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 Summary
FieldsModifier and TypeFieldDescriptionprivate final AWSToken
Instance of AWSToken that will be used to acces the aws services.private final CategoryRepositoryReadOnly
Instance of CategoryRepository that will be used to access the db.private static final org.apache.logging.log4j.Logger
private final QuestionRepository
Instance of QuestionRepository that will be used to access the db.private final UserRepositoryReadOnly
Instance of UserRepository that will be used to access the db.Fields inherited from class it.unimib.unimibmodules.controller.DTOMapping
modelMapper
-
Constructor Summary
ConstructorsConstructorDescriptionQuestionController
(QuestionRepository questionRepository, UserRepositoryReadOnly userRepository, org.modelmapper.ModelMapper modelMapper, CategoryRepositoryReadOnly categoryRepository, AWSToken awsToken) -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String>
addQuestion
(QuestionDTO questionDTO) Creates a question, with the given text and idconvertListToDTO
(Iterable<Question> questions) Converts a list of Question to a list of questionDTOconvertToDTO
(Question question) Converts an instance of Question to an instance of questionDTOconvertToEntity
(QuestionDTO questionDTO) Converts an instance of QuestionDTO to an instance of Questionorg.springframework.http.ResponseEntity<String>
deleteQuestion
(int id) Deletes the question associated with the given id.org.springframework.http.ResponseEntity<List<QuestionDTO>>
findQuestionsByText
(String text) Gets the question in the database where text is contained in the text of the questionorg.springframework.http.ResponseEntity<List<QuestionDTO>>
findQuestionsByTextLazy
(String text, int offset, int limit) Gets the question in the database where text is contained in the text of the question with Lazy Loadingorg.springframework.http.ResponseEntity<List<QuestionDTO>>
findQuestionsForSurvey
(int id) Gets the Question associated with the given id.org.springframework.http.ResponseEntity<QuestionDTO>
getQuestion
(int id) Gets the Question associated with the given id.org.springframework.http.ResponseEntity<List<QuestionDTO>>
Gets all the questionsorg.springframework.http.ResponseEntity<List<QuestionDTO>>
getQuestionsByCategory
(int id) Gets all the questions associated with the given id of categoryorg.springframework.http.ResponseEntity<List<QuestionDTO>>
getQuestionsByCategoryLazy
(int id, int offset, int limit) Gets all the questions associated with the given id of category with Lazy Loadingorg.springframework.http.ResponseEntity<List<QuestionDTO>>
getQuestionsByUser
(int id) Gets all the questions of the userorg.springframework.http.ResponseEntity<List<QuestionDTO>>
getQuestionsByUserLazy
(int id, int offset, int limit) Gets all the questions of the user with Lazy Loadingorg.springframework.http.ResponseEntity<List<QuestionDTO>>
getQuestionsLazy
(int offset, int limit) Gets all the questions with Lazy Loadingorg.springframework.http.ResponseEntity<String>
getToken
(int id) org.springframework.http.ResponseEntity<String>
modifyQuestion
(QuestionDTO questionDTO) Modifies the question's text associated with the given id.
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger logger -
questionRepository
Instance of QuestionRepository that will be used to access the db. -
userRepository
Instance of UserRepository that will be used to access the db. -
categoryRepository
Instance of CategoryRepository that will be used to access the db. -
awsToken
Instance of AWSToken that will be used to acces the aws services.
-
-
Constructor Details
-
QuestionController
@Autowired public QuestionController(QuestionRepository questionRepository, UserRepositoryReadOnly userRepository, org.modelmapper.ModelMapper modelMapper, CategoryRepositoryReadOnly categoryRepository, AWSToken awsToken)
-
-
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 byid
has been found
-
getQuestions
@GetMapping(path="/getQuestion") public org.springframework.http.ResponseEntity<List<QuestionDTO>> getQuestions() throws NotFoundExceptionGets 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 idoffset
-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 idoffset
-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 byid
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 foundoffset
-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 byid
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 byid
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 byid
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 byid
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 byid
has been found
-
convertToDTO
Converts an instance of Question to an instance of questionDTO- Specified by:
convertToDTO
in classDTOMapping<Question,
QuestionDTO> - Parameters:
question
- an instance of Question- Returns:
- an instance of QuestionDTO, containing the serialized data of question
- See Also:
-
convertListToDTO
Converts a list of Question to a list of questionDTO- Specified by:
convertListToDTO
in classDTOListMapping<Question,
QuestionDTO> - Parameters:
questions
- the list of Questions- Returns:
- a list of QuestionDTO, containing the serialized data of questions
- See Also:
-
convertToEntity
Converts an instance of QuestionDTO to an instance of Question- Specified by:
convertToEntity
in classDTOMapping<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 byid
has been found- See Also:
-