ShopArticleController initial

This commit is contained in:
Hannes Huber 2020-05-02 14:38:40 +02:00
parent 6ab3b63923
commit f48f5c40f0
3 changed files with 105 additions and 53 deletions

View File

@ -43,7 +43,7 @@ public class RequestController {
String gto = (String) session.getAttribute("afterLogin"); String gto = (String) session.getAttribute("afterLogin");
Optional<User> user = userRepository.findByEmail(username); Optional<User> user = userRepository.findByEmail(username);
if (user.isEmpty()) { if (!user.isPresent()) {
request.setAttribute("error", "Email Adresse falsch."); request.setAttribute("error", "Email Adresse falsch.");
response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
return "login"; return "login";
@ -114,28 +114,28 @@ public class RequestController {
return "shop/checkoutFinish"; return "shop/checkoutFinish";
} }
@GetMapping("/shop/articles/{id}") // @GetMapping("/shop/articles/{id}")
public String shopArticlesById() { // public String shopArticlesById() {
return "shop/articles/id"; // return "shop/articles/id";
} // }
//
@PostMapping("/shop/articles/{id}") // @PostMapping("/shop/articles/{id}")
public String shopArticlesByIdBuy(HttpSession session, // public String shopArticlesByIdBuy(HttpSession session,
@RequestAttribute(value = "user", required = false) User customer, // @RequestAttribute(value = "user", required = false) User customer,
@PathVariable("id") Integer id, // @PathVariable("id") Integer id,
@RequestParam("fastcheckout") Boolean fastcheckout // @RequestParam("fastcheckout") Boolean fastcheckout
) { // ) {
if (customer != null) { // if (customer != null) {
if (!fastcheckout) { // if (!fastcheckout) {
return "shop/articles/post_add"; // return "shop/articles/post_add";
} else { // } else {
return "shop/checkout"; // return "shop/checkout";
} // }
} else { // } else {
session.setAttribute("afterLogin", "/shop/articles/" + id); // session.setAttribute("afterLogin", "/shop/articles/" + id);
return "redirect:/login"; // return "redirect:/login";
} // }
} // }
@GetMapping("/about") @GetMapping("/about")
public String about() { public String about() {

View File

@ -1,8 +1,75 @@
package org.hso.ecommerce.controller.shop; 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.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 @Controller
//@RequestMapping("...") @RequestMapping("/shop/articles")
public class ShopArticleController { 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<Article> commercialArticles = new ArrayList<Article>();
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";
}
}
} }

View File

@ -19,17 +19,12 @@
<div class="detailgrid"> <div class="detailgrid">
<div class="s"> <div class="s">
<h1>Tolle Kamera</h1> <h1 th:text="${article.title}"></h1>
<script th:src="@{/js/back.js}"></script> <script th:src="@{/js/back.js}"></script>
<div class="back" data-group="shop" data-insert="true"></div> <div class="back" data-group="shop" data-insert="true"></div>
<h2>25.14&nbsp;EUR</h2> <h2 th:text="${article.shopPricePerUnitNetCent}"></h2>
<p> <p th:text="${article.description}"></p>
Eine TOLLE Kamera <br>
Jaja du denkst jetzt bestimmt: "Bei dem Preis kann sie gar nich sooo TOLL sein". <br>
Aber glaub mir, sie is echt echt TOLL! <br>
Indianerehrenwort!
</p>
</div> </div>
<div class="s"> <div class="s">
<img th:src="@{/img/product-1.jpg}"/> <img th:src="@{/img/product-1.jpg}"/>
@ -37,14 +32,17 @@
<div class="s"></div> <div class="s"></div>
<form class="s" method="POST"> <form class="s" method="POST">
<div class="detailgrid m"> <div class="detailgrid m">
<h2>50.28&nbsp;EUR</h2> <h2 th:text="${article.shopPricePerUnitNetCent}"></h2>
<div> <div>
<label class="nolinebreak">Menge:</label> <label class="nolinebreak">Menge:</label>
<select size="1"> <select size="1">
<option>2</option> <option th:each="quantity : ${#numbers.sequence(1,100)}"
th:value="${quantity}"
th:text="${quantity}"></option>
</select> </select>
</div> </div>
<h3 class="no-margin secondarytext">Auf Lager</h3> <h3 class="no-margin secondarytext" th:text="${inStock} ? 'AUF LAGER' : 'NICHT AUF LAGER'"></h3>
<button class="no-margin secondary" name="fastcheckout" value="false">In den Einkaufswagen <button class="no-margin secondary" name="fastcheckout" value="false">In den Einkaufswagen
</button> </button>
<button class="no-margin" name="fastcheckout" value="true">Schneller Checkout</button> <button class="no-margin" name="fastcheckout" value="true">Schneller Checkout</button>
@ -56,26 +54,13 @@
<div class="sidebar-layout"> <div class="sidebar-layout">
<div></div> <div></div>
<div> <div>
<h1>Weitere Schnäpchen</h1> <h1>Weitere Schnäppchen</h1>
<div class='grid m base shadow'> <div class='grid m base shadow'>
<section><a th:href="@{/shop/articles/1234}" class="section"> <section th:each="article: ${commercialArticles}"><a th:href="@{/shop/articles/{id}(id = ${article.id})}" class="section">
<img th:src="@{/img/product-4.jpg}"> <img th:src="@{/img/product-4.jpg}">
<h2>Kamera Stativ.</h2> <h2 th:text="${article.title}"></h2>
<p class='price'> 25.14&nbsp;EUR</p> <p class='price' th:text="${article.shopPricePerUnitNetCent}"></p>
<p> <p th:text="${article.description}"></p>
Das Stativ der Zukunft! Jetzt kaufen und verwenden für
wackelfreie Bilder aus der Zukunft!.
</p>
</a>
</section>
<section><a th:href="@{/shop/articles/1234}" class="section">
<img th:src="@{/img/product-5.jpg}">
<h2>Bluetooth Ersatzfernbedinung</h2>
<p class='price'> 10.14&nbsp;EUR</p>
<p>
Kann alles und jeden ausknippsen.
</p>
</a> </a>
</section> </section>
</div> </div>