ShopArticleController initial
This commit is contained in:
parent
6ab3b63923
commit
f48f5c40f0
|
@ -43,7 +43,7 @@ public class RequestController {
|
|||
String gto = (String) session.getAttribute("afterLogin");
|
||||
|
||||
Optional<User> 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() {
|
||||
|
|
|
@ -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<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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,17 +19,12 @@
|
|||
<div class="detailgrid">
|
||||
<div class="s">
|
||||
|
||||
<h1>Tolle Kamera</h1>
|
||||
<h1 th:text="${article.title}"></h1>
|
||||
<script th:src="@{/js/back.js}"></script>
|
||||
<div class="back" data-group="shop" data-insert="true"></div>
|
||||
|
||||
<h2>25.14 EUR</h2>
|
||||
<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>
|
||||
<h2 th:text="${article.shopPricePerUnitNetCent}"></h2>
|
||||
<p th:text="${article.description}"></p>
|
||||
</div>
|
||||
<div class="s">
|
||||
<img th:src="@{/img/product-1.jpg}"/>
|
||||
|
@ -37,14 +32,17 @@
|
|||
<div class="s"></div>
|
||||
<form class="s" method="POST">
|
||||
<div class="detailgrid m">
|
||||
<h2>50.28 EUR</h2>
|
||||
<h2 th:text="${article.shopPricePerUnitNetCent}"></h2>
|
||||
<div>
|
||||
|
||||
<label class="nolinebreak">Menge:</label>
|
||||
<select size="1">
|
||||
<option>2</option>
|
||||
<option th:each="quantity : ${#numbers.sequence(1,100)}"
|
||||
th:value="${quantity}"
|
||||
th:text="${quantity}"></option>
|
||||
</select>
|
||||
</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>
|
||||
<button class="no-margin" name="fastcheckout" value="true">Schneller Checkout</button>
|
||||
|
@ -56,26 +54,13 @@
|
|||
<div class="sidebar-layout">
|
||||
<div></div>
|
||||
<div>
|
||||
<h1>Weitere Schnäpchen</h1>
|
||||
<h1>Weitere Schnäppchen</h1>
|
||||
<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}">
|
||||
<h2>Kamera Stativ.</h2>
|
||||
<p class='price'> 25.14 EUR</p>
|
||||
<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 EUR</p>
|
||||
<p>
|
||||
Kann alles und jeden ausknippsen.
|
||||
</p>
|
||||
<h2 th:text="${article.title}"></h2>
|
||||
<p class='price' th:text="${article.shopPricePerUnitNetCent}"></p>
|
||||
<p th:text="${article.description}"></p>
|
||||
</a>
|
||||
</section>
|
||||
</div>
|
||||
|
|
Reference in New Issue