mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add removal of CustomCatalogEntry inside catalog via button
This commit is contained in:
parent
580529ab2f
commit
e7a722b6f8
|
@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
@ -30,14 +31,22 @@ public class CatalogController {
|
|||
@GetMapping("/catalog_editor")
|
||||
public String catalog_configuration(Model model) {
|
||||
model.addAttribute("inventory", inventory);
|
||||
model.addAttribute("formCatalogEntry", new CustomCatalogEntry());
|
||||
model.addAttribute("formCatalogEntry", new CustomCatalogEntry(
|
||||
CustomCatalogEntry.EventType.EVENT_CATERING,
|
||||
new HashMap<String, Integer>(),
|
||||
0,
|
||||
0));
|
||||
return "catalog_editor";
|
||||
}
|
||||
|
||||
@PostMapping("/catalog_editor/catalog_add")
|
||||
public String catalog_add(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) {
|
||||
public String catalog_add(Model model) {
|
||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(
|
||||
// TODO: Fill with formCatalogEntry's data
|
||||
// TODO: Fill with formCatalogEntry's data instead of dummy data
|
||||
CustomCatalogEntry.EventType.EVENT_CATERING,
|
||||
new HashMap<String, Integer>(),
|
||||
0,
|
||||
0
|
||||
));
|
||||
return "redirect:/catalog";
|
||||
}
|
||||
|
@ -46,7 +55,7 @@ public class CatalogController {
|
|||
@PostMapping("/catalog/remove")
|
||||
public String removeEntry(@RequestParam int catalogEntryID) {
|
||||
catalogEntryRepository.removeCatalogEntry(catalogEntryID);
|
||||
return "catalog_editor";
|
||||
return "redirect:/catalog";
|
||||
}
|
||||
|
||||
@PostMapping("/catalog_editor/product_add")
|
||||
|
@ -70,10 +79,11 @@ public class CatalogController {
|
|||
}
|
||||
|
||||
@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
|
||||
public String add_time(@RequestParam int minimumTimePeriod, @ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) {
|
||||
System.out.println(minimumTimePeriod);
|
||||
/*System.out.println(formCatalogEntry.getMinimumTimePeriod());
|
||||
model.addAttribute("formCatalogEntry", formCatalogEntry);*/
|
||||
// TODO: Might not work because on every GetMapping of /catalog_editor a new formCatalogEntry is created
|
||||
return "redirect:/catalog_editor";
|
||||
}
|
||||
|
||||
|
|
|
@ -11,13 +11,13 @@ public class CustomCatalogEntry {
|
|||
private int minimumTimePeriod; // Declared as int for simplification of the prototype. Only whole hours.
|
||||
private int totalCost; // Should actually accumulate the price of all items.
|
||||
|
||||
public CustomCatalogEntry() {
|
||||
public CustomCatalogEntry(EventType eventType, Map<String, Integer> products, int minimumTimePeriod, int totalCost) {
|
||||
this.id = idCounter;
|
||||
idCounter++;
|
||||
this.eventType = EventType.EVENT_CATERING;
|
||||
this.products = new HashMap<String, Integer>();
|
||||
this.minimumTimePeriod = 5;
|
||||
this.totalCost = 3;
|
||||
this.eventType = eventType;
|
||||
this.products = products;
|
||||
this.minimumTimePeriod = minimumTimePeriod;
|
||||
this.totalCost = totalCost;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
@ -44,6 +44,9 @@ public class CustomCatalogEntry {
|
|||
this.eventType = eventType;
|
||||
}
|
||||
|
||||
public void setProducts(Map<String, Integer> products) {
|
||||
this.products = products;
|
||||
}
|
||||
public void setMinimumTimePeriod(int timePeriod) {
|
||||
this.minimumTimePeriod = timePeriod;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer {
|
|||
Map<String, Integer> products = new HashMap<>();
|
||||
products.put("Brötchen", 30);
|
||||
products.put("Kerze", 20);
|
||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry());
|
||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(CustomCatalogEntry.EventType.EVENT_CATERING, products, 4, 500));
|
||||
|
||||
products = new HashMap<>();
|
||||
products.put("Kuchen", 3);
|
||||
|
@ -28,6 +28,6 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer {
|
|||
products.put("Pizza Margherita", 1);
|
||||
products.put("Pizza Quattro Formaggi", 1);
|
||||
products.put("Ballon", 20);
|
||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry());
|
||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(CustomCatalogEntry.EventType.PARTY_SERVICE, products, 2, 1000));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
<td>
|
||||
**BILD**
|
||||
</td>
|
||||
<td th:text="${catalogEntry.getId()}">
|
||||
<td th:text="${catalogEntry.getEventType()}">
|
||||
<td th:text="${catalogEntry.getMinimumTimePeriod()}">h
|
||||
<td>
|
||||
|
@ -41,6 +42,12 @@
|
|||
</ul>
|
||||
</td>
|
||||
<td th:text="${catalogEntry.getTotalCost()}">
|
||||
<td>
|
||||
<form method="post" th:action="@{/catalog/remove}">
|
||||
<input type="hidden" name="catalogEntryID" th:value="${catalogEntry.getId()}">
|
||||
<button type="submit">Entfernen</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -57,6 +64,12 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<form th:action="@{/catalog_editor}">
|
||||
<button type="submit">Hinzufügen</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button type="button">Hinzufügen</button>
|
||||
</div>
|
||||
|
@ -70,4 +83,3 @@
|
|||
</p>
|
||||
</footer>
|
||||
</html>
|
||||
|
||||
|
|
|
@ -18,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>
|
||||
|
@ -31,7 +31,7 @@
|
|||
<h2>Mindestzeitraum</h2>
|
||||
<form th:object="${formCatalogEntry}" method="post" th:action="@{/catalog_editor/add_time}">
|
||||
<label>Mindestzeitraum:</label>
|
||||
<input th:field="*{minimumTimePeriod}" type="number" min="1" step="1" value="1"/>
|
||||
<input th:field="*{minimumTimePeriod}" type="number" min="0" step="1" value="1"/>
|
||||
<button type="submit">Zum Model hinzufügen</button>
|
||||
</form>
|
||||
|
||||
|
@ -46,8 +46,6 @@
|
|||
<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()}"> €
|
||||
|
@ -58,6 +56,8 @@
|
|||
</form>
|
||||
</td>
|
||||
</table>
|
||||
<hr>
|
||||
<div style="height: 20px;"></div>
|
||||
<form method="post" th:action="@{/catalog_editor/product_add}">
|
||||
<label for="name">Produktname</label>
|
||||
<input type="text" id="name" name="name" required>
|
||||
|
|
Loading…
Reference in a new issue