From cef94a0bdbbf0436a78c47ba3e46c56aef3c6d0f Mon Sep 17 00:00:00 2001 From: Mathis Kral Date: Sun, 3 Dec 2023 21:32:12 +0100 Subject: [PATCH] Fix broken cart cleanup This fixes an error occuring when multiple employees were added to the event before checkout. --- src/main/java/catering/order/CustomCart.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/catering/order/CustomCart.java b/src/main/java/catering/order/CustomCart.java index 83ac409..842ffb5 100644 --- a/src/main/java/catering/order/CustomCart.java +++ b/src/main/java/catering/order/CustomCart.java @@ -11,7 +11,7 @@ import java.util.HashSet; import java.util.Set; public class CustomCart extends Cart { - private final Set staff; + private Set staff; private OrderType orderType; private LocalDateTime start; private LocalDateTime finish; @@ -31,12 +31,12 @@ public class CustomCart extends Cart { * Adds an employee to the cart */ public boolean addEmployee(Employee employee) { - for (Employee myEmployee : this.staff) { + for (Employee myEmployee : staff) { if (myEmployee.equals(employee)) { return false; } } - return this.staff.add(employee); + return staff.add(employee); } public Set getStaff() { @@ -44,9 +44,9 @@ public class CustomCart extends Cart { } public boolean removeEmployee(Employee employee) { - for (Employee myEmployee : this.staff) { + for (Employee myEmployee : staff) { if (myEmployee.equals(employee)) { - return this.staff.remove(myEmployee); + return staff.remove(myEmployee); } } return false; @@ -56,7 +56,7 @@ public class CustomCart extends Cart { * Add staff to order (analogous to cart.addItemsTo(order)) */ public CustomOrder addStaffTo(CustomOrder order) { - for (Employee employee : this.staff) { + for (Employee employee : staff) { order.addEmployee(employee); } @@ -106,12 +106,16 @@ public class CustomCart extends Cart { total = total.add(Money.of(getDurationInHoursTimesRate(12.0), "EUR")); } + for (Employee employee : staff) { + total = total.add(Money.of(getDurationInHoursTimesRate(12), "EUR")); // TODO: get from employee + } + return total; } @Override public void clear() { super.clear(); - staff.forEach(staff::remove); + staff = new HashSet<>(); } }