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 Details

    • logger

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

      private Random rand
    • userRepository

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

      private final MailService mailService
      Instance of MailService, that will be used to send an email when the answers are saved.
  • Constructor Details

  • Method Details

    • getNewCode

      @GetMapping(path="/getNewCode") public org.springframework.http.ResponseEntity<String> getNewCode() throws NotFoundException
      Throws:
      NotFoundException
    • getSaltString

      protected String 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

      public UserDTO convertToDTO(User user)
      Converts an instance of User to an instance of UserDTO
      Specified by:
      convertToDTO in class DTOMapping<User,UserDTO>
      Parameters:
      user - an instance of user
      Returns:
      an instance of UserDTO, containing the serialized data of user
      See Also:
    • convertToEntity

      public User convertToEntity(UserDTO userDTO) throws EmptyFieldException
      Converts an instance of UserDTO to an instance of User
      Specified by:
      convertToEntity in class DTOMapping<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: