Skip to content

Instantly share code, notes, and snippets.

@yusufcakal
Created October 11, 2020 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yusufcakal/b3290619399d01160d1fba94fe3bd707 to your computer and use it in GitHub Desktop.
Save yusufcakal/b3290619399d01160d1fba94fe3bd707 to your computer and use it in GitHub Desktop.
@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