From e5c0852e54af2c6d5ff7d20e21bce79b97528daa Mon Sep 17 00:00:00 2001 From: Paul Heimer Date: Fri, 24 Nov 2023 23:46:28 +0100 Subject: [PATCH] Add Comments to functions --- .../inventory/InventoryController.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/main/java/catering/inventory/InventoryController.java b/src/main/java/catering/inventory/InventoryController.java index 9eaabbc..cd65123 100644 --- a/src/main/java/catering/inventory/InventoryController.java +++ b/src/main/java/catering/inventory/InventoryController.java @@ -53,6 +53,13 @@ class InventoryController { this.cateringCatalog = cateringCatalog; } + /** + * Function to list all inventory products + * + * @param model the result of + * {@link org.springframework.ui.Model} + * @return inventory.html + */ @PreAuthorize("hasRole('ADMIN')") @GetMapping("/inventory") String list(Model model) { @@ -61,6 +68,15 @@ class InventoryController { return "inventory"; } + /** + * Function to get data from form. + * + * @param model the result of + * * {@link org.springframework.ui.Model} + * @param pid type of + * * {@link org.salespointframework.catalog.Product} + * @return 2nd edit() with new data of edit product + */ @PreAuthorize("hasRole('ADMIN')") @GetMapping("/inventory/edit/{pid}") String edit(Model model, @PathVariable Product pid) { @@ -77,6 +93,15 @@ class InventoryController { .map(NumberValue::doubleValueExact))); } + /** + * Function to display the edit product. + * @param model the result of + * * {@link org.springframework.ui.Model} + * @param pid type of + * * {@link org.salespointframework.catalog.Product} + * @param form type of catering.InventoryMutateForm + * @return inventory-mutate.html + */ String edit(Model model, @PathVariable Product pid, InventoryMutateForm form) { model.addAttribute("actionIsAdd", false); model.addAttribute("form", form); @@ -84,6 +109,18 @@ class InventoryController { return "inventory-mutate"; } + /** + * Function to set and save new data of edit product. + * + * @param form type of catering.InventoryMutateForm + * @param result the result of + * * * {@link org.springframework.validation.Errors} + * @param pid type of + * {@link org.salespointframework.catalog.Product} + * @param model the result of + * * {@link org.springframework.ui.Model} + * @return a redirect to inventory.html but with edit product + */ @PreAuthorize("hasRole('ADMIN')") @PostMapping("/inventory/edit/{pid}") String edit(@Valid @ModelAttribute("form") InventoryMutateForm form, Errors result, @PathVariable Product pid, Model model) { @@ -107,18 +144,42 @@ class InventoryController { return "redirect:/inventory"; } + /** + * Helper function for error handling in 3rd add(). + * + * @param model the result of + * * {@link org.springframework.ui.Model} + * @return the 2nd add() with empty InventoryMutate Form + */ @PreAuthorize("hasRole('ADMIN')") @GetMapping("/inventory/add") String add(Model model) { return add(model, InventoryMutateForm.empty()); } + /** + * Function to display the add product. + * + * @param model the result of + * * {@link org.springframework.ui.Model} + * @param form type of catering.InventoryMutateForm + * @return inventory-mutate.html + */ String add(Model model, InventoryMutateForm form) { model.addAttribute("actionIsAdd", true); model.addAttribute("form", form); return "inventory-mutate"; } + /** + * + * @param form type of catering.InventoryMutateForm + * @param result the result of + * * {@link org.springframework.validation.Errors} + * @param model the result of + * * {@link org.springframework.ui.Model} + * @return a redirect to inventory.html but with added product + */ @PreAuthorize("hasRole('ADMIN')") @PostMapping("/inventory/add") String add(@Valid @ModelAttribute("form") InventoryMutateForm form, Errors result, Model model) { @@ -134,6 +195,13 @@ class InventoryController { return "redirect:/inventory"; } + /** + * Function to delete one product in inventory. + * + * @param pid type of + * * {@link org.salespointframework.catalog.Product} + * @return a redirect to inventory.html but without deleted product. + */ @PreAuthorize("hasRole('ADMIN')") @GetMapping("/inventory/delete/{pid}") String delete(@PathVariable Product pid) {