diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java index d7ee930..f3c0d52 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java @@ -27,10 +27,10 @@ public class InternArticleController { @GetMapping("/") public String internListedArticles(Model model) { - List totals = new ArrayList(); + List totals = new ArrayList(); for (Article article : articleRepository.findAll()) { - ListedArticlesListTotals tmp = new ListedArticlesListTotals(); + UImodelArticles tmp = new UImodelArticles(); tmp.addListedArticle(article, warehouseEntryRepository.getArticleStock(article.id).orElse(0)); totals.add(tmp); } @@ -44,16 +44,10 @@ public class InternArticleController { int articleid = Integer.parseInt(id); - ListedArticlesListIdTotal total = new ListedArticlesListIdTotal(); - - - + UImodelArticle total = new UImodelArticle(); total.addArticle(articleRepository.findArticleById(articleid), warehouseEntryRepository.getArticleStock(articleid).orElse(0)); - - - // System.out.println("GETshouldReorder: " + articleRepository.findArticleById(articleid).shouldReorder); model.addAttribute("ArticleID", total); @@ -61,36 +55,42 @@ public class InternArticleController { } @PostMapping("/{id}/saveChanges") - public RedirectView saveChanges(@ModelAttribute ListedArticlesListIdTotal changedArticleTotal) { + public RedirectView saveChanges( + @ModelAttribute UImodelArticle changedArticleTotal, + @RequestParam("units-per-slot") String sWarehouseUnitsPerSlot, + @RequestParam("price_netto") String sPrice_netto, + @RequestParam("reorderMaxPrice") String sReorderMaxPrice, + @RequestParam("autobuy") String sShouldReorder, + @RequestParam("categories") String sCategories) { Article oldArticle = articleRepository.findArticleById(changedArticleTotal.id); - //TODO img - //TODO price - //TODO reorder price - //TODO categories - - - - // oldArticle.shopPricePerUnitNetCent = changedArticleTotal.price_netto; - // System.out.println("netto: " + changedArticleTotal.price_netto); - - //System.out.println("POSTshouldReorder: " + oldArticle.shouldReorder); - //oldArticle.shouldReorder = changedArticleTotal.shouldReorder; - - System.out.println("POSTwarehouseUnitsPerSlot: " + oldArticle.warehouseUnitsPerSlot); - - //oldArticle.warehouseUnitsPerSlot = Integer.parseInt(changedArticleTotal.warehouseUnitsPerSlot); - - - oldArticle.title = changedArticleTotal.title; //works - oldArticle.description = changedArticleTotal.description; //works + // TODO img + // TODO categories + /* + * String separatedCategories[] = sCategories.split("\\r?\\n"); + * + * + * for (int i = 0; i < separatedCategories.length; i++) { + * + * oldArticle.categories.add(separatedCategories[i]); + * + * } + */ + + oldArticle.shouldReorder = (sShouldReorder.equals("true")) ? true : false; + oldArticle.reorderMaxPrice = (int) (Float.parseFloat(sReorderMaxPrice) * 100); + oldArticle.shopPricePerUnitNetCent = (int) (Float.parseFloat(sPrice_netto) * 100); + oldArticle.warehouseUnitsPerSlot = Integer.parseInt(sWarehouseUnitsPerSlot); + oldArticle.title = changedArticleTotal.title; + oldArticle.description = changedArticleTotal.description; articleRepository.save(oldArticle); // save updated article - return new RedirectView("../"); + return new RedirectView("../"); //return to overview page } - public static class ListedArticlesListTotals { + + public static class UImodelArticles { public String imgPath; @@ -120,7 +120,7 @@ public class InternArticleController { } } - public static class ListedArticlesListIdTotal { + public static class UImodelArticle { public String getImgPath() { return imgPath; @@ -154,11 +154,11 @@ public class InternArticleController { this.price_netto = price_netto; } - public int getReorderMaxPrice() { + public String getReorderMaxPrice() { return reorderMaxPrice; } - public void setReorderMaxPrice(int reorderMaxPrice) { + public void setReorderMaxPrice(String reorderMaxPrice) { this.reorderMaxPrice = reorderMaxPrice; } @@ -222,7 +222,7 @@ public class InternArticleController { public String title; public String price; public String price_netto; - public int reorderMaxPrice; + public String reorderMaxPrice; public String categorie; public int stock; public long offer_id; @@ -240,7 +240,7 @@ public class InternArticleController { this.stock = stock; this.offer_id = article.related.id; this.id = article.id; - this.reorderMaxPrice = article.reorderMaxPrice; + this.reorderMaxPrice = String.format("%.2f", ((float) article.reorderMaxPrice / 100)); this.shouldReorder = article.shouldReorder; this.warehouseUnitsPerSlot = String.valueOf(article.warehouseUnitsPerSlot); this.description = article.description; diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/shop/Article.java b/prototype/src/main/java/org/hso/ecommerce/entities/shop/Article.java index ed351ea..98b8a15 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/shop/Article.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/shop/Article.java @@ -42,6 +42,7 @@ public class Article @JoinTable(name = "article_categories_bindings") public Set categories = new HashSet<>(); + // returns all categories as string public String getCategories() { StringBuilder result = new StringBuilder(); diff --git a/prototype/src/main/resources/templates/intern/listedArticles/id.html b/prototype/src/main/resources/templates/intern/listedArticles/id.html index 5bb62e6..4667d39 100644 --- a/prototype/src/main/resources/templates/intern/listedArticles/id.html +++ b/prototype/src/main/resources/templates/intern/listedArticles/id.html @@ -52,14 +52,14 @@

-  EUR
+  EUR
(19% Mwst.)
=  EUR Brutto

-  EUR +  EUR

@@ -76,7 +76,7 @@

Bitte jede Kategorien in eine eigene Zeile

-
@@ -84,7 +84,7 @@

- +

Lagerbestand: