BAEL-7547: small fix
This commit is contained in:
parent
34fd8269e3
commit
23ff3bc2fc
@ -13,18 +13,21 @@ public class LoyalCustomersRepository {
|
|||||||
|
|
||||||
public Optional<LoyalCustomer> find(String customerId) {
|
public Optional<LoyalCustomer> find(String customerId) {
|
||||||
return customers.stream()
|
return customers.stream()
|
||||||
.filter(it -> it.customerId().equals(customerId))
|
.filter(it -> it.customerId().equals(customerId))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void awardPoints(String customerId, int points) {
|
public void awardPoints(String customerId, int points) {
|
||||||
var customer = find(customerId).orElseThrow();
|
var customer = find(customerId)
|
||||||
|
.orElseGet(() -> save(new LoyalCustomer(customerId, 0)));
|
||||||
|
|
||||||
customers.remove(customer);
|
customers.remove(customer);
|
||||||
customers.add(customer.addPoints(points));
|
customers.add(customer.addPoints(points));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(String customerId) {
|
public LoyalCustomer save(LoyalCustomer customer) {
|
||||||
customers.add(new LoyalCustomer(customerId, 0));
|
customers.add(customer);
|
||||||
|
return customer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoyalCustomer(String customerId) {
|
public boolean isLoyalCustomer(String customerId) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user