Class AddressesService
java.lang.Object
com.fiap.tech_challenge.parte1.ms_users.services.AddressesService
Service responsible for managing user addresses,
including retrieval, saving, updating, and grouping addresses by user.
-
Constructor Summary
ConstructorsConstructorDescriptionAddressesService
(AddressesRepository addressesRepository) Constructs the AddressesService with the given repository. -
Method Summary
Modifier and TypeMethodDescriptionfindAllByUserId
(UUID userId) Retrieves all addresses associated with a specific user by their UUID.findAllByUserIds
(Set<UUID> userIdSet) Retrieves addresses for a set of user IDs and groups them by user ID (as String).void
save
(@NotEmpty(message="User must have at least one Address") List<AddressRequestDTO> address, UUID generatedUserId) Saves a list of address DTOs for a given user ID.void
update
(List<AddressRequestDTO> addressDTOs, UUID userId) Updates the addresses of a user by deleting existing addresses and saving the new list.
-
Constructor Details
-
AddressesService
Constructs the AddressesService with the given repository.- Parameters:
addressesRepository
- repository used for address persistence operations
-
-
Method Details
-
findAllByUserId
Retrieves all addresses associated with a specific user by their UUID.- Parameters:
userId
- the UUID of the user whose addresses are to be fetched- Returns:
- a list of addresses belonging to the specified user
-
save
public void save(@NotEmpty(message="User must have at least one Address") @NotEmpty(message="User must have at least one Address") List<AddressRequestDTO> address, UUID generatedUserId) Saves a list of address DTOs for a given user ID. Requires the address list to be non-empty.- Parameters:
address
- the list of address DTOs to savegeneratedUserId
- the UUID of the user to whom these addresses belong- Throws:
jakarta.validation.ConstraintViolationException
- if the address list is empty
-
findAllByUserIds
Retrieves addresses for a set of user IDs and groups them by user ID (as String).- Parameters:
userIdSet
- the set of user UUIDs to fetch addresses for- Returns:
- a map where the key is the user ID (String) and the value is the list of addresses for that user
-
update
Updates the addresses of a user by deleting existing addresses and saving the new list.- Parameters:
addressDTOs
- the new list of address DTOs to be saveduserId
- the UUID of the user whose addresses are to be updated
-