Class AddressesService

java.lang.Object
com.fiap.tech_challenge.parte1.ms_users.services.AddressesService

@Service public class AddressesService extends Object
Service responsible for managing user addresses, including retrieval, saving, updating, and grouping addresses by user.
  • Constructor Details

    • AddressesService

      public AddressesService(AddressesRepository addressesRepository)
      Constructs the AddressesService with the given repository.
      Parameters:
      addressesRepository - repository used for address persistence operations
  • Method Details

    • findAllByUserId

      public List<Address> findAllByUserId(UUID userId)
      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 save
      generatedUserId - the UUID of the user to whom these addresses belong
      Throws:
      jakarta.validation.ConstraintViolationException - if the address list is empty
    • findAllByUserIds

      public Map<String,List<Address>> findAllByUserIds(Set<UUID> userIdSet)
      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

      public void update(List<AddressRequestDTO> addressDTOs, UUID userId)
      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 saved
      userId - the UUID of the user whose addresses are to be updated