BAEL-7547: small fix

This commit is contained in:
emanuel.trandafir 2024-03-22 15:37:18 +01:00
parent 34fd8269e3
commit 23ff3bc2fc

View File

@ -18,13 +18,16 @@ public class LoyalCustomersRepository {
} }
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) {