mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add forms to the catalog editor to submit its data
This commit is contained in:
parent
94a03e2266
commit
89eed0755d
|
@ -2,14 +2,23 @@ package catering.orderCatalog;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class CatalogController {
|
public class CatalogController {
|
||||||
private CustomCatalogEntryRepository catalogEntryRepository;
|
private CustomCatalogEntryRepository catalogEntryRepository;
|
||||||
|
private Set<CustomProduct> inventory;
|
||||||
|
|
||||||
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) {
|
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) {
|
||||||
|
inventory = new HashSet<>();
|
||||||
this.catalogEntryRepository = catalogEntryRepository;
|
this.catalogEntryRepository = catalogEntryRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,13 +29,44 @@ public class CatalogController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/catalog_editor")
|
@GetMapping("/catalog_editor")
|
||||||
public String event_configuration() {
|
public String catalog_configuration(Model model) {
|
||||||
|
model.addAttribute("inventory", inventory);
|
||||||
|
model.addAttribute("formCatalogEntry", new CustomCatalogEntry());
|
||||||
return "catalog_editor";
|
return "catalog_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes a catalog entry
|
||||||
@PostMapping("/catalog/remove")
|
@PostMapping("/catalog/remove")
|
||||||
public String removeItem() {
|
public String removeEntry(@RequestParam int catalogEntryID) {
|
||||||
|
catalogEntryRepository.removeCatalogEntry(catalogEntryID);
|
||||||
return "catalog_editor";
|
return "catalog_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/catalog_editor/product_add")
|
||||||
|
public String product_add(Model model) {
|
||||||
|
inventory.add(new CustomProduct("Test product", 5, 50));
|
||||||
|
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);
|
||||||
|
|
||||||
|
return "redirect:/catalog_editor";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/catalog_editor/add_time")
|
||||||
|
public String add_time(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) {
|
||||||
|
model.addAttribute("formCatalogEntry", formCatalogEntry);
|
||||||
|
return "redirect:/catalog_editor";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
|
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
|
||||||
<head>
|
<head>
|
||||||
<title>Basiseventkonfiguration</title>
|
<title>Basisevent-Konfiguration</title></head>
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
<div class="topnav"> <!-- später für css -->
|
<div class="topnav"> <!-- später für css -->
|
||||||
|
@ -16,6 +15,7 @@
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<h1>Basisevent konfigurieren</h1>
|
<h1>Basisevent konfigurieren</h1>
|
||||||
|
<input type="hidden" name="addCatalog">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h2>Dienstleistung</h2>
|
<h2>Dienstleistung</h2>
|
||||||
<label for="dienstleistungen"></label>
|
<label for="dienstleistungen"></label>
|
||||||
|
@ -28,9 +28,14 @@
|
||||||
Eventbasispreis: 500€
|
Eventbasispreis: 500€
|
||||||
|
|
||||||
<h2>Mindestzeitraum</h2>
|
<h2>Mindestzeitraum</h2>
|
||||||
<label>Mindestzeitraum:
|
<form th:object="${formCatalogEntry}" method="post" th:action="@{/catalog_editor/add_time}">
|
||||||
<input type="number" name="amount" min="1" step="1" value="1"/>
|
<label>Mindestzeitraum:
|
||||||
</label>h
|
<input th:field="*{minimumTimePeriod}" type="number" name="minimumTimePeriod" min="1" step="1" value="1"/>
|
||||||
|
<button type="submit">Zum Model hinzufügen</button>
|
||||||
|
</label>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<span th:text="${formCatalogEntry.minimumTimePeriod}"></span>
|
||||||
|
|
||||||
<h2>Basisausstattung</h2>
|
<h2>Basisausstattung</h2>
|
||||||
<table>
|
<table>
|
||||||
|
@ -39,39 +44,30 @@
|
||||||
<th>Menge</th>
|
<th>Menge</th>
|
||||||
<th>Stückpreis</th>
|
<th>Stückpreis</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr th:each="item : ${inventory}">
|
||||||
<td>Brötchen</td>
|
<td th:text="${item.getName()}">
|
||||||
|
<td th:text="${item.getAmount()}">
|
||||||
|
<td th:text="${item.getCost()}"> €
|
||||||
<td>
|
<td>
|
||||||
<input type="number" name="amount" min="1" step="1" value="1"/>
|
<form method="post" th:action="@{/catalog_editor/remove_product}">
|
||||||
</td>
|
<input type="hidden" th:action="${inventory.remove(item.getItemId())}" name="productId" th:value="${item.getItemId()}">
|
||||||
<td>1,00 €</td>
|
<button type="submit">Entfernen</button>
|
||||||
<td>
|
|
||||||
<form method="post" th:action="@{/catalog/remove}">
|
|
||||||
<input type="hidden" name="itemID" value="0"/>
|
|
||||||
<input type="submit" value="remove" th:value="Entfernen"/>
|
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Kerze</td>
|
|
||||||
<td>
|
<td>
|
||||||
<input type="number" name="amount" min="1" step="1" value="1"/>
|
<form method="post" th:action="@{/catalog_editor/product_add}">
|
||||||
</td>
|
<input type="hidden" name="addProduct">
|
||||||
<td>3.00 €</td>
|
<button type="submit">Artikel hinzufügen</button>
|
||||||
<td>
|
|
||||||
<form method="post" th:action="@{/catalog/remove}">
|
|
||||||
<input type="hidden" name="itemID" value="0"/>
|
|
||||||
<input type="submit" value="remove" th:value="Entfernen"/>
|
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td>[Artikel Hinzufügen]</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
Gesamtpreis: 90 €<br>
|
Gesamtpreis: 90 €<br>
|
||||||
<button>Zum Katalog hinzufügen</button>
|
<form method="post" th:action="@{/catalog_editor/catalog_add}" th:object="${formCatalogEntry}">
|
||||||
|
<button type="submit">Zum Katalog hinzufügen</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue