From f67a23bab9c67a88de76114c83700c745af5375c Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 1 May 2020 12:19:52 +0200 Subject: [PATCH 1/2] ShopIndexController initial implementation --- .../hso/ecommerce/app/RequestController.java | 46 +++++------ .../controller/shop/ShopIndexController.java | 77 ++++++++++++++++++- .../main/resources/templates/shop/index.html | 53 ++----------- 3 files changed, 105 insertions(+), 71 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java b/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java index 3602236..defeb1c 100644 --- a/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java +++ b/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java @@ -22,10 +22,10 @@ public class RequestController { static int notSoRandom = 0; - @GetMapping("/") - public String home() { - return "redirect:/shop/"; - } +// @GetMapping("/") +// public String home() { +// return "redirect:/shop/"; +// } @GetMapping("/login") public String login() { @@ -43,7 +43,7 @@ public class RequestController { String gto = (String) session.getAttribute("afterLogin"); Optional user = userRepository.findByEmail(username); - if (user.isEmpty()) { + if (!user.isPresent()) { request.setAttribute("error", "Email Adresse falsch."); response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); return "login"; @@ -88,10 +88,10 @@ public class RequestController { return "redirect:/"; } - @GetMapping("/shop/") - public String shop() { - return "shop/index"; - } +// @GetMapping("/shop/") +// public String shop() { +// return "shop/index"; +// } @GetMapping("/shop/search") public String shopSearch() { @@ -137,20 +137,20 @@ public class RequestController { } } - @GetMapping("/about") - public String about() { - return "about"; - } - - @GetMapping("/terms") - public String terms() { - return "terms"; - } - - @GetMapping("/privacy") - public String privacy() { - return "privacy"; - } +// @GetMapping("/about") +// public String about() { +// return "about"; +// } +// +// @GetMapping("/terms") +// public String terms() { +// return "terms"; +// } +// +// @GetMapping("/privacy") +// public String privacy() { +// return "privacy"; +// } @GetMapping("/intern/") 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 0f423db..5d442d6 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 @@ -1,8 +1,83 @@ package org.hso.ecommerce.controller.shop; +import org.hso.ecommerce.entities.shop.Article; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; @Controller -//@RequestMapping("...") +@RequestMapping("/") public class ShopIndexController { + + @GetMapping("/") + public String home() { + return "redirect:/shop/"; + } + + @GetMapping("/shop/") + public String shop(Model model) { + + ArrayList
dummyArticles = getArticles(); + + model.addAttribute("articles", dummyArticles); + return "shop/index"; + } + + @GetMapping("/about") + public String about() { + return "about"; + } + + @GetMapping("/terms") + public String terms() { + return "terms"; + } + + @GetMapping("/privacy") + public String privacy() { + return "privacy"; + } + + + + public ArrayList
getArticles(){ + ArrayList
dummyArticles = new ArrayList
(); + + Article d1 = new Article(); + d1.description = "this is dummy1"; + d1.title = "dummy1"; + d1.shopPricePerUnitNetCent = 1500; + d1.id = 1234; + dummyArticles.add(d1); + + Article d2 = new Article(); + d2.description = "this is dummy2"; + d2.title = "dummy2"; + d2.shopPricePerUnitNetCent = 2000; + d2.id = 2345; + dummyArticles.add(d2); + + Article d3 = new Article(); + d3.description = "this is dummy3"; + d3.title = "dummy3"; + d3.shopPricePerUnitNetCent = 2500; + d3.id = 3456; + dummyArticles.add(d3); + + Article d4 = new Article(); + d4.description = "this is dummy4"; + d4.title = "dummy4"; + d4.shopPricePerUnitNetCent = 3000; + d4.id = 4567; + dummyArticles.add(d4); + + return dummyArticles; + } + + } diff --git a/prototype/src/main/resources/templates/shop/index.html b/prototype/src/main/resources/templates/shop/index.html index 68a4a1f..a019c8a 100644 --- a/prototype/src/main/resources/templates/shop/index.html +++ b/prototype/src/main/resources/templates/shop/index.html @@ -18,54 +18,13 @@
-
+
+ - -

Lorem Ipsum

-

25.14 EUR

-

- Als Gregor Samsa eines Morgens aus unruhigen Träumen erwachte. -

-
-
-
- - -

Lorem Ipsum

-

10.14 EUR

-

- Als Gregor Samsa eines Morgens aus unruhigen Träumen erwachte. -

-
-
-
- - -

Lorem Ipsum

-

25.14 EUR

-

- Als Gregor Samsa eines Morgens aus unruhigen Träumen erwachte. -

-
-
-
- - -

Lorem Ipsum

-

10.14 EUR

-

- Als Gregor Samsa eines Morgens aus unruhigen Träumen erwachte. -

-
-
-
- - -

Lorem Ipsum

-

44.14 EUR

-

- Als Gregor Samsa eines Morgens aus unruhigen Träumen erwachte. -

+ +

+

+

From 8f081823ca24b5f97ee4ca4d86ef80c0af29b38a Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 1 May 2020 14:40:43 +0200 Subject: [PATCH 2/2] 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 @@