From a62e3e8a63ca3809f093e1b813ab8a7ef43a468d Mon Sep 17 00:00:00 2001 From: Hannes Date: Sun, 10 May 2020 15:28:39 +0200 Subject: [PATCH] fix only show ordered Articles from specific Customer --- .../hso/ecommerce/controller/shop/ShopIndexController.java | 7 +++---- .../org/hso/ecommerce/repos/shop/ArticleRepository.java | 4 ++-- prototype/src/main/resources/templates/shop/index.html | 5 ++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopIndexController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopIndexController.java index 9d1e47a..4897445 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopIndexController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopIndexController.java @@ -34,14 +34,13 @@ public class ShopIndexController { boolean isLoggedIn = false; boolean hasOrders = false; + if (session != null && session.getAttribute("userId") != null) { long userId = (long) session.getAttribute("userId"); isLoggedIn = true; - } - if (isLoggedIn) { - List
suggestedArticles = articleRepository.getOrderedArticles(); - suggestedArticles = suggestedArticles.size() > 3 ? suggestedArticles.subList(0,4) : suggestedArticles; //only latest 4 articles + List
suggestedArticles = articleRepository.getOrderedArticles(userId); + suggestedArticles = suggestedArticles.size() > 3 ? suggestedArticles.subList(0, 4) : suggestedArticles; //only latest 4 articles if (suggestedArticles.size() > 0) { model.addAttribute("suggestedArticles", suggestedArticles); hasOrders = true; 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 90b6d11..0b108f1 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 @@ -19,8 +19,8 @@ public interface ArticleRepository extends JpaRepository { List
getAdvertisedArticles(); - @Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a ORDER BY co.id DESC") - List
getOrderedArticles(); + @Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a WHERE c.id = :customerId ORDER BY co.id DESC") + List
getOrderedArticles(long customerId); } diff --git a/prototype/src/main/resources/templates/shop/index.html b/prototype/src/main/resources/templates/shop/index.html index 300471a..54985ad 100644 --- a/prototype/src/main/resources/templates/shop/index.html +++ b/prototype/src/main/resources/templates/shop/index.html @@ -17,7 +17,10 @@

Angebote

-
+
+

Momentan gibt es keine Angebote

+
+