Class UserController

java.lang.Object
com.app.controller.UserController

@RestController @RequestMapping("/users") public class UserController extends Object
REST controller for user management operations.
  • Constructor Details

    • UserController

      public UserController()
  • Method Details

    • createUser

      @PostMapping @ResponseStatus(CREATED) public ResponseDto<Long> createUser(@RequestBody CreateUserDto createUserDto)
      Creates a new user.
      Parameters:
      createUserDto - DTO containing user creation details.
      Returns:
      ResponseDto containing the ID of the created user.
    • activatedUser

      @PatchMapping @ResponseStatus(OK) public ResponseDto<Long> activatedUser(@RequestBody UserActivationTokenDto userActivationTokenDto)
      Activates a user account using an activation token.
      Parameters:
      userActivationTokenDto - DTO containing the activation token.
      Returns:
      ResponseDto containing the ID of the activated user.
    • refreshVerificationEmailToken

      @PostMapping("/refresh") @ResponseStatus(OK) public ResponseDto<Long> refreshVerificationEmailToken(@RequestBody EmailDto emailDto)
      Requests a new verification email token to be sent.
      Parameters:
      emailDto - DTO containing the user's email address.
      Returns:
      ResponseDto containing the user ID for whom the token was refreshed.
    • lostPassword

      @PatchMapping("/lost") @ResponseStatus(OK) public ResponseDto<Long> lostPassword(@RequestBody EmailDto emailDto)
      Initiates a lost password process by sending a reset email.
      Parameters:
      emailDto - DTO containing the user's email address.
      Returns:
      ResponseDto containing the user ID associated with the request.
    • newPassword

      @PatchMapping("/new") @ResponseStatus(OK) public ResponseDto<Long> newPassword(@RequestBody NewPasswordDto newPasswordDto)
      Sets a new password for the user.
      Parameters:
      newPasswordDto - DTO containing the new password and related info.
      Returns:
      ResponseDto containing the user ID whose password was updated.
    • refreshToken

      @GetMapping("/refresh") @ResponseStatus(OK) public ResponseDto<TokensDto> refreshToken(@CookieValue("RefreshToken") String token, jakarta.servlet.http.HttpServletResponse response)
      Refreshes authentication tokens using the refresh token from cookies.
      Parameters:
      token - Refresh token from the cookie.
      response - HTTP response to set updated cookies.
      Returns:
      ResponseDto containing the new tokens.
    • hasAccess

      @GetMapping("/in/access") @ResponseStatus(OK) public ResponseDto<String> hasAccess(@CookieValue("AccessToken") String token)
      Checks if the user has access (token validation).
      Parameters:
      token - Access token from the cookie.
      Returns:
      ResponseDto with success message.
    • disable

      @GetMapping("/in/disable") @ResponseStatus(OK) public ResponseDto<LogoutDto> disable(@CookieValue("AccessToken") String token, jakarta.servlet.http.HttpServletResponse response)
      Logs out the user by invalidating authentication cookies.
      Parameters:
      token - Access token from the cookie.
      response - HTTP response to clear cookies.
      Returns:
      ResponseDto containing logout confirmation message.
    • getActualLoginUser

      @GetMapping("/in/user") @ResponseStatus(OK) public ResponseDto<UserDto> getActualLoginUser(@CookieValue("AccessToken") String token)
      Retrieves information about the currently logged-in user.
      Parameters:
      token - Access token from the cookie.
      Returns:
      ResponseDto containing the user data.
    • getActualLoginRole

      @GetMapping("/in/role") @ResponseStatus(OK) public ResponseDto<Role> getActualLoginRole(@CookieValue("AccessToken") String token)
      Retrieves the role of the currently logged-in user.
      Parameters:
      token - Access token from the cookie.
      Returns:
      ResponseDto containing the user's role.
    • changePassword

      @PatchMapping("/in/password") @ResponseStatus(OK) public ResponseDto<Long> changePassword(@RequestBody ChangePasswordDto changePasswordDto, @CookieValue("AccessToken") String token)
      Changes the password of the currently logged-in user.
      Parameters:
      changePasswordDto - DTO containing old and new passwords.
      token - Access token from the cookie.
      Returns:
      ResponseDto containing the user ID whose password was changed.
    • changeEmail

      @PatchMapping("/in/email") @ResponseStatus(OK) public ResponseDto<Long> changeEmail(@RequestBody NewEmailDto newEmailDto, @CookieValue("AccessToken") String token)
      Changes the email address of the currently logged-in user.
      Parameters:
      newEmailDto - DTO containing the new email.
      token - Access token from the cookie.
      Returns:
      ResponseDto containing the user ID whose email was changed.
    • deleteUser

      @DeleteMapping("/in") @ResponseStatus(OK) public ResponseDto<Long> deleteUser(@CookieValue("AccessToken") String token)
      Deletes the currently logged-in user.
      Parameters:
      token - Access token from the cookie.
      Returns:
      ResponseDto containing the ID of the deleted user.
    • getUser

      @GetMapping("/{id}") @ResponseStatus(OK) public ResponseDto<UserDto> getUser(@PathVariable Long id)
      Retrieves a user by their ID.
      Parameters:
      id - ID of the user to retrieve.
      Returns:
      ResponseDto containing the user data.
    • getUsers

      @PatchMapping("/filter") @ResponseStatus(OK) public ResponseDto<List<UserDto>> getUsers(@RequestBody UserSpecificationDto userSpecificationDto)
      Retrieves users filtered by criteria.
      Parameters:
      userSpecificationDto - DTO containing filtering criteria.
      Returns:
      ResponseDto containing a list of users matching the criteria.
    • deleteUser

      @DeleteMapping @ResponseStatus(OK) public ResponseDto<Long> deleteUser(@RequestParam Long userId, @RequestHeader("Authorization") String token)
      Deletes a user by their ID (admin operation).
      Parameters:
      userId - ID of the user to delete.
      token - Authorization token from the request header.
      Returns:
      ResponseDto containing the ID of the deleted user.
    • updateUser

      @PatchMapping("/update") @ResponseStatus(OK) public ResponseDto<Long> updateUser(@RequestBody UpdateUserDto updateUserDto)
      Updates a user with new data.
      Parameters:
      updateUserDto - DTO containing updated user data.
      Returns:
      ResponseDto containing the ID of the updated user.