mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add Comments to functions
This commit is contained in:
parent
53c40fec2f
commit
e5c0852e54
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue