-
-
Save pawelpluta/8841abef0d0f6f1f26725ed509aa61e5 to your computer and use it in GitHub Desktop.
Tell don't ask - sales
This file contains 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
public class Sales { | |
private final CrateRepository crateRepository; | |
private final DeliveryService deliveryService; | |
public Sales(CrateRepository crateRepository, DeliveryService deliveryService) { | |
this.crateRepository = crateRepository; | |
this.deliveryService = deliveryService; | |
} | |
public boolean sell(Integer soldCrates, ProductType type, Customer customer) { | |
List<Crate> crates = crateRepository.findByTypeLimit(type, soldCrates); | |
if (crates.size() != soldCrates) { | |
return false; | |
} | |
if (customer.getWarehouseAddressVerified()) { | |
Package packageToDeliver = new Package(crates, customer); | |
deliveryService.send(packageToDeliver); | |
crateRepository.delete(crates); | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment