Add display of all catalog entries (CustomCatalogEntry) in catalog

This commit is contained in:
Erik Hohlfeld 2023-11-09 23:46:55 +01:00 committed by Simon Bruder
parent 052b8e1a75
commit 6875622c19
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
6 changed files with 43 additions and 34 deletions

View file

@ -3,12 +3,19 @@ package catering.orderCatalog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.ui.Model;
@Controller
public class CatalogController {
private CustomCatalogEntryRepository catalogEntryRepository;
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) {
this.catalogEntryRepository = catalogEntryRepository;
}
@GetMapping("/catalog")
public String catalog() {
public String catalog(Model model) {
model.addAttribute("catalogEntries", catalogEntryRepository.getCatalogEntries());
return "catalog";
}
@ -19,7 +26,7 @@ public class CatalogController {
@PostMapping("/catalog/remove")
public String removeItem() {
return "redirect:/catalog";
return "catalog_editor";
}
}

View file

@ -8,13 +8,15 @@ public class CustomCatalogEntry {
private EventType eventType;
private Map<String, Integer> products;
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(EventType eventType, Map<String, Integer> products, int minimumTimePeriod) {
public CustomCatalogEntry(EventType eventType, Map<String, Integer> products, int minimumTimePeriod, int totalCost) {
this.id = idCounter;
idCounter++;
this.eventType = eventType;
this.products = products;
this.minimumTimePeriod = minimumTimePeriod;
this.totalCost = totalCost;
}
public int getId() {
@ -29,8 +31,12 @@ public class CustomCatalogEntry {
return products;
}
public int getMinimumTimePeriod() {
return minimumTimePeriod;
public String getMinimumTimePeriod() {
return minimumTimePeriod + " h";
}
public String getTotalCost() {
return totalCost + "";
}
public enum EventType {

View file

@ -23,7 +23,8 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer {
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(
CustomCatalogEntry.EventType.EVENT_CATERING,
products,
3
3,
300
));
products = new HashMap<>();
@ -35,7 +36,8 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer {
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(
CustomCatalogEntry.EventType.PARTY_SERVICE,
products,
3
3,
500
));
}
}

View file

@ -25,4 +25,8 @@ public class CustomCatalogEntryRepository {
}
return false;
}
public Set<CustomCatalogEntry> getCatalogEntries() {
return catalogEntries;
}
}

View file

@ -29,35 +29,18 @@
<th>Basisausstattung</th>
<th>Preis ab</th>
</tr>
<tr>
<tr th:each="catalogEntry : ${catalogEntries}">
<td>
**BILD**
</td>
<td>Rent-a-Cook</td>
<td>3h</td>
<td th:text="${catalogEntry.getEventType()}">
<td th:text="${catalogEntry.getMinimumTimePeriod()}">h
<td>
<ul>
<li>1 Koch</li>
<li>300kg Mettbrötchen</li>
<li>300kg vegane Weißwurst</li>
<ul th:each="product : ${catalogEntry.getProducts()}">
<li th:text="${product}"/>
</ul>
</td>
<td>499,99€</td>
</tr>
<tr>
<td>
**BILD**
</td>
<td>Sushi-Abend</td>
<td>4h</td>
<td>
<ul>
<li>2 Köche</li>
<li>300kg Sushi</li>
<li>300kg Sushi vegan</li>
</ul>
</td>
<td>699,99€</td>
<td th:text="${catalogEntry.getTotalCost()}">
</tr>
</table>
</div>
@ -68,6 +51,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>

View file

@ -3,7 +3,8 @@
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title>Auftragskonfiguration</title></head>
<title>Basiseventkonfiguration</title>
</head>
<body>
<nav>
<div class="topnav"> <!-- später für css -->
@ -14,7 +15,7 @@
<!--<a href="#account">Mein Konto</a>-->
</div>
</nav>
<h1>Auftrag konfigurieren</h1>
<h1>Basisevent konfigurieren</h1>
<div class="content">
<h2>Dienstleistung</h2>
<label for="dienstleistungen"></label>