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..48c4f18 100644 --- a/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java +++ b/prototype/src/main/java/org/hso/ecommerce/app/RequestController.java @@ -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"; @@ -114,28 +114,28 @@ public class RequestController { return "shop/checkoutFinish"; } - @GetMapping("/shop/articles/{id}") - public String shopArticlesById() { - return "shop/articles/id"; - } - - @PostMapping("/shop/articles/{id}") - public String shopArticlesByIdBuy(HttpSession session, - @RequestAttribute(value = "user", required = false) User customer, - @PathVariable("id") Integer id, - @RequestParam("fastcheckout") Boolean fastcheckout - ) { - if (customer != null) { - if (!fastcheckout) { - return "shop/articles/post_add"; - } else { - return "shop/checkout"; - } - } else { - session.setAttribute("afterLogin", "/shop/articles/" + id); - return "redirect:/login"; - } - } +// @GetMapping("/shop/articles/{id}") +// public String shopArticlesById() { +// return "shop/articles/id"; +// } +// +// @PostMapping("/shop/articles/{id}") +// public String shopArticlesByIdBuy(HttpSession session, +// @RequestAttribute(value = "user", required = false) User customer, +// @PathVariable("id") Integer id, +// @RequestParam("fastcheckout") Boolean fastcheckout +// ) { +// if (customer != null) { +// if (!fastcheckout) { +// return "shop/articles/post_add"; +// } else { +// return "shop/checkout"; +// } +// } else { +// session.setAttribute("afterLogin", "/shop/articles/" + id); +// return "redirect:/login"; +// } +// } @GetMapping("/about") public String about() { diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java index 27ccf63..653286e 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java @@ -1,8 +1,75 @@ package org.hso.ecommerce.controller.shop; +import org.hso.ecommerce.entities.shop.Article; +import org.hso.ecommerce.entities.user.User; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpSession; +import java.util.ArrayList; +import java.util.List; @Controller -//@RequestMapping("...") +@RequestMapping("/shop/articles") public class ShopArticleController { + + @GetMapping("/{id}") + public String shopArticlesById(Model model, @PathVariable("id") Integer Id) { + + //TODO: Get Article by Id instead of this dummy shit + Article d1 = new Article(); + d1.description = "this is dummy1"; + d1.title = "dummy1"; + d1.shopPricePerUnitNetCent = 1500; + d1.id = 1234; + + model.addAttribute("article", d1); + + //TODO: Check if in Stock + if(false){ + model.addAttribute("inStock", true); + }else{ + model.addAttribute("inStock", false); + } + + //TODO: Get 2 Commercialised Articles + List
commercialArticles = new ArrayList
(); + Article d2 = new Article(); + d2.description = "this is dummy2"; + d2.title = "dummy2"; + d2.shopPricePerUnitNetCent = 2000; + d2.id = 2345; + Article d3 = new Article(); + d3.description = "this is dummy3"; + d3.title = "dummy3"; + d3.shopPricePerUnitNetCent = 2500; + d3.id = 3456; + commercialArticles.add(d2); + commercialArticles.add(d3); + model.addAttribute("commercialArticles", commercialArticles); + + return "shop/articles/id"; + } + + @PostMapping("/{id}") + public String shopArticlesByIdBuy(HttpSession session, + @RequestAttribute(value = "user", required = false) User customer, +// @RequestAttribute(value = "shoppingCart", required = true) ShoppingCart shoppingCart, + @PathVariable("id") Integer id, + @RequestParam("fastcheckout") Boolean fastcheckout + ) { + if (customer != null) { + //TODO: Add Article to Shopping Cart + + if (!fastcheckout) { + return "shop/articles/post_add"; + } else { + return "shop/checkout"; + } + } else { + session.setAttribute("afterLogin", "/shop/articles/" + id); + return "redirect:/login"; + } + } } diff --git a/prototype/src/main/resources/templates/shop/articles/id.html b/prototype/src/main/resources/templates/shop/articles/id.html index c99ed1d..2a7df6d 100644 --- a/prototype/src/main/resources/templates/shop/articles/id.html +++ b/prototype/src/main/resources/templates/shop/articles/id.html @@ -19,17 +19,12 @@
-

Tolle Kamera

+

-

25.14 EUR

-

- Eine TOLLE Kamera
- Jaja du denkst jetzt bestimmt: "Bei dem Preis kann sie gar nich sooo TOLL sein".
- Aber glaub mir, sie is echt echt TOLL!
- Indianerehrenwort! -

+

+

@@ -37,14 +32,17 @@
-

50.28 EUR

+

+
-

Auf Lager

+

@@ -56,26 +54,13 @@