package org.hso.ecommerce.controller.intern.suppliers; import java.util.ArrayList; import java.util.List; import org.hso.ecommerce.entities.supplier.ArticleOffer; import org.hso.ecommerce.repos.shop.CategoryRepository; import org.hso.ecommerce.repos.shop.OffersRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller @RequestMapping("/intern/") public class SupplierOfferController { @Autowired private final OffersRepository offersRepository = null; @GetMapping("supplierOffers") public String internListedArticles(Model model) { List totals = new ArrayList(); for (ArticleOffer article : offersRepository.findAll()) { UImodelOfferedArticle tmp = new UImodelOfferedArticle(); tmp.addData(article,"supplierName01", 4884, 5); totals.add(tmp); } model.addAttribute("OfferedArticles", totals); return "intern/offeredArticles/index"; } public class UImodelOfferedArticle { String title; String manufacturer; String articlenumber; String supplierName; int supplierId; String price; String ads; int listedArticleId; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getManufacturer() { return manufacturer; } public void setManufacturer(String manufacturer) { this.manufacturer = manufacturer; } public String getArticlenumber() { return articlenumber; } public void setArticlenumber(String articlenumber) { this.articlenumber = articlenumber; } public String getSupplierName() { return supplierName; } public void setSupplierName(String supplierName) { this.supplierName = supplierName; } public int getSupplierId() { return supplierId; } public void setSupplierId(int supplierId) { this.supplierId = supplierId; } public String getPrice() { return price; } public void setPrice(String price) { this.price = price; } public String getAds() { return ads; } public void setAds(String ads) { this.ads = ads; } public int getListedArticleId() { return listedArticleId; } public void setListedArticleId(int listedArticleId) { this.listedArticleId = listedArticleId; } public void addData(ArticleOffer article, String supplierName, int supplierId, int listedArticleId) { this.title = article.title; this.manufacturer = article.manufacturer; this.articlenumber = article.articleNumber; this.supplierName = supplierName; this.supplierId = supplierId; this.price = String.format("%.2f", ((float) article.pricePerUnitNet / 100)); this.ads = (article.shouldBeAdvertised) ? "Ja" : "Nein"; this.listedArticleId = listedArticleId; } } }