package catering.order; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; @Controller public class OrderController { private final CustomOrderRepository orderRepository; private final CustomCart cart; public OrderController(CustomOrderRepository orderRepository, CustomCart cart) { this.orderRepository = orderRepository; this.cart = cart; } @GetMapping("/orders") public String orders(Model model) { model.addAttribute("orders", orderRepository.getOrders()); model.addAttribute("total", orderRepository.getOrders().size()); return "orders"; } @GetMapping("/event") public String event(Model model) { model.addAttribute("items", cart.getProucts()); model.addAttribute("type", cart.getOrderType()); model.addAttribute("productForm", new ProductForm()); return "event"; } @PostMapping("/orders/remove") public String removeOrder(@RequestParam int orderID) { orderRepository.removeOrder(orderID); return "redirect:/orders"; } @PostMapping("/event/addProduct") public String addProduct(@ModelAttribute ProductForm product, Model model) { cart.addProduct(product.getProduct(), product.getNumber()); model.addAttribute("items", cart.getProucts()); model.addAttribute("type", cart.getOrderType()); model.addAttribute("productForm", new ProductForm()); return "redirect:/event"; } }