For the context
what do you think of this?
@Transactional
public Customer updateCustomer(Long id, CustomerDTO customerDTO) {
log.info("Updating customer with ID: {}", id);
Customer existingCustomer = customerRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Customer not found with ID: " + id));
modelMapper.map(customerDTO, existingCustomer);
existingCustomer.setCustomerId(id);
List<LocationDTO> pickupLocationDTOs= customerDTO.getPickupLocations();
List<LocationDTO> deliveryLocationDTOs = customerDTO.getDeliveryLocations();
List<Location> pickupLocations = mapLocations(pickupLocationDTOs, LocationType.PICKUP, existingCustomer);
List<Location> deliveryLocations = mapLocations(deliveryLocationDTOs, LocationType.DELIVERY, existingCustomer);
List<Location> allLocations = new ArrayList<>(pickupLocations.size()+deliveryLocations.size());
allLocations.addAll(pickupLocations);
allLocations.addAll(deliveryLocations);
locationRepository.saveAll(allLocations);
return customerRepository.save(existingCustomer);
}