mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add inventory based product selection
This commit is contained in:
parent
ddf4d7f645
commit
eab8e3fee0
|
@ -2,22 +2,28 @@ package catering.orderCatalog;
|
||||||
|
|
||||||
import catering.order.OrderType;
|
import catering.order.OrderType;
|
||||||
import org.salespointframework.catalog.Product;
|
import org.salespointframework.catalog.Product;
|
||||||
|
import org.salespointframework.inventory.UniqueInventory;
|
||||||
|
import org.salespointframework.inventory.UniqueInventoryItem;
|
||||||
|
import org.salespointframework.quantity.Quantity;
|
||||||
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;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import javax.money.Monetary;
|
||||||
import javax.money.MonetaryAmount;
|
import javax.money.MonetaryAmount;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class CatalogController {
|
public class CatalogController {
|
||||||
private final CustomCatalogEntryRepository catalogEntryRepository;
|
private final CustomCatalogEntryRepository catalogEntryRepository;
|
||||||
private Set<Product> productSet;
|
private Set<Product> productSet;
|
||||||
private CustomCatalogEntry formCatalogEntry;
|
private CustomCatalogEntry formCatalogEntry;
|
||||||
|
private final UniqueInventory<UniqueInventoryItem> inventory;
|
||||||
|
|
||||||
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) {
|
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository, UniqueInventory<UniqueInventoryItem> inventory) {
|
||||||
productSet = new HashSet<>();
|
productSet = new HashSet<>();
|
||||||
formCatalogEntry = new CustomCatalogEntry(
|
formCatalogEntry = new CustomCatalogEntry(
|
||||||
OrderType.EVENT_CATERING,
|
OrderType.EVENT_CATERING,
|
||||||
|
@ -25,6 +31,7 @@ public class CatalogController {
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
this.catalogEntryRepository = catalogEntryRepository;
|
this.catalogEntryRepository = catalogEntryRepository;
|
||||||
|
this.inventory = inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/catalog")
|
@GetMapping("/catalog")
|
||||||
|
@ -34,14 +41,15 @@ public class CatalogController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/catalog_editor")
|
@GetMapping("/catalog_editor")
|
||||||
public String catalog_configuration(Model model) {
|
public String editCatalog(Model model) {
|
||||||
model.addAttribute("inventory", productSet);
|
model.addAttribute("productSet", productSet);
|
||||||
model.addAttribute("formCatalogEntry", formCatalogEntry);
|
model.addAttribute("formCatalogEntry", formCatalogEntry);
|
||||||
|
model.addAttribute("inventory", inventory.findAll().stream().collect(Collectors.toList()));
|
||||||
return "catalog_editor";
|
return "catalog_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/catalog_editor/catalog_add")
|
@PostMapping("/catalog_editor/addCatalogEntry")
|
||||||
public String catalog_add(@RequestParam OrderType eventType,
|
public String addCatalogEntry(@RequestParam OrderType eventType,
|
||||||
@RequestParam int minimumTimePeriod,
|
@RequestParam int minimumTimePeriod,
|
||||||
@RequestParam int totalCost,
|
@RequestParam int totalCost,
|
||||||
Model model) {
|
Model model) {
|
||||||
|
@ -63,7 +71,7 @@ public class CatalogController {
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
productSet.clear();
|
productSet.clear();
|
||||||
model.addAttribute("inventory", productSet);
|
model.addAttribute("productSet", productSet);
|
||||||
model.addAttribute("formCatalogEntry", formCatalogEntry);
|
model.addAttribute("formCatalogEntry", formCatalogEntry);
|
||||||
return "redirect:/catalog";
|
return "redirect:/catalog";
|
||||||
}
|
}
|
||||||
|
@ -77,10 +85,13 @@ public class CatalogController {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@PostMapping("/catalog_editor/product_add")
|
@PostMapping("/catalog_editor/addProduct")
|
||||||
public String product_add(@RequestParam String name, @RequestParam int amount, @RequestParam MonetaryAmount price) {
|
public String addProduct(@RequestParam("pid") Product product, @RequestParam("number") int number) {
|
||||||
productSet.add(new Product(name, price));
|
// TODO: This has to get a price
|
||||||
formCatalogEntry.addProduct(name, amount);
|
Quantity amount = Quantity.of(number);
|
||||||
|
productSet.add(new Product(product.getName(), product.getPrice()));
|
||||||
|
// TODO: formCatalogEntry.addProduct has to use Quantity amount instead of int number
|
||||||
|
formCatalogEntry.addProduct(product.getName(), number);
|
||||||
return "redirect:/catalog_editor";
|
return "redirect:/catalog_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,14 +99,14 @@ public class CatalogController {
|
||||||
/* TODO: reimplement this function based on Product
|
/* TODO: reimplement this function based on Product
|
||||||
@PostMapping("/catalog_editor/remove_product")
|
@PostMapping("/catalog_editor/remove_product")
|
||||||
public String removeProduct(@RequestParam String id, Model model) {
|
public String removeProduct(@RequestParam String id, Model model) {
|
||||||
Iterator<Product> iterator = inventory.iterator();
|
Iterator<Product> iterator = productSet.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Product currentProduct = iterator.next();
|
Product currentProduct = iterator.next();
|
||||||
|
|
||||||
// TODO: Have a look at salespointframework.catalog.Product.ProductIdentifier, maybe use inventory.remove()
|
// TODO: Have a look at salespointframework.catalog.Product.ProductIdentifier, maybe use productSet.remove()
|
||||||
if (currentProduct.getId() == Integer.parseInt(id)) {
|
if (currentProduct.getId() == Integer.parseInt(id)) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
inventory.remove(currentProduct.getId());
|
productSet.remove(currentProduct.getId());
|
||||||
currentProduct.getId();
|
currentProduct.getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,8 +114,8 @@ public class CatalogController {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@PostMapping("/catalog_editor/add_time")
|
@PostMapping("/catalog_editor/addTime")
|
||||||
public String add_time(@RequestParam int minimumTimePeriod,
|
public String addTime(@RequestParam int minimumTimePeriod,
|
||||||
@RequestParam OrderType eventType,
|
@RequestParam OrderType eventType,
|
||||||
@RequestParam Map<String, Integer> products,
|
@RequestParam Map<String, Integer> products,
|
||||||
Model model) {
|
Model model) {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import jakarta.persistence.*;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
//@Table(name = "CatalogEntries")
|
|
||||||
public class CustomCatalogEntry {
|
public class CustomCatalogEntry {
|
||||||
static int idCounter = 0;
|
static int idCounter = 0;
|
||||||
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package catering.orderCatalog;
|
|
||||||
|
|
||||||
public class CustomProduct {
|
|
||||||
private static int itemIdCounter;
|
|
||||||
private int itemId;
|
|
||||||
private String name;
|
|
||||||
private int amount;
|
|
||||||
private double cost;
|
|
||||||
|
|
||||||
public CustomProduct(String name, int amount, double cost) {
|
|
||||||
this.itemId = itemIdCounter;
|
|
||||||
itemIdCounter++;
|
|
||||||
this.name = name;
|
|
||||||
this.amount = amount;
|
|
||||||
this.cost = cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAmount() {
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getCost() {
|
|
||||||
return cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getItemId() {
|
|
||||||
return itemId;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,13 +22,13 @@
|
||||||
**BILD**
|
**BILD**
|
||||||
</td>
|
</td>
|
||||||
<td th:text="${catalogEntry.getEventType()}">
|
<td th:text="${catalogEntry.getEventType()}">
|
||||||
<td th:text="${catalogEntry.getMinimumTimePeriod()}">
|
<td th:text="${catalogEntry.getMinimumTimePeriod()} + ' h'">
|
||||||
<td>
|
<td>
|
||||||
<ul th:each="product : ${catalogEntry.getProducts()}">
|
<ul th:each="product : ${catalogEntry.getProducts()}">
|
||||||
<li th:text="${product.getKey().toString()} + ': ' + ${product.getValue().toString()}"/>
|
<li th:text="${product.getKey().toString()} + ': ' + ${product.getValue().toString()}"/>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td th:text="${catalogEntry.getTotalCost()}">
|
<td th:text="${catalogEntry.getTotalCost()} + ' €'">
|
||||||
<td sec:authorize="hasRole('ADMIN')">
|
<td sec:authorize="hasRole('ADMIN')">
|
||||||
<form method="post" th:action="@{/catalog/remove}">
|
<form method="post" th:action="@{/catalog/remove}">
|
||||||
<input type="hidden" name="catalogEntryID" th:value="${catalogEntry.getId()}">
|
<input type="hidden" name="catalogEntryID" th:value="${catalogEntry.getId()}">
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
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/addTime}">
|
||||||
<label class="form-label">Mindestzeitraum:</label>
|
<label class="form-label">Mindestzeitraum:</label>
|
||||||
<input type="hidden" th:field="*{eventType}">
|
<input type="hidden" th:field="*{eventType}">
|
||||||
<input class="form-control w-auto d-inline-block" th:field="*{minimumTimePeriod}" type="number" min="0" step="1" value="1"/>
|
<input class="form-control w-auto d-inline-block" th:field="*{minimumTimePeriod}" type="number" min="0" step="1" value="1"/>
|
||||||
|
@ -36,34 +36,46 @@
|
||||||
<th>Menge</th>
|
<th>Menge</th>
|
||||||
<th>Stückpreis</th>
|
<th>Stückpreis</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr th:each="item : ${inventory}">
|
<tr th:each="item : ${productSet}">
|
||||||
<td th:text="${item.getName()}">
|
<td th:text="${item.getName()}">
|
||||||
<td th:text="${item.getAmount()}">
|
<td th:text="${item.getPrice()}">€
|
||||||
<td th:text="${item.getCost()}"> €
|
|
||||||
<td>
|
<td>
|
||||||
<form method="post" th:action="@{/catalog_editor/remove_product}">
|
<form method="post" th:action="@{/catalog_editor/remove_product}">
|
||||||
<input class="form-control w-auto d-inline-block" type="hidden" name="id" th:value="${item.getItemId()}">
|
<input class="form-control w-auto d-inline-block" type="hidden" name="id" th:value="${item.getId()}">
|
||||||
<button class="btn btn-danger" type="submit">Entfernen</button>
|
<button class="btn btn-danger" type="submit">Entfernen</button>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<form method="post" th:action="@{/catalog_editor/product_add}">
|
<h2>Produktauswahl</h2>
|
||||||
<label class="form-label" for="name">Produktname</label>
|
<table class="table">
|
||||||
<input class="form-control w-auto d-inline-block" type="text" id="name" name="name" required>
|
<tr>
|
||||||
<label class="form-label" for="amount">Menge</label>
|
<th>Produktname</th>
|
||||||
<input class="form-control w-auto d-inline-block" type="number" id="amount" name="amount" min="1" required>
|
<th>Kosten</th>
|
||||||
<input type="hidden" name="cost" value="50.0">
|
<th>Verfügbar</th>
|
||||||
<button class="btn btn-primary" type="submit">Artikel hinzufügen</button>
|
<th>Menge</th>
|
||||||
|
</tr>
|
||||||
|
<tr th:each="item : ${inventory}">
|
||||||
|
<td th:text="${item.getProduct().getName()}">Name</td>
|
||||||
|
<td th:text="${item.getProduct().getPrice()}">Preis</td>
|
||||||
|
<td th:text="${item.getQuantity()}">Verfügbar</td>
|
||||||
|
<td>
|
||||||
|
<form th:action="@{/catalog_editor/addProduct}" method="post">
|
||||||
|
<input id="number" type="number" name="number" min="1" value="1"/>
|
||||||
|
<input type="hidden" name="pid" th:value="${item.getProduct().getId()}"/>
|
||||||
|
<input class="btn btn-primary" type="submit" th:value="Hinzufügen"/>
|
||||||
</form>
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
<br>
|
<br>
|
||||||
<h3>Momentane Auswahl</h3>
|
<h3>Momentane Auswahl</h3>
|
||||||
Eventtyp: <span th:text="${formCatalogEntry.getEventType()}"></span><br>
|
Eventtyp: <span th:text="${formCatalogEntry.getEventType()}"></span><br>
|
||||||
Mindestzeitraum: <span th:text="${formCatalogEntry.getMinimumTimePeriod()}"></span><br>
|
Mindestzeitraum: <span th:text="${formCatalogEntry.getMinimumTimePeriod()} + ' h'"></span><br>
|
||||||
<span>Gesamtpreis: 90 €</span>
|
<span th:text="'Gesamtpreis: ' + ${formCatalogEntry.getTotalCost()} + ' €'">Gesamtpreis</span>
|
||||||
<form method="post" th:action="@{/catalog_editor/catalog_add}" th:object="${formCatalogEntry}">
|
<form method="post" th:action="@{/catalog_editor/addCatalogEntry}" th:object="${formCatalogEntry}">
|
||||||
<input type="hidden" name="eventType" th:value="${formCatalogEntry.getEventType()}">
|
<input type="hidden" name="eventType" th:value="${formCatalogEntry.getEventType()}">
|
||||||
<input type="hidden" name="products" th:value="${inventory}">
|
<input type="hidden" name="products" th:value="${productSet}">
|
||||||
<input type="hidden" name="minimumTimePeriod" th:value="${formCatalogEntry.getMinimumTimePeriod}">
|
<input type="hidden" name="minimumTimePeriod" th:value="${formCatalogEntry.getMinimumTimePeriod}">
|
||||||
<input type="hidden" name="totalCost" th:value="${formCatalogEntry.getTotalCost()}">
|
<input type="hidden" name="totalCost" th:value="${formCatalogEntry.getTotalCost()}">
|
||||||
<button class="btn btn-primary" type="submit">Zum Katalog hinzufügen</button>
|
<button class="btn btn-primary" type="submit">Zum Katalog hinzufügen</button>
|
||||||
|
|
Loading…
Reference in a new issue