Class UserController
java.lang.Object
it.unimib.unimibmodules.controller.DTOMapping<User,UserDTO>
it.unimib.unimibmodules.controller.UserController
@RestController
@RequestMapping("/api")
public class UserController
extends DTOMapping<User,UserDTO>
Controller handling HTTP requests from User
- Version:
- 0.4.1
- Author:
- Gianlorenzo Martini
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.apache.logging.log4j.Logger
private final MailService
Instance of MailService, that will be used to send an email when the answers are saved.private Random
private final UserRepository
Instance of UserRepository that will be used to access the db.Fields inherited from class it.unimib.unimibmodules.controller.DTOMapping
modelMapper
-
Constructor Summary
ConstructorsConstructorDescriptionUserController
(UserRepository userRepository, org.modelmapper.ModelMapper modelMapper, MailService mailService) -
Method Summary
Modifier and TypeMethodDescriptionconvertToDTO
(User user) Converts an instance of User to an instance of UserDTOconvertToEntity
(UserDTO userDTO) Converts an instance of UserDTO to an instance of Userorg.springframework.http.ResponseEntity<String>
protected String
getSurveysCreated
(String username) Gets the surveys created by the user identified by the usernameorg.springframework.http.ResponseEntity<UserDTO>
getUser
(int id) Gets the User associated with the given id.org.springframework.http.ResponseEntity<String>
Logs the User into the website if the combination of username and password match.org.springframework.http.ResponseEntity<String>
signUpUser
(UserDTO userDTO) Create a new User.
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger logger -
rand
-
userRepository
Instance of UserRepository that will be used to access the db. -
mailService
Instance of MailService, that will be used to send an email when the answers are saved.
-
-
Constructor Details
-
UserController
@Autowired public UserController(UserRepository userRepository, org.modelmapper.ModelMapper modelMapper, MailService mailService) throws NoSuchAlgorithmException - Throws:
NoSuchAlgorithmException
-
-
Method Details
-
getNewCode
@GetMapping(path="/getNewCode") public org.springframework.http.ResponseEntity<String> getNewCode() throws NotFoundException- Throws:
NotFoundException
-
getSaltString
-
getUser
@GetMapping(path="/getUser/{id}") public org.springframework.http.ResponseEntity<UserDTO> getUser(@PathVariable int id) throws NotFoundException Gets the User associated with the given id.- Parameters:
id
- the id of the user- Returns:
- an HTTP response with status 200 and the UserDTO if the user has been found, 500 otherwise
- Throws:
NotFoundException
-
getSurveysCreated
@GetMapping("/getSurveysCreated") public org.springframework.http.ResponseEntity<List<SurveyDTO>> getSurveysCreated(@RequestParam(name="username") String username) throws NotFoundException Gets the surveys created by the user identified by the username- Parameters:
username
- the username of a user- Returns:
- a list of surveys created by the user identified with username
- Throws:
NotFoundException
- if no user identified by username is found
-
logInUser
@PostMapping(path="/logInUser", produces="application/json") public org.springframework.http.ResponseEntity<String> logInUser(@RequestBody UserDTO userDTO) throws NotFoundException Logs the User into the website if the combination of username and password match.- Parameters:
userDTO
- Representation of a user from the body of the http post- Returns:
- an HTTP response with status 200 and the UserDTO if the user has been auth, 500 otherwise
- Throws:
NotFoundException
-
signUpUser
@PostMapping(path="/signUpUser", produces="application/json") public org.springframework.http.ResponseEntity<String> signUpUser(@RequestBody UserDTO userDTO) throws EmptyFieldException Create a new User.- Parameters:
userDTO
- Representation of a user from the body of the http post- Returns:
- an HTTP response with status 200 and the UserDTO if the user has been created, 500 otherwise
- Throws:
EmptyFieldException
-
convertToDTO
Converts an instance of User to an instance of UserDTO- Specified by:
convertToDTO
in classDTOMapping<User,
UserDTO> - Parameters:
user
- an instance of user- Returns:
- an instance of UserDTO, containing the serialized data of user
- See Also:
-
convertToEntity
Converts an instance of UserDTO to an instance of User- Specified by:
convertToEntity
in classDTOMapping<User,
UserDTO> - Parameters:
userDTO
- an instance of UserDTO- Returns:
- an instance of User, containing the deserialized data of UserDTO
- Throws:
EmptyFieldException
- when one of the required field is empty- See Also:
-