Class UsersService
java.lang.Object
com.fiap.tech_challenge.parte1.ms_users.services.UsersService
Service class responsible for managing user operations such as
creation, update, retrieval, password changes, and activation status.
-
Constructor Summary
ConstructorsConstructorDescriptionUsersService
(UserRepository userRepository, UserMapper userMapper, AddressesService addressesService, UsersValidationService usersValidationService, PasswordValidationService passwordValidationService, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder) -
Method Summary
Modifier and TypeMethodDescriptionvoid
changePassword
(UUID id, @Valid ChangePasswordRequestDTO dto) Changes the password of a user after validating the old password.Creates a new user and saves their associated addresses.void
deactivateUser
(UUID id) Deactivates a user by ID.findAllUsers
(int size, int page) Retrieves a paginated list of all users and their addresses.Retrieves a user by ID, including their associated addresses.void
reactivateUser
(UUID id) Reactivates a previously deactivated user.updateUser
(UUID id, UpdateUserDTO dto) Updates user information including name, email, login, and address.
-
Constructor Details
-
UsersService
public UsersService(UserRepository userRepository, UserMapper userMapper, AddressesService addressesService, UsersValidationService usersValidationService, PasswordValidationService passwordValidationService, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)
-
-
Method Details
-
findById
Retrieves a user by ID, including their associated addresses.- Parameters:
id
- the user ID- Returns:
- the user response DTO
- Throws:
UserNotFoundException
- if the user is not found
-
findAllUsers
Retrieves a paginated list of all users and their addresses.- Parameters:
size
- page sizepage
- page number- Returns:
- list of user response DTOs
-
createUser
Creates a new user and saves their associated addresses.- Parameters:
dto
- the user request DTO- Returns:
- the created user response DTO
-
deactivateUser
Deactivates a user by ID.- Parameters:
id
- the user ID- Throws:
UserNotFoundException
- if the user is not found
-
reactivateUser
Reactivates a previously deactivated user.- Parameters:
id
- the user ID- Throws:
UserNotFoundException
- if the user is not found
-
changePassword
Changes the password of a user after validating the old password.- Parameters:
id
- the user IDdto
- the change password request DTO- Throws:
UserNotFoundException
- if the user is not found
-
updateUser
Updates user information including name, email, login, and address.- Parameters:
id
- the user IDdto
- the update user DTO- Returns:
- the updated user response DTO
-