2023-11-05 10:39:39 +01:00
|
|
|
package catering.order;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
2023-11-05 12:33:43 +01:00
|
|
|
import org.springframework.ui.Model;
|
2023-11-07 20:53:31 +01:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
2023-11-05 10:39:39 +01:00
|
|
|
|
2023-11-05 15:36:46 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2023-11-05 10:39:39 +01:00
|
|
|
@Controller
|
|
|
|
public class OrderController {
|
|
|
|
|
2023-11-05 12:33:43 +01:00
|
|
|
private final CustomOrderRepository orderRepository;
|
2023-11-07 20:53:31 +01:00
|
|
|
private final CustomCart cart;
|
2023-11-05 12:33:43 +01:00
|
|
|
|
2023-11-07 20:53:31 +01:00
|
|
|
public OrderController(CustomOrderRepository orderRepository, CustomCart cart) {
|
2023-11-05 12:33:43 +01:00
|
|
|
this.orderRepository = orderRepository;
|
2023-11-07 20:53:31 +01:00
|
|
|
this.cart = cart;
|
2023-11-05 12:33:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/orders")
|
|
|
|
public String orders(Model model) {
|
2023-11-05 15:36:46 +01:00
|
|
|
model.addAttribute("orders", orderRepository.getOrders());
|
2023-11-05 12:33:43 +01:00
|
|
|
model.addAttribute("total", orderRepository.getOrders().size());
|
|
|
|
return "orders";
|
|
|
|
}
|
2023-11-05 16:41:22 +01:00
|
|
|
|
2023-11-07 17:50:29 +01:00
|
|
|
@GetMapping("/event")
|
2023-11-07 20:53:31 +01:00
|
|
|
public String event(Model model) {
|
|
|
|
model.addAttribute("items", cart.getProucts());
|
|
|
|
model.addAttribute("type", cart.getOrderType());
|
|
|
|
model.addAttribute("productForm", new ProductForm());
|
|
|
|
return "event";
|
2023-11-07 17:50:29 +01:00
|
|
|
}
|
|
|
|
|
2023-11-05 16:41:22 +01:00
|
|
|
@PostMapping("/orders/remove")
|
|
|
|
public String removeOrder(@RequestParam int orderID) {
|
|
|
|
orderRepository.removeOrder(orderID);
|
|
|
|
return "redirect:/orders";
|
|
|
|
}
|
2023-11-07 20:53:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
@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";
|
|
|
|
}
|
2023-11-05 10:39:39 +01:00
|
|
|
}
|