implement only show advertisements which are in stock
This commit is contained in:
parent
6b9db3eed5
commit
8d6a1f4053
|
@ -2,7 +2,9 @@ package org.hso.ecommerce.controller.shop;
|
||||||
|
|
||||||
import org.hso.ecommerce.action.shop.GetRandomArticlesAction;
|
import org.hso.ecommerce.action.shop.GetRandomArticlesAction;
|
||||||
import org.hso.ecommerce.entities.shop.Article;
|
import org.hso.ecommerce.entities.shop.Article;
|
||||||
|
import org.hso.ecommerce.entities.warehouse.WarehouseBookingPositionSlotEntry;
|
||||||
import org.hso.ecommerce.repos.shop.ArticleRepository;
|
import org.hso.ecommerce.repos.shop.ArticleRepository;
|
||||||
|
import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
|
@ -10,6 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@ -19,6 +22,9 @@ public class ShopIndexController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private final ArticleRepository articleRepository = null;
|
private final ArticleRepository articleRepository = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final WarehouseBookingPositionSlotEntryRepository warehouseBookingPositionSlotEntryRepository = null;
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public String home() {
|
public String home() {
|
||||||
return "redirect:/shop/";
|
return "redirect:/shop/";
|
||||||
|
@ -27,7 +33,14 @@ public class ShopIndexController {
|
||||||
@GetMapping("/shop/")
|
@GetMapping("/shop/")
|
||||||
public String shop(Model model, HttpSession session) {
|
public String shop(Model model, HttpSession session) {
|
||||||
|
|
||||||
List<Article> commercialArticles = GetRandomArticlesAction.getRandomArticles(8, articleRepository.getAdvertisedArticles());
|
List<Article> commercialArticlesBefore = GetRandomArticlesAction.getRandomArticles(8, articleRepository.getAdvertisedArticles());
|
||||||
|
List<Article> commercialArticles = new ArrayList<Article>();
|
||||||
|
for (int i = 0; i < commercialArticlesBefore.size(); i++) { //check for stockamount
|
||||||
|
Article article = commercialArticlesBefore.get(i);
|
||||||
|
if (warehouseBookingPositionSlotEntryRepository.getByArticle(article.id).get(0).newSumSlot != 0) {
|
||||||
|
commercialArticles.add(article);
|
||||||
|
}
|
||||||
|
}
|
||||||
model.addAttribute("commercialArticles", commercialArticles);
|
model.addAttribute("commercialArticles", commercialArticles);
|
||||||
|
|
||||||
boolean isLoggedIn = false;
|
boolean isLoggedIn = false;
|
||||||
|
|
Reference in New Issue