This repository has been archived on 2020-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
e-commerce/web_backend/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOfferController.java

78 lines
2.3 KiB
Java
Raw Normal View History

2020-04-29 22:44:16 +02:00
package org.hso.ecommerce.controller.intern.suppliers;
2020-04-28 22:41:29 +02:00
import java.util.ArrayList;
import java.util.List;
2020-05-19 16:30:27 +02:00
import java.util.Optional;
import org.hso.ecommerce.entities.supplier.ArticleOffer;
2020-05-19 16:30:27 +02:00
import org.hso.ecommerce.repos.shop.ArticleRepository;
import org.hso.ecommerce.repos.shop.OffersRepository;
import org.springframework.beans.factory.annotation.Autowired;
2020-04-28 22:41:29 +02:00
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
2020-04-28 22:41:29 +02:00
@Controller
2020-05-15 14:14:29 +02:00
@RequestMapping("/intern/")
2020-05-01 10:48:12 +02:00
public class SupplierOfferController {
2020-05-15 14:14:29 +02:00
@Autowired
private final OffersRepository offersRepository = null;
2020-05-19 16:30:27 +02:00
@Autowired
private final ArticleRepository articleRepository = null;
2020-05-15 20:57:56 +02:00
@GetMapping("supplierOffers")
public String internListedArticles(Model model) {
2020-05-15 14:14:29 +02:00
2020-06-01 17:10:04 +02:00
List<UImodelOfferedArticle> totals = new ArrayList<>();
for (ArticleOffer article : offersRepository.findAll()) {
UImodelOfferedArticle tmp = new UImodelOfferedArticle(article,
articleRepository.findArticleIDByRelatedID(article.id));
totals.add(tmp);
}
model.addAttribute("OfferedArticles", totals);
return "intern/offeredArticles/index";
}
public class UImodelOfferedArticle {
2020-06-05 18:05:10 +02:00
public long offerId;
public String title;
public String manufacturer;
public String articleNumber;
public String supplierName;
public String price;
public String ads;
public int listedArticleId;
public boolean offerIsListed; // true --> offered article is listed
public UImodelOfferedArticle(ArticleOffer article, Optional<Integer> listedArticleId) {
2020-06-05 18:05:10 +02:00
this.offerId = article.id;
this.title = article.title;
this.manufacturer = article.manufacturer;
2020-06-05 18:05:10 +02:00
this.articleNumber = article.articleNumber;
if (article.cheapestSupplier != null) {
this.supplierName = article.cheapestSupplier.name;
} else {
this.supplierName = "-";
}
this.price = String.format("%.2f", ((float) article.pricePerUnitNet / 100));
2020-05-19 16:30:27 +02:00
this.ads = (article.shouldBeAdvertised) ? "Ja" : "Nein";
2020-05-15 14:14:29 +02:00
2020-05-19 16:30:27 +02:00
if (listedArticleId.isPresent()) {
// this offer is listed --> show link
this.listedArticleId = listedArticleId.get();
offerIsListed = true;
} else {
// this offer is not listed
offerIsListed = false;
}
}
}
2020-04-28 22:41:29 +02:00
}