Add order backend for kundenwunsch

This checks if the requested product to add is suitable for the event.
This works on #100
This commit is contained in:
Mathis Kral 2023-12-11 14:06:32 +01:00 committed by Mathis
parent 5736b49080
commit 44c9eb8f3a

View file

@ -173,6 +173,11 @@ public class OrderController {
@PostMapping("/event/addProduct")
@PreAuthorize("hasRole('CUSTOMER')")
public String addProduct(@RequestParam("pid") Product product, @RequestParam("number") int number, @ModelAttribute("event") CustomCart cart) {
// check if product is suitable
if (product.getCategories().stream().noneMatch(c -> c.equals(cart.getOrderType().toString()))) {
return "redirect:/event";
}
Quantity amount = Quantity.of(number > 0 ? number : 1);
Quantity cartQuantity = cart.getQuantity(product);
Quantity available;