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;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
2023-11-05 16:41:22 +01:00
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
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;
|
|
|
|
|
|
|
|
public OrderController(CustomOrderRepository orderRepository) {
|
|
|
|
this.orderRepository = orderRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
@PostMapping("/orders/remove")
|
|
|
|
public String removeOrder(@RequestParam int orderID) {
|
|
|
|
orderRepository.removeOrder(orderID);
|
|
|
|
return "redirect:/orders";
|
|
|
|
}
|
2023-11-05 10:39:39 +01:00
|
|
|
}
|