Created
October 11, 2020 22:12
-
-
Save yusufcakal/b3290619399d01160d1fba94fe3bd707 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class AddressService { | |
private final AddressRepository addressRepository; | |
private final SendNotificationService sendNotificationService; | |
public AddressService(AddressRepository addressRepository, SendNotificationService sendNotificationService) { | |
this.addressRepository = addressRepository; | |
this.sendNotificationService = sendNotificationService; | |
} | |
public void update(AddressUpdateRequest addressUpdateRequest) { | |
Optional<Address> addressOpt = addressRepository.findById(addressUpdateRequest.getId()); | |
addressOpt.map(address -> addressRepository.update(buildAddressFor(addressUpdateRequest))).orElseThrow(AddressUpdateException::new); | |
Notification notification = Notification.addressUpdateSuccessNotification(addressUpdateRequest.getMemberId()); | |
sendNotificationService.send(notification); | |
} | |
private Address buildAddressFor(AddressUpdateRequest addressUpdateRequest) { | |
Address address = new Address(); | |
address.setId(addressUpdateRequest.getId()); | |
address.setCity(addressUpdateRequest.getCity()); | |
address.setCounty(addressUpdateRequest.getCounty()); | |
address.setStreet(addressUpdateRequest.getStreet()); | |
return address; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment