From 6bd1c23e2d92664cb8fdf2e1d8286b80d5e54de7 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Tue, 21 Nov 2023 23:01:33 +0100 Subject: [PATCH] Bind inventory mutate form to template Co-authored-by: Paul Heimer --- .../inventory/InventoryController.java | 24 +++++++++++++++++-- .../resources/templates/inventory-mutate.html | 20 ++++++++-------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main/java/catering/inventory/InventoryController.java b/src/main/java/catering/inventory/InventoryController.java index be5cb59..27218f9 100644 --- a/src/main/java/catering/inventory/InventoryController.java +++ b/src/main/java/catering/inventory/InventoryController.java @@ -17,6 +17,12 @@ package catering.inventory; import static org.salespointframework.core.Currencies.EURO; + +import java.util.Optional; + +import javax.money.MonetaryAmount; +import javax.money.NumberValue; + import org.javamoney.moneta.Money; import org.salespointframework.catalog.Product; import org.salespointframework.inventory.UniqueInventory; @@ -57,8 +63,22 @@ class InventoryController { @PreAuthorize("hasRole('ADMIN')") @GetMapping("/inventory/edit/{pid}") String edit(Model model, @PathVariable Product pid) { - model.addAttribute("product", pid); - model.addAttribute("item", inventory.findByProduct(pid).get()); + CatalogDummy product = (CatalogDummy) pid; + UniqueInventoryItem item = inventory.findByProduct(pid).get(); + return edit(model, pid, + new InventoryMutateForm(product.getType(), + product.getName(), + item.getQuantity(), + product.getWholesalePrice().getNumber().doubleValueExact(), + product.getPrice().getNumber().doubleValueExact(), + Optional.ofNullable(product.getPromotionPrice()) + .map(MonetaryAmount::getNumber) + .map(NumberValue::doubleValueExact))); + } + + String edit(Model model, @PathVariable Product pid, InventoryMutateForm form) { + model.addAttribute("actionIsAdd", false); + model.addAttribute("form", form); return "inventory-mutate"; } diff --git a/src/main/resources/templates/inventory-mutate.html b/src/main/resources/templates/inventory-mutate.html index 79f5f35..21efc93 100644 --- a/src/main/resources/templates/inventory-mutate.html +++ b/src/main/resources/templates/inventory-mutate.html @@ -5,37 +5,37 @@ layout:decorate="~{layout.html(title='Lagerverwaltung')}">
-

- -
+

+
- +
- +
- +
+
- +
- +
- +
- +