Class UsersController
java.lang.Object
com.fiap.tech_challenge.parte1.ms_users.controllers.UsersController
REST controller for managing users.
Provides endpoints to create, update, retrieve, activate/deactivate users, and handle authentication-related operations.
-
Constructor Summary
ConstructorsConstructorDescriptionUsersController
(UsersService service, TokenService tokenService, org.springframework.security.authentication.AuthenticationManager authenticationManager) -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String>
changePassword
(UUID id, @Valid ChangePasswordRequestDTO dto) Changes the password of a user.org.springframework.http.ResponseEntity<CreateUserDTO>
create
(@Valid UsersRequestDTO dto) Creates a new user.org.springframework.http.ResponseEntity<TokenJWTInfoDTO>
executeLogin
(@Valid AuthenticationDataDTO data) Authenticates a user and returns a JWT token if successful.org.springframework.http.ResponseEntity<List<UsersResponseDTO>>
findAllUsers
(int size, int page) Retrieves a paginated list of users.org.springframework.http.ResponseEntity<UsersResponseDTO>
Retrieves a user by their unique ID.org.springframework.http.ResponseEntity<String>
toggleActivation
(UUID id, boolean activate) Toggles user activation status.org.springframework.http.ResponseEntity<UsersResponseDTO>
updateUser
(UUID id, @Valid UpdateUserDTO dto) Updates user details.
-
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 pagepage
- 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/deactivateactivate
- 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 changeddto
- 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 updatedto
- Update user request data validated automatically- Returns:
- ResponseEntity containing the updated user data
-