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

51 lines
1.4 KiB
Java
Raw Normal View History

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";
}
2023-11-05 16:41:22 +01:00
@GetMapping("/event")
public String event(Model model) {
model.addAttribute("items", cart.getProucts());
model.addAttribute("type", cart.getOrderType());
model.addAttribute("productForm", new ProductForm());
return "event";
}
2023-11-05 16:41:22 +01:00
@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";
}
}