Class SurveyController
java.lang.Object
it.unimib.unimibmodules.controller.DTOMapping<Survey,SurveyDTO>
it.unimib.unimibmodules.controller.SurveyController
@RestController
@RequestMapping("/api")
public class SurveyController
extends DTOMapping<Survey,SurveyDTO>
Controller handling HTTP requests related to Survey.
- Version:
- 0.4.1
- Author:
- Luca Milazzo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.apache.logging.log4j.Logger
Logger instance for debug purposeprivate static final String
Common strings used by the loggerprivate static final String
private final SurveyRepository
Instance of SurveyRepository.private final UserRepositoryReadOnly
Instance of UserRepository.Fields inherited from class it.unimib.unimibmodules.controller.DTOMapping
modelMapper
-
Constructor Summary
ConstructorsConstructorDescriptionSurveyController
(UserRepositoryReadOnly userRepository, SurveyRepository surveyRepository, org.modelmapper.ModelMapper modelMapper) -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String>
Creates a survey, with the given name and request's date-time, that is associated to the given user idconvertToDTO
(Survey survey) Conversion of an instance of Survey to an instance of SurveyDTOconvertToDTOAndSkipQuestions
(Survey survey) Conversion of an instance of Survey to an instance of SurveyDTO skipping QuestionsListconvertToEntity
(SurveyDTO surveyDTO) Conversion of an instance of SurveyDTO to an instance of Surveyorg.springframework.http.ResponseEntity<String>
deleteSurvey
(int id) Deletes the survey associated with the given id.Finds all surveys.Finds all surveys without their questions list.findAllSurveysNoQuestionLazy
(int offset, int limit) Finds all surveys without their questions.org.springframework.http.ResponseEntity<SurveyDTO>
findSurvey
(int id) Finds the survey associated with the given id.org.springframework.http.ResponseEntity<SurveyDTO>
Finds the survey associated with the given id.findSurveyByText
(String text) Finds the surveys where text is contained in their names or in their identifiers.Finds the surveys where text is contained in their names or in their identifiers without their questions listfindSurveyByTextNoQuestionsLazy
(String text, int offset, int limit) Finds the surveys where text is contained in their names or in their identifiers without their questions list using Lazy Loading parameters.org.springframework.http.ResponseEntity<SurveyDTO>
findSurveyNoQuestion
(int id) Finds the survey associated with the given id without its questions list.org.springframework.http.ResponseEntity<String>
modifySurvey
(SurveyDTO surveyDTO) Modifies the survey's name associated with the given surveyDTO.
-
Field Details
-
surveyRepository
Instance of SurveyRepository. It's used to access the Repository layer. -
userRepository
Instance of UserRepository. It's used to access the Repository layer. -
logger
private static final org.apache.logging.log4j.Logger loggerLogger instance for debug purpose -
RETRIVEDALLSURVEYS
Common strings used by the logger- See Also:
-
RETRIVEDNSURVEYS
- See Also:
-
-
Constructor Details
-
SurveyController
@Autowired public SurveyController(UserRepositoryReadOnly userRepository, SurveyRepository surveyRepository, org.modelmapper.ModelMapper modelMapper)
-
-
Method Details
-
findSurveyByCompilationCode
@GetMapping("/findSurveyByCompilationCode") public org.springframework.http.ResponseEntity<SurveyDTO> findSurveyByCompilationCode(@RequestParam(name="code") String code) throws NotFoundException Finds the survey associated with the given id.- Parameters:
id
- the id of the Survey- Returns:
- If the survey has been found: an HTTP response with status 200 and the SurveyDTO
- Throws:
NotFoundException
- if the survey doesn't exists- See Also:
-
findSurvey
@GetMapping("/findSurvey") public org.springframework.http.ResponseEntity<SurveyDTO> findSurvey(@RequestParam(name="id") int id) throws NotFoundException Finds the survey associated with the given id.- Parameters:
id
- the id of the Survey- Returns:
- If the survey has been found: an HTTP response with status 200 and the SurveyDTO
- Throws:
NotFoundException
- if the survey doesn't exists- See Also:
-
findSurveyNoQuestion
@GetMapping(path="/findSurveyNoQuestion/{id}") public org.springframework.http.ResponseEntity<SurveyDTO> findSurveyNoQuestion(@PathVariable int id) throws NotFoundException Finds the survey associated with the given id without its questions list.- Parameters:
id
- the id of the Survey- Returns:
- If the survey has been found: an HTTP response with status 200 and the SurveyDTO
- Throws:
NotFoundException
- if the survey doesn't exists- See Also:
-
findSurveyByText
@GetMapping("/findSurveyByText") public org.springframework.http.ResponseEntity<List<SurveyDTO>> findSurveyByText(@RequestParam(name="text") String text) throws NotFoundException Finds the surveys where text is contained in their names or in their identifiers.- Parameters:
text
- the text to be found- Returns:
- If one survey at least has been found: an HTTP response with status 200 and the SurveyDTOs
- Throws:
NotFoundException
- if no survey has been found- See Also:
-
findSurveyByTextNoQuestions
@GetMapping("/findSurveyByTextNoQuestion") public org.springframework.http.ResponseEntity<List<SurveyDTO>> findSurveyByTextNoQuestions(@RequestParam(name="text") String text) throws NotFoundException Finds the surveys where text is contained in their names or in their identifiers without their questions list- Parameters:
text
- the text to be found- Returns:
- If one survey at least has been found: an HTTP response with status 200 and the SurveyDTOs
- Throws:
NotFoundException
- if no survey has been found- See Also:
-
findSurveyByTextNoQuestionsLazy
@GetMapping("/findSurveyByTextNoQuestionLazy") public org.springframework.http.ResponseEntity<List<SurveyDTO>> findSurveyByTextNoQuestionsLazy(@RequestParam(name="text") String text, @RequestParam int offset, @RequestParam int limit) throws NotFoundException Finds the surveys where text is contained in their names or in their identifiers without their questions list using Lazy Loading parameters.- Parameters:
text
- the text to be foundoffset
- offset for lazy loadinglimit
- to limit the result length- Returns:
- If one survey at least has been found: an HTTP response with status 200 and the SurveyDTOs
- Throws:
NotFoundException
- if no survey has been found- See Also:
-
findAllSurveys
@GetMapping("/findAllSurveys") public org.springframework.http.ResponseEntity<List<SurveyDTO>> findAllSurveys() throws NotFoundExceptionFinds all surveys.- Returns:
- If one survey at least has been found: an HTTP response with status 200
- Throws:
NotFoundException
- if no surveys exist- See Also:
-
findAllSurveysNoQuestion
@GetMapping("/findAllSurveysNoQuestion") public org.springframework.http.ResponseEntity<List<SurveyDTO>> findAllSurveysNoQuestion() throws NotFoundExceptionFinds all surveys without their questions list.- Returns:
- If one survey at least has been found: an HTTP response with status 200
- Throws:
NotFoundException
- if no surveys exist- See Also:
-
findAllSurveysNoQuestionLazy
@GetMapping("/findAllSurveysNoQuestionLazy") public org.springframework.http.ResponseEntity<List<SurveyDTO>> findAllSurveysNoQuestionLazy(@RequestParam int offset, @RequestParam int limit) throws NotFoundException Finds all surveys without their questions.- Returns:
- If one survey at least has been found: an HTTP response with status 200
- Throws:
NotFoundException
- if no surveys exist- See Also:
-
addSurvey
@PostMapping(path="/addSurvey", produces="application/json") public org.springframework.http.ResponseEntity<String> addSurvey(@RequestBody SurveyDTO surveyDTO) throws FormatException, NotFoundException, EmptyFieldException Creates a survey, with the given name and request's date-time, that is associated to the given user id- Parameters:
surveyDTO
- the serialized version of a Survey object- Returns:
- If the survey has been created : an HTTP response with status 201
- Throws:
FormatException
NotFoundException
EmptyFieldException
- See Also:
-
modifySurvey
@PatchMapping(path="/modifySurvey", produces="application/json") public org.springframework.http.ResponseEntity<String> modifySurvey(@RequestBody SurveyDTO surveyDTO) throws FormatException, NotFoundException, EmptyFieldException Modifies the survey's name associated with the given surveyDTO.- Parameters:
surveyDTO
- the serialized version of a Survey object- Returns:
- If the survey has been updated: an HTTP response with status 200
- Throws:
FormatException
NotFoundException
EmptyFieldException
- See Also:
-
deleteSurvey
@DeleteMapping(path="/deleteSurvey/{id}") public org.springframework.http.ResponseEntity<String> deleteSurvey(@PathVariable int id) throws FormatException Deletes the survey associated with the given id.- Parameters:
id
- the id of the survey to delete- Returns:
- if the survey has been deleted : an HTTP Response with status 200
- Throws:
NotFoundException
FormatException
- See Also:
-
convertToDTO
Conversion of an instance of Survey to an instance of SurveyDTO- Specified by:
convertToDTO
in classDTOMapping<Survey,
SurveyDTO> - Parameters:
survey
- an instance of Survey- Returns:
- an instance of SurveyDTO, containing the serialized data of survey
- See Also:
-
convertToDTOAndSkipQuestions
Conversion of an instance of Survey to an instance of SurveyDTO skipping QuestionsList- Parameters:
survey
- an instance of Survey- Returns:
- an instance of SurveyDTO, containing the serialized data of survey
- See Also:
-
convertToEntity
public Survey convertToEntity(SurveyDTO surveyDTO) throws FormatException, NotFoundException, EmptyFieldException Conversion of an instance of SurveyDTO to an instance of Survey- Specified by:
convertToEntity
in classDTOMapping<Survey,
SurveyDTO> - Parameters:
surveyDTO
- an instance of SurveyDTO- Returns:
- an instance of Survey
- Throws:
FormatException
EmptyFieldException
NotFoundException
- when one of the queries fails- See Also:
-