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 70e7b19..d7ee930 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 @@ -3,6 +3,9 @@ package org.hso.ecommerce.controller.intern; import java.util.ArrayList; import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.hso.ecommerce.entities.shop.Article; import org.hso.ecommerce.repos.shop.ArticleRepository; import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository; @@ -40,30 +43,52 @@ public class InternArticleController { public String internListedArticlesId(Model model, @PathVariable String id) { int articleid = Integer.parseInt(id); - + ListedArticlesListIdTotal total = new ListedArticlesListIdTotal(); + + + total.addArticle(articleRepository.findArticleById(articleid), warehouseEntryRepository.getArticleStock(articleid).orElse(0)); + + // System.out.println("GETshouldReorder: " + articleRepository.findArticleById(articleid).shouldReorder); + model.addAttribute("ArticleID", total); return "intern/listedArticles/id"; } - - - @PostMapping("/{id}/saveChanges") - public RedirectView saveChanges() { - - System.out.println("\n------ POST -----\n"); - - - + @PostMapping("/{id}/saveChanges") + public RedirectView saveChanges(@ModelAttribute ListedArticlesListIdTotal changedArticleTotal) { + + 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 + + articleRepository.save(oldArticle); // save updated article return new RedirectView("../"); - } - + } public static class ListedArticlesListTotals { @@ -97,6 +122,102 @@ public class InternArticleController { public static class ListedArticlesListIdTotal { + public String getImgPath() { + return imgPath; + } + + public void setImgPath(String imgPath) { + this.imgPath = imgPath; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + + public String getPrice_netto() { + return price_netto; + } + + public void setPrice_netto(String price_netto) { + this.price_netto = price_netto; + } + + public int getReorderMaxPrice() { + return reorderMaxPrice; + } + + public void setReorderMaxPrice(int reorderMaxPrice) { + this.reorderMaxPrice = reorderMaxPrice; + } + + public String getCategorie() { + return categorie; + } + + public void setCategorie(String categorie) { + this.categorie = categorie; + } + + public int getStock() { + return stock; + } + + public void setStock(int stock) { + this.stock = stock; + } + + public long getOffer_id() { + return offer_id; + } + + public void setOffer_id(long offer_id) { + this.offer_id = offer_id; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public boolean isShouldReorder() { + return shouldReorder; + } + + public void setShouldReorder(boolean shouldReorder) { + this.shouldReorder = shouldReorder; + } + + public String getWarehouseUnitsPerSlot() { + return warehouseUnitsPerSlot; + } + + public void setWarehouseUnitsPerSlot(String warehouseUnitsPerSlot) { + this.warehouseUnitsPerSlot = warehouseUnitsPerSlot; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + public String imgPath; public String title; public String price; @@ -107,7 +228,7 @@ public class InternArticleController { public long offer_id; public long id; public boolean shouldReorder; - public int warehouseUnitsPerSlot; + public String warehouseUnitsPerSlot; public String description; void addArticle(Article article, int stock) { @@ -121,7 +242,7 @@ public class InternArticleController { this.id = article.id; this.reorderMaxPrice = article.reorderMaxPrice; this.shouldReorder = article.shouldReorder; - this.warehouseUnitsPerSlot = article.warehouseUnitsPerSlot; + this.warehouseUnitsPerSlot = String.valueOf(article.warehouseUnitsPerSlot); this.description = article.description; } } diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java index 93803cc..47f1d7c 100644 --- a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java +++ b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java @@ -9,8 +9,7 @@ import org.springframework.stereotype.Repository; import java.util.List; @Repository -public interface ArticleRepository extends JpaRepository -{ +public interface ArticleRepository extends JpaRepository { @Query("SELECT a FROM Article a WHERE a.id = :articleId") Article findArticleById(@Param("articleId") long articleId); diff --git a/prototype/src/main/resources/templates/intern/listedArticles/id.html b/prototype/src/main/resources/templates/intern/listedArticles/id.html index b694325..5bb62e6 100644 --- a/prototype/src/main/resources/templates/intern/listedArticles/id.html +++ b/prototype/src/main/resources/templates/intern/listedArticles/id.html @@ -25,7 +25,11 @@

Gelisteter Artikel ID

-
+ + + + +

@@ -33,7 +37,7 @@

- Details + Details

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

- +

Lagerbestand: