swt23w23/src/main/java/catering/order/CustomCart.java

46 lines
962 B
Java
Raw Normal View History

package catering.order;
2023-11-07 22:23:48 +01:00
import org.salespointframework.quantity.Quantity;
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;
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() {
return products;
}
public void addProduct(String product, int number) {
2023-11-07 22:23:48 +01:00
products.put(product, Quantity.of(number));
}
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<>();
}
}