Add Comments to functions

This commit is contained in:
Paul Heimer 2023-11-24 23:46:28 +01:00
parent 53c40fec2f
commit e5c0852e54

View file

@ -53,6 +53,13 @@ class InventoryController {
this.cateringCatalog = cateringCatalog; 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')") @PreAuthorize("hasRole('ADMIN')")
@GetMapping("/inventory") @GetMapping("/inventory")
String list(Model model) { String list(Model model) {
@ -61,6 +68,15 @@ class InventoryController {
return "inventory"; 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')") @PreAuthorize("hasRole('ADMIN')")
@GetMapping("/inventory/edit/{pid}") @GetMapping("/inventory/edit/{pid}")
String edit(Model model, @PathVariable Product pid) { String edit(Model model, @PathVariable Product pid) {
@ -77,6 +93,15 @@ class InventoryController {
.map(NumberValue::doubleValueExact))); .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) { String edit(Model model, @PathVariable Product pid, InventoryMutateForm form) {
model.addAttribute("actionIsAdd", false); model.addAttribute("actionIsAdd", false);
model.addAttribute("form", form); model.addAttribute("form", form);
@ -84,6 +109,18 @@ class InventoryController {
return "inventory-mutate"; 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')") @PreAuthorize("hasRole('ADMIN')")
@PostMapping("/inventory/edit/{pid}") @PostMapping("/inventory/edit/{pid}")
String edit(@Valid @ModelAttribute("form") InventoryMutateForm form, Errors result, @PathVariable Product pid, Model model) { String edit(@Valid @ModelAttribute("form") InventoryMutateForm form, Errors result, @PathVariable Product pid, Model model) {
@ -107,18 +144,42 @@ class InventoryController {
return "redirect:/inventory"; 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')") @PreAuthorize("hasRole('ADMIN')")
@GetMapping("/inventory/add") @GetMapping("/inventory/add")
String add(Model model) { String add(Model model) {
return add(model, InventoryMutateForm.empty()); 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) { String add(Model model, InventoryMutateForm form) {
model.addAttribute("actionIsAdd", true); model.addAttribute("actionIsAdd", true);
model.addAttribute("form", form); model.addAttribute("form", form);
return "inventory-mutate"; 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')") @PreAuthorize("hasRole('ADMIN')")
@PostMapping("/inventory/add") @PostMapping("/inventory/add")
String add(@Valid @ModelAttribute("form") InventoryMutateForm form, Errors result, Model model) { String add(@Valid @ModelAttribute("form") InventoryMutateForm form, Errors result, Model model) {
@ -134,6 +195,13 @@ class InventoryController {
return "redirect:/inventory"; 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')") @PreAuthorize("hasRole('ADMIN')")
@GetMapping("/inventory/delete/{pid}") @GetMapping("/inventory/delete/{pid}")
String delete(@PathVariable Product pid) { String delete(@PathVariable Product pid) {