mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Fix broken cart cleanup
This fixes an error occuring when multiple employees were added to the event before checkout.
This commit is contained in:
parent
ee7ab27a6d
commit
cef94a0bdb
|
@ -11,7 +11,7 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class CustomCart extends Cart {
|
public class CustomCart extends Cart {
|
||||||
private final Set<Employee> staff;
|
private Set<Employee> staff;
|
||||||
private OrderType orderType;
|
private OrderType orderType;
|
||||||
private LocalDateTime start;
|
private LocalDateTime start;
|
||||||
private LocalDateTime finish;
|
private LocalDateTime finish;
|
||||||
|
@ -31,12 +31,12 @@ public class CustomCart extends Cart {
|
||||||
* Adds an employee to the cart
|
* Adds an employee to the cart
|
||||||
*/
|
*/
|
||||||
public boolean addEmployee(Employee employee) {
|
public boolean addEmployee(Employee employee) {
|
||||||
for (Employee myEmployee : this.staff) {
|
for (Employee myEmployee : staff) {
|
||||||
if (myEmployee.equals(employee)) {
|
if (myEmployee.equals(employee)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.staff.add(employee);
|
return staff.add(employee);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Employee> getStaff() {
|
public Set<Employee> getStaff() {
|
||||||
|
@ -44,9 +44,9 @@ public class CustomCart extends Cart {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeEmployee(Employee employee) {
|
public boolean removeEmployee(Employee employee) {
|
||||||
for (Employee myEmployee : this.staff) {
|
for (Employee myEmployee : staff) {
|
||||||
if (myEmployee.equals(employee)) {
|
if (myEmployee.equals(employee)) {
|
||||||
return this.staff.remove(myEmployee);
|
return staff.remove(myEmployee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -56,7 +56,7 @@ public class CustomCart extends Cart {
|
||||||
* Add staff to order (analogous to cart.addItemsTo(order))
|
* Add staff to order (analogous to cart.addItemsTo(order))
|
||||||
*/
|
*/
|
||||||
public CustomOrder addStaffTo(CustomOrder order) {
|
public CustomOrder addStaffTo(CustomOrder order) {
|
||||||
for (Employee employee : this.staff) {
|
for (Employee employee : staff) {
|
||||||
order.addEmployee(employee);
|
order.addEmployee(employee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,12 +106,16 @@ public class CustomCart extends Cart {
|
||||||
total = total.add(Money.of(getDurationInHoursTimesRate(12.0), "EUR"));
|
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;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
super.clear();
|
super.clear();
|
||||||
staff.forEach(staff::remove);
|
staff = new HashSet<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue