java.lang.Object
com.fiap.tech_challenge.parte1.ms_users.controllers.UsersController

@RestController @RequestMapping("/users") public class UsersController extends Object
REST controller for managing users.

Provides endpoints to create, update, retrieve, activate/deactivate users, and handle authentication-related operations.

  • Constructor Details

    • UsersController

      public UsersController(UsersService service, TokenService tokenService, org.springframework.security.authentication.AuthenticationManager authenticationManager)
  • Method Details

    • getById

      @GetMapping("/{id}") public org.springframework.http.ResponseEntity<UsersResponseDTO> getById(@PathVariable UUID id)
      Retrieves a user by their unique ID.
      Parameters:
      id - UUID of the user to retrieve
      Returns:
      ResponseEntity containing the user data if found
    • findAllUsers

      @GetMapping public org.springframework.http.ResponseEntity<List<UsersResponseDTO>> findAllUsers(@RequestParam int size, @RequestParam int page)
      Retrieves a paginated list of users.
      Parameters:
      size - number of users per page
      page - page index (zero-based)
      Returns:
      ResponseEntity with the list of users
    • create

      @PostMapping public org.springframework.http.ResponseEntity<CreateUserDTO> create(@RequestBody @Valid @Valid UsersRequestDTO dto)
      Creates a new user.
      Parameters:
      dto - User creation request data validated automatically
      Returns:
      ResponseEntity containing the created user and a generated JWT token
    • executeLogin

      @PostMapping("/login") public org.springframework.http.ResponseEntity<TokenJWTInfoDTO> executeLogin(@RequestBody @Valid @Valid AuthenticationDataDTO data)
      Authenticates a user and returns a JWT token if successful.
      Parameters:
      data - User login credentials validated automatically
      Returns:
      ResponseEntity containing the JWT token
    • toggleActivation

      @PatchMapping("/{id}") public org.springframework.http.ResponseEntity<String> toggleActivation(@PathVariable UUID id, @RequestParam boolean activate)
      Toggles user activation status.
      Parameters:
      id - UUID of the user to activate/deactivate
      activate - true to activate, false to deactivate
      Returns:
      ResponseEntity with confirmation message
    • changePassword

      @PatchMapping("/{id}/password") public org.springframework.http.ResponseEntity<String> changePassword(@PathVariable UUID id, @RequestBody @Valid @Valid ChangePasswordRequestDTO dto)
      Changes the password of a user.
      Parameters:
      id - UUID of the user whose password is to be changed
      dto - Change password request containing old and new passwords
      Returns:
      ResponseEntity with confirmation message
    • updateUser

      @PutMapping("/{id}") public org.springframework.http.ResponseEntity<UsersResponseDTO> updateUser(@PathVariable UUID id, @RequestBody @Valid @Valid UpdateUserDTO dto)
      Updates user details.
      Parameters:
      id - UUID of the user to update
      dto - Update user request data validated automatically
      Returns:
      ResponseEntity containing the updated user data