mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add functionality to add to the catalog with the catalog_editor
This commit is contained in:
parent
bde2754a51
commit
47f8071382
|
@ -2,23 +2,25 @@ 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 org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class CatalogController {
|
public class CatalogController {
|
||||||
private CustomCatalogEntryRepository catalogEntryRepository;
|
private CustomCatalogEntryRepository catalogEntryRepository;
|
||||||
private Set<CustomProduct> inventory;
|
private Set<CustomProduct> inventory;
|
||||||
|
private CustomCatalogEntry formCatalogEntry;
|
||||||
|
|
||||||
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) {
|
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) {
|
||||||
inventory = new HashSet<>();
|
inventory = new HashSet<>();
|
||||||
|
formCatalogEntry = new CustomCatalogEntry(
|
||||||
|
CustomCatalogEntry.EventType.EVENT_CATERING,
|
||||||
|
new HashMap<String, Integer>(),
|
||||||
|
0,
|
||||||
|
0);
|
||||||
this.catalogEntryRepository = catalogEntryRepository;
|
this.catalogEntryRepository = catalogEntryRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,23 +33,35 @@ public class CatalogController {
|
||||||
@GetMapping("/catalog_editor")
|
@GetMapping("/catalog_editor")
|
||||||
public String catalog_configuration(Model model) {
|
public String catalog_configuration(Model model) {
|
||||||
model.addAttribute("inventory", inventory);
|
model.addAttribute("inventory", inventory);
|
||||||
model.addAttribute("formCatalogEntry", new CustomCatalogEntry(
|
model.addAttribute("formCatalogEntry", formCatalogEntry);
|
||||||
CustomCatalogEntry.EventType.EVENT_CATERING,
|
|
||||||
new HashMap<String, Integer>(),
|
|
||||||
0,
|
|
||||||
0));
|
|
||||||
return "catalog_editor";
|
return "catalog_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/catalog_editor/catalog_add")
|
@PostMapping("/catalog_editor/catalog_add")
|
||||||
public String catalog_add(Model model) {
|
public String catalog_add(@RequestParam CustomCatalogEntry.EventType eventType,
|
||||||
|
@RequestParam int minimumTimePeriod,
|
||||||
|
@RequestParam int totalCost,
|
||||||
|
Model model) {
|
||||||
|
Map<String, Integer> products = new HashMap<String, Integer>();
|
||||||
|
|
||||||
|
for (CustomProduct product : inventory) {
|
||||||
|
products.put(product.getName(), product.getAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Products looks like this:" + products);
|
||||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(
|
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(
|
||||||
// TODO: Fill with formCatalogEntry's data instead of dummy data
|
eventType,
|
||||||
CustomCatalogEntry.EventType.EVENT_CATERING,
|
products,
|
||||||
new HashMap<String, Integer>(),
|
minimumTimePeriod,
|
||||||
0,
|
totalCost));
|
||||||
0
|
this.formCatalogEntry = new CustomCatalogEntry(
|
||||||
));
|
CustomCatalogEntry.EventType.EVENT_CATERING,
|
||||||
|
new HashMap<String, Integer>(),
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
inventory.clear();
|
||||||
|
model.addAttribute("inventory", inventory);
|
||||||
|
model.addAttribute("formCatalogEntry", formCatalogEntry);
|
||||||
return "redirect:/catalog";
|
return "redirect:/catalog";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +75,7 @@ public class CatalogController {
|
||||||
@PostMapping("/catalog_editor/product_add")
|
@PostMapping("/catalog_editor/product_add")
|
||||||
public String product_add(@RequestParam String name, @RequestParam int amount, @RequestParam double cost) {
|
public String product_add(@RequestParam String name, @RequestParam int amount, @RequestParam double cost) {
|
||||||
inventory.add(new CustomProduct(name, amount, cost));
|
inventory.add(new CustomProduct(name, amount, cost));
|
||||||
|
formCatalogEntry.addProduct(name, amount);
|
||||||
return "redirect:/catalog_editor";
|
return "redirect:/catalog_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,11 +94,35 @@ public class CatalogController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/catalog_editor/add_time")
|
@PostMapping("/catalog_editor/add_time")
|
||||||
public String add_time(@RequestParam int minimumTimePeriod, @ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) {
|
public String add_time(@RequestParam int minimumTimePeriod,
|
||||||
System.out.println(minimumTimePeriod);
|
@RequestParam CustomCatalogEntry.EventType eventType,
|
||||||
/*System.out.println(formCatalogEntry.getMinimumTimePeriod());
|
@RequestParam Map<String, Integer> products,
|
||||||
model.addAttribute("formCatalogEntry", formCatalogEntry);*/
|
Model model) {
|
||||||
// TODO: Might not work because on every GetMapping of /catalog_editor a new formCatalogEntry is created
|
formCatalogEntry.setMinimumTimePeriod(minimumTimePeriod);
|
||||||
|
model.addAttribute("formCatalogEntry", formCatalogEntry);
|
||||||
|
return "redirect:/catalog_editor";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/catalog_editor/chooseEvent")
|
||||||
|
public String chooseEvent(String events) {
|
||||||
|
switch (events) {
|
||||||
|
case "event_catering":
|
||||||
|
formCatalogEntry.setEventType(CustomCatalogEntry.EventType.EVENT_CATERING);
|
||||||
|
break;
|
||||||
|
case "party_service":
|
||||||
|
formCatalogEntry.setEventType(CustomCatalogEntry.EventType.PARTY_SERVICE);
|
||||||
|
break;
|
||||||
|
case "mobile_breakfast":
|
||||||
|
formCatalogEntry.setEventType(CustomCatalogEntry.EventType.MOBILE_BREAKFAST);
|
||||||
|
break;
|
||||||
|
case "rent_a_cook":
|
||||||
|
formCatalogEntry.setEventType(CustomCatalogEntry.EventType.RENT_A_COOK);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
formCatalogEntry.setEventType(CustomCatalogEntry.EventType.EVENT_CATERING);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return "redirect:/catalog_editor";
|
return "redirect:/catalog_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package catering.orderCatalog;
|
package catering.orderCatalog;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class CustomCatalogEntry {
|
public class CustomCatalogEntry {
|
||||||
|
@ -36,14 +35,18 @@ public class CustomCatalogEntry {
|
||||||
return minimumTimePeriod;
|
return minimumTimePeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTotalCost() {
|
public int getTotalCost() {
|
||||||
return totalCost + " €";
|
return totalCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEventType(EventType eventType) {
|
public void setEventType(EventType eventType) {
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addProduct(String name, Integer count) {
|
||||||
|
this.products.put(name, count);
|
||||||
|
}
|
||||||
|
|
||||||
public void setProducts(Map<String, Integer> products) {
|
public void setProducts(Map<String, Integer> products) {
|
||||||
this.products = products;
|
this.products = products;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h1>Katalog</h1>
|
<h1>Katalog</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
@ -33,7 +33,6 @@
|
||||||
<td>
|
<td>
|
||||||
**BILD**
|
**BILD**
|
||||||
</td>
|
</td>
|
||||||
<td th:text="${catalogEntry.getId()}">
|
|
||||||
<td th:text="${catalogEntry.getEventType()}">
|
<td th:text="${catalogEntry.getEventType()}">
|
||||||
<td th:text="${catalogEntry.getMinimumTimePeriod()}">h
|
<td th:text="${catalogEntry.getMinimumTimePeriod()}">h
|
||||||
<td>
|
<td>
|
||||||
|
@ -70,6 +69,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>
|
||||||
|
|
|
@ -18,27 +18,28 @@
|
||||||
<h1>Basisevent konfigurieren</h1>
|
<h1>Basisevent konfigurieren</h1>
|
||||||
<input type="hidden" name="addCatalog">
|
<input type="hidden" name="addCatalog">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h2>Dienstleistung</h2>
|
<h2>Dienstleistung</h2>
|
||||||
<label for="dienstleistungen"></label>
|
<label for="events"></label>
|
||||||
<select name="dienstleistungen" id="dienstleistungen">
|
<form th:object="${formCatalogEntry}" method="post" th:action="@{/catalog_editor/chooseEvent}">
|
||||||
<option value="eventcatering">Eventcatering</option>
|
<select name="events" id="events">
|
||||||
<option value="partyservice">Partyservice</option>
|
<option value="event_catering">Eventcatering</option>
|
||||||
<option value="mobile_breakfast">Mobile Breakfast</option>
|
<option value="party_service">Partyservice</option>
|
||||||
<option value="rent-a-cook">Rent-a-Cook</option>
|
<option value="mobile_breakfast">Mobile Breakfast</option>
|
||||||
</select>
|
<option value="rent_a_cook">Rent-a-Cook</option>
|
||||||
|
</select>
|
||||||
|
<button type="submit">Event auswählen</button>
|
||||||
|
</form>
|
||||||
Eventbasispreis: 500€
|
Eventbasispreis: 500€
|
||||||
|
|
||||||
<h2>Mindestzeitraum</h2>
|
<h2>Mindestzeitraum</h2>
|
||||||
<form th:object="${formCatalogEntry}" method="post" th:action="@{/catalog_editor/add_time}">
|
<form th:object="${formCatalogEntry}" method="post" th:action="@{/catalog_editor/add_time}">
|
||||||
<label>Mindestzeitraum:</label>
|
<label>Mindestzeitraum:</label>
|
||||||
|
<input type="hidden" th:field="*{eventType}">
|
||||||
<input th:field="*{minimumTimePeriod}" type="number" min="0" step="1" value="1"/>
|
<input th:field="*{minimumTimePeriod}" type="number" min="0" step="1" value="1"/>
|
||||||
<button type="submit">Zum Model hinzufügen</button>
|
<button type="submit">Zum Model hinzufügen</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<span th:text="${formCatalogEntry.minimumTimePeriod}"></span>
|
<h2>Basisausstattung</h2>
|
||||||
<span th:text="${formCatalogEntry}"></span>
|
|
||||||
|
|
||||||
<h2>Basisausstattung</h2>
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Produktname</th>
|
<th>Produktname</th>
|
||||||
|
@ -56,7 +57,7 @@
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</table>
|
</table>
|
||||||
<hr>
|
<hr>
|
||||||
<div style="height: 20px;"></div>
|
<div style="height: 20px;"></div>
|
||||||
<form method="post" th:action="@{/catalog_editor/product_add}">
|
<form method="post" th:action="@{/catalog_editor/product_add}">
|
||||||
<label for="name">Produktname</label>
|
<label for="name">Produktname</label>
|
||||||
|
@ -65,10 +66,17 @@
|
||||||
<input type="number" id="amount" name="amount" min="1" required>
|
<input type="number" id="amount" name="amount" min="1" required>
|
||||||
<input type="hidden" name="cost" value="50.0">
|
<input type="hidden" name="cost" value="50.0">
|
||||||
<button type="submit">Artikel hinzufügen</button>
|
<button type="submit">Artikel hinzufügen</button>
|
||||||
</form>
|
</form>hinzufügen
|
||||||
<br>
|
<br>
|
||||||
Gesamtpreis: 90 €<br>
|
<h3>Momentane Auswahl</h3>
|
||||||
|
Eventtyp: <span th:text="${formCatalogEntry.getEventType()}"></span><br>
|
||||||
|
Mindestzeitraum: <span th:text="${formCatalogEntry.getMinimumTimePeriod()}"></span><br>
|
||||||
|
<span>Gesamtpreis: 90 €</span>
|
||||||
<form method="post" th:action="@{/catalog_editor/catalog_add}" th:object="${formCatalogEntry}">
|
<form method="post" th:action="@{/catalog_editor/catalog_add}" th:object="${formCatalogEntry}">
|
||||||
|
<input type="hidden" name="eventType" th:value="${formCatalogEntry.getEventType()}">
|
||||||
|
<input type="hidden" name="products" th:value="${inventory}">
|
||||||
|
<input type="hidden" name="minimumTimePeriod" th:value="${formCatalogEntry.getMinimumTimePeriod}">
|
||||||
|
<input type="hidden" name="totalCost" th:value="${formCatalogEntry.getTotalCost()}">
|
||||||
<button type="submit">Zum Katalog hinzufügen</button>
|
<button type="submit">Zum Katalog hinzufügen</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue