mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add adding and removing of CustomProducts inside catalog_editor
This commit is contained in:
parent
5925ede2f8
commit
580529ab2f
|
@ -8,6 +8,7 @@ import org.springframework.ui.Model;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
@Controller
|
||||
|
@ -33,6 +34,14 @@ public class CatalogController {
|
|||
return "catalog_editor";
|
||||
}
|
||||
|
||||
@PostMapping("/catalog_editor/catalog_add")
|
||||
public String catalog_add(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) {
|
||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(
|
||||
// TODO: Fill with formCatalogEntry's data
|
||||
));
|
||||
return "redirect:/catalog";
|
||||
}
|
||||
|
||||
// Removes a catalog entry
|
||||
@PostMapping("/catalog/remove")
|
||||
public String removeEntry(@RequestParam int catalogEntryID) {
|
||||
|
@ -41,29 +50,30 @@ public class CatalogController {
|
|||
}
|
||||
|
||||
@PostMapping("/catalog_editor/product_add")
|
||||
public String product_add(Model model) {
|
||||
inventory.add(new CustomProduct("Test product", 5, 50));
|
||||
public String product_add(@RequestParam String name, @RequestParam int amount, @RequestParam double cost) {
|
||||
inventory.add(new CustomProduct(name, amount, cost));
|
||||
return "redirect:/catalog_editor";
|
||||
}
|
||||
|
||||
@PostMapping("/catalog_editor/catalog_add")
|
||||
public String catalog_add(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) {
|
||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry());
|
||||
return "redirect:/catalog";
|
||||
}
|
||||
|
||||
// Removes a product from the catalog_editor
|
||||
@PostMapping("/catalog_editor/remove_product")
|
||||
public String removeProduct(@RequestParam int productId, Model model) {
|
||||
inventory.remove(productId);
|
||||
model.addAttribute("inventory", inventory);
|
||||
public String removeProduct(@RequestParam String id, Model model) {
|
||||
Iterator<CustomProduct> iterator = inventory.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
CustomProduct currentProduct = iterator.next();
|
||||
|
||||
if (currentProduct.getItemId() == Integer.parseInt(id)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
return "redirect:/catalog_editor";
|
||||
}
|
||||
|
||||
@PostMapping("/catalog_editor/add_time")
|
||||
public String add_time(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) {
|
||||
System.out.println(formCatalogEntry.getMinimumTimePeriod());
|
||||
model.addAttribute("formCatalogEntry", formCatalogEntry);
|
||||
// Might not work because on every GetMapping of /catalog_editor a new formCatalogEntry is created
|
||||
return "redirect:/catalog_editor";
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ public class CustomCatalogEntry {
|
|||
return products;
|
||||
}
|
||||
|
||||
public String getMinimumTimePeriod() {
|
||||
return minimumTimePeriod + " h";
|
||||
public int getMinimumTimePeriod() {
|
||||
return minimumTimePeriod;
|
||||
}
|
||||
|
||||
public String getTotalCost() {
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
|
||||
<head>
|
||||
<title>Basisevent-Konfiguration</title></head>
|
||||
<title>Basisevent-Konfiguration</title>
|
||||
</head>
|
||||
<body>
|
||||
<nav>
|
||||
<div class="topnav"> <!-- später für css -->
|
||||
|
@ -17,7 +18,7 @@
|
|||
<h1>Basisevent konfigurieren</h1>
|
||||
<input type="hidden" name="addCatalog">
|
||||
<div class="content">
|
||||
<h2>Dienstleistung</h2>
|
||||
<h2>Dienstleistung</h2>
|
||||
<label for="dienstleistungen"></label>
|
||||
<select name="dienstleistungen" id="dienstleistungen">
|
||||
<option value="eventcatering">Eventcatering</option>
|
||||
|
@ -29,13 +30,13 @@
|
|||
|
||||
<h2>Mindestzeitraum</h2>
|
||||
<form th:object="${formCatalogEntry}" method="post" th:action="@{/catalog_editor/add_time}">
|
||||
<label>Mindestzeitraum:
|
||||
<input th:field="*{minimumTimePeriod}" type="number" name="minimumTimePeriod" min="1" step="1" value="1"/>
|
||||
<button type="submit">Zum Model hinzufügen</button>
|
||||
</label>
|
||||
<label>Mindestzeitraum:</label>
|
||||
<input th:field="*{minimumTimePeriod}" type="number" min="1" step="1" value="1"/>
|
||||
<button type="submit">Zum Model hinzufügen</button>
|
||||
</form>
|
||||
|
||||
<span th:text="${formCatalogEntry.minimumTimePeriod}"></span>
|
||||
<span th:text="${formCatalogEntry}"></span>
|
||||
|
||||
<h2>Basisausstattung</h2>
|
||||
<table>
|
||||
|
@ -45,24 +46,26 @@
|
|||
<th>Stückpreis</th>
|
||||
</tr>
|
||||
<tr th:each="item : ${inventory}">
|
||||
<td th:text="${item}">
|
||||
<td th:text="${item.getItemId()}">
|
||||
<td th:text="${item.getName()}">
|
||||
<td th:text="${item.getAmount()}">
|
||||
<td th:text="${item.getCost()}"> €
|
||||
<td>
|
||||
<form method="post" th:action="@{/catalog_editor/remove_product}">
|
||||
<input type="hidden" th:action="${inventory.remove(item.getItemId())}" name="productId" th:value="${item.getItemId()}">
|
||||
<input type="hidden" name="id" th:value="${item.getItemId()}">
|
||||
<button type="submit">Entfernen</button>
|
||||
</form>
|
||||
</td>
|
||||
<tr>
|
||||
<td>
|
||||
<form method="post" th:action="@{/catalog_editor/product_add}">
|
||||
<input type="hidden" name="addProduct">
|
||||
<button type="submit">Artikel hinzufügen</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<form method="post" th:action="@{/catalog_editor/product_add}">
|
||||
<label for="name">Produktname</label>
|
||||
<input type="text" id="name" name="name" required>
|
||||
<label for="amount">Menge</label>
|
||||
<input type="number" id="amount" name="amount" min="1" required>
|
||||
<input type="hidden" name="cost" value="50.0">
|
||||
<button type="submit">Artikel hinzufügen</button>
|
||||
</form>
|
||||
<br>
|
||||
Gesamtpreis: 90 €<br>
|
||||
<form method="post" th:action="@{/catalog_editor/catalog_add}" th:object="${formCatalogEntry}">
|
||||
|
|
Loading…
Reference in a new issue