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 34f4fcf069
commit f1f71beaf4
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.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.ui.Model;
@Controller @Controller
public class CatalogController { public class CatalogController {
private CustomCatalogEntryRepository catalogEntryRepository;
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) {
this.catalogEntryRepository = catalogEntryRepository;
}
@GetMapping("/catalog") @GetMapping("/catalog")
public String catalog() { public String catalog(Model model) {
model.addAttribute("catalogEntries", catalogEntryRepository.getCatalogEntries());
return "catalog"; return "catalog";
} }
@ -19,7 +26,7 @@ public class CatalogController {
@PostMapping("/catalog/remove") @PostMapping("/catalog/remove")
public String removeItem() { public String removeItem() {
return "redirect:/catalog"; return "catalog_editor";
} }
} }

View file

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

View file

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

View file

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

View file

@ -17,7 +17,7 @@
</div> </div>
<div> <div>
<h1>Katalog</h1> <h1>Katalog</h1>
</div> </div>
<div> <div>
@ -29,35 +29,18 @@
<th>Basisausstattung</th> <th>Basisausstattung</th>
<th>Preis ab</th> <th>Preis ab</th>
</tr> </tr>
<tr> <tr th:each="catalogEntry : ${catalogEntries}">
<td> <td>
**BILD** **BILD**
</td> </td>
<td>Rent-a-Cook</td> <td th:text="${catalogEntry.getEventType()}">
<td>3h</td> <td th:text="${catalogEntry.getMinimumTimePeriod()}">h
<td> <td>
<ul> <ul th:each="product : ${catalogEntry.getProducts()}">
<li>1 Koch</li> <li th:text="${product}"/>
<li>300kg Mettbrötchen</li>
<li>300kg vegane Weißwurst</li>
</ul> </ul>
</td> </td>
<td>499,99€</td> <td th:text="${catalogEntry.getTotalCost()}">
</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>
</tr> </tr>
</table> </table>
</div> </div>
@ -68,6 +51,12 @@
</form> </form>
</div> </div>
<div>
<form th:action="@{/catalog_editor}">
<button type="submit">Hinzufügen</button>
</form>
</div>
<div> <div>
<button type="button">Hinzufügen</button> <button type="button">Hinzufügen</button>
</div> </div>

View file

@ -3,7 +3,8 @@
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>Auftragskonfiguration</title></head> <title>Basiseventkonfiguration</title>
</head>
<body> <body>
<nav> <nav>
<div class="topnav"> <!-- später für css --> <div class="topnav"> <!-- später für css -->
@ -14,7 +15,7 @@
<!--<a href="#account">Mein Konto</a>--> <!--<a href="#account">Mein Konto</a>-->
</div> </div>
</nav> </nav>
<h1>Auftrag konfigurieren</h1> <h1>Basisevent konfigurieren</h1>
<div class="content"> <div class="content">
<h2>Dienstleistung</h2> <h2>Dienstleistung</h2>
<label for="dienstleistungen"></label> <label for="dienstleistungen"></label>
@ -69,7 +70,7 @@
</tr> </tr>
</table> </table>
<br> <br>
Gesamtpreis: 90 €<br> Gesamtpreis: 90 €<br>
<button>Zum Katalog hinzufügen</button> <button>Zum Katalog hinzufügen</button>
</div> </div>
</body> </body>