2023-11-07 20:53:31 +01:00
|
|
|
package catering.order;
|
|
|
|
|
2023-11-07 22:23:48 +01:00
|
|
|
import org.salespointframework.quantity.Quantity;
|
2023-11-07 20:53:31 +01:00
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
public class CustomCart {
|
|
|
|
private CustomOrder.OrderType orderType;
|
2023-11-07 22:23:48 +01:00
|
|
|
private Map<String, Quantity> products;
|
2023-11-07 20:53:31 +01:00
|
|
|
|
|
|
|
public CustomCart() {
|
|
|
|
this.orderType = CustomOrder.OrderType.SOMETHING_ELSE;
|
|
|
|
this.products = new HashMap<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public CustomOrder.OrderType getOrderType() {
|
|
|
|
return orderType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOrderType(CustomOrder.OrderType type) {
|
|
|
|
this.orderType = type;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-07 22:23:48 +01:00
|
|
|
public Map<String, Quantity> getProucts() {
|
2023-11-07 20:53:31 +01:00
|
|
|
return products;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addProduct(String product, int number) {
|
2023-11-07 22:23:48 +01:00
|
|
|
products.put(product, Quantity.of(number));
|
2023-11-07 20:53:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean removeProduct(String product) {
|
|
|
|
return products.remove(product) != null;
|
|
|
|
}
|
2023-11-07 22:23:48 +01:00
|
|
|
|
|
|
|
public void resetCart() {
|
|
|
|
orderType = CustomOrder.OrderType.SOMETHING_ELSE;
|
|
|
|
products = new HashMap<>();
|
|
|
|
}
|
2023-11-07 20:53:31 +01:00
|
|
|
}
|