Skip to content

Instantly share code, notes, and snippets.

@pawelpluta

pawelpluta/Sales.java Secret

Created Jan 29, 2021
Embed
What would you like to do?
Tell don't ask - sales
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