Class UserController


  • @RestController
    @RequestMapping("/users")
    public class UserController
    extends java.lang.Object
    The entry point for clients to access user data
    • Constructor Detail

      • UserController

        public UserController()
    • Method Detail

      • getAllUsers

        @GetMapping(value="/users",
                    produces="application/json")
        public org.springframework.http.ResponseEntity<?> getAllUsers()
        Returns a list of all users
        Example: http://localhost:2019/users/users
        Returns:
        JSON list of all users with a status of OK
        See Also:
        UserService.findAll()
      • getUserById

        @PreAuthorize("hasAnyRole(\'ADMIN\')")
        @GetMapping(value="/user/{userid}",
                    produces="application/json")
        public org.springframework.http.ResponseEntity<?> getUserById​(@PathVariable
                                                                      java.lang.Long userid)
        Returns a single user based off a user id number
        Example: http://localhost:2019/users/user/2
        Parameters:
        userid - The primary key of the user you seek
        Returns:
        JSON object of the user you seek
        See Also:
        UserService.findById(long)
      • getUserByUsername

        @PreAuthorize("hasAnyRole(\'ADMIN\')")
        @GetMapping(value="/user/username/{username}",
                    produces="application/json")
        public org.springframework.http.ResponseEntity<?> getUserByUsername​(@PathVariable
                                                                            java.lang.String username)
        Return a user object based on a given username
        Example: http://localhost:2019/users/user/username/hpotter
        Parameters:
        username - of the user (String) you seek
        Returns:
        JSON object of the user you seek
        See Also:
        UserService.findByUsername(String)
      • getUserByEmail

        @PreAuthorize("hasAnyRole(\'ADMIN\')")
        @GetMapping(value="/user/email/{email}",
                    produces="application/json")
        public org.springframework.http.ResponseEntity<?> getUserByEmail​(@PathVariable
                                                                         java.lang.String email)
        Return a user object based on a given email
        Example: http://localhost:2019/users/user/email/srogers@example.com
        Parameters:
        email - of the user (String) you seek
        Returns:
        JSON object of the user you seek
        See Also:
        UserService.findByEmail(String)
      • getUserProfile

        @GetMapping(value="/user/profile",
                    produces="application/json")
        public org.springframework.http.ResponseEntity<?> getUserProfile​(org.springframework.security.core.Authentication authentication)
      • getUsersLikeUsername

        @PreAuthorize("hasAnyRole(\'ADMIN\')")
        @GetMapping(value="/username/like/{username}",
                    produces="application/json")
        public org.springframework.http.ResponseEntity<?> getUsersLikeUsername​(@PathVariable
                                                                               java.lang.String username)
        Returns a list of users whose username contains the given substring
        Example: http://localhost:2019/users/username/like/da
        Parameters:
        username - of the user (String) you seek
        Returns:
        JSON list of users you seek
        See Also:
        UserService.findUsernamesContaining(String)
      • getAllUsersByLastName

        @PreAuthorize("hasAnyRole(\'ADMIN\')")
        @GetMapping(value="/lastname/like/{lastname}",
                    produces="application/json")
        public org.springframework.http.ResponseEntity<?> getAllUsersByLastName​(@PathVariable
                                                                                java.lang.String lastname)
        Returns a list of users whose last name contains the given substring
        Example: http://localhost:2019/users/lastname/like/potter
        Parameters:
        lastname - of the user (String) you seek
        Returns:
        JSON list of users you seek
        See Also:
        UserService.findAllByLastName(String)
      • addNewUser

        @PostMapping(value="/user",
                     consumes="application/json")
        public org.springframework.http.ResponseEntity<?> addNewUser​(@Valid @RequestBody
                                                                     @Valid User newuser)
                                                              throws java.net.URISyntaxException
        Given a complete User Object, create a new User record and accompanying useremail records and user role records.
        Example: http://localhost:2019/users/user
        Parameters:
        newuser - A complete new user to add including emails and roles. roles must already exist.
        Returns:
        A location header with the URI to the newly created user and a status of CREATED
        Throws:
        java.net.URISyntaxException - Exception if something does not work in creating the location header
        See Also:
        UserService.save(User)
      • replaceUser

        @PutMapping(value="/user/{userid}",
                    consumes="application/json")
        public org.springframework.http.ResponseEntity<?> replaceUser​(@Valid @RequestBody
                                                                      @Valid User replaceUser,
                                                                      @PathVariable
                                                                      long userid)
        Given a complete User Object Given the user id, primary key, is in the User table, replace the User record and Useremail records. Roles are handled through different endpoints
        Example: http://localhost:2019/users/user/2
        Parameters:
        replaceUser - A complete User including all emails and roles to be used to replace the User. Roles must already exist.
        userid - The primary key of the user you wish to replace.
        Returns:
        status of OK
        See Also:
        UserService.save(User)
      • updateUser

        @PatchMapping(value="/user/{id}",
                      consumes="application/json")
        public org.springframework.http.ResponseEntity<?> updateUser​(@Valid @RequestBody
                                                                     @Valid User updateUser,
                                                                     @PathVariable
                                                                     long id)
        Updates the user record associated with the given id with the provided data. Only the provided fields are affected. If role list is given, it replaces the original role list.
        Example: http://localhost:2019/users/user/7
        Parameters:
        updateUser - An object containing values for just the fields that are being updated. All other fields are left NULL.
        id - The primary key of the user you wish to update.
        Returns:
        A status of OK
        See Also:
        UserService.update(User, long)
      • deleteUserById

        @DeleteMapping(value="/user/{id}",
                       produces="application/json")
        public org.springframework.http.ResponseEntity<?> deleteUserById​(@PathVariable
                                                                         long id)
        Deletes a given user along with associated roles
        Example: http://localhost:2019/users/user/3
        Parameters:
        id - the primary key of the user you wish to delete
        Returns:
        Status of OK
        See Also:
        UserService.delete(long)