From e9e072b26b4b3d2b746704d18e489a2e604aa21f Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 1 May 2020 14:40:43 +0200 Subject: [PATCH] ShopIndexController without databasestuff --- .../controller/shop/ShopIndexController.java | 31 ++++++++++++++++--- .../main/resources/templates/shop/index.html | 26 ++++++++++++++-- 2 files changed, 50 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 5d442d6..0be1a50 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 @@ -6,6 +6,7 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import javax.servlet.http.HttpSession; import javax.swing.*; import java.awt.*; import java.util.ArrayList; @@ -20,11 +21,32 @@ public class ShopIndexController { } @GetMapping("/shop/") - public String shop(Model model) { + public String shop(Model model, HttpSession session) { - ArrayList
dummyArticles = getArticles(); + //TODO: get commercialised Articles + ArrayList
commercialArticles = getArticles(); + model.addAttribute("commercialArticles", commercialArticles); + + //check if logged in + boolean isLoggedIn = false; + boolean hasOrders = false; + if (session != null && session.getAttribute("id") != null) { + long userId = (long) session.getAttribute("id"); + isLoggedIn = true; + if (false) { + hasOrders = true; //TODO: Find out whether user has orders! + } + } + model.addAttribute("isLoggedIn", isLoggedIn); + model.addAttribute("hasOrders", hasOrders); + + + if (hasOrders) { + //TODO: get up to last 4 Orders + ArrayList
suggestedArticles = getArticles(); + model.addAttribute("suggestedArticles", suggestedArticles); + } - model.addAttribute("articles", dummyArticles); return "shop/index"; } @@ -44,8 +66,7 @@ public class ShopIndexController { } - - public ArrayList
getArticles(){ + public ArrayList
getArticles() { ArrayList
dummyArticles = new ArrayList
(); Article d1 = new Article(); diff --git a/prototype/src/main/resources/templates/shop/index.html b/prototype/src/main/resources/templates/shop/index.html index a019c8a..c3c7535 100644 --- a/prototype/src/main/resources/templates/shop/index.html +++ b/prototype/src/main/resources/templates/shop/index.html @@ -18,7 +18,7 @@