70 lines
1.9 KiB
Java
70 lines
1.9 KiB
Java
package org.hso.ecommerce.controller.shop;
|
|
|
|
import org.hso.ecommerce.entities.shop.Article;
|
|
import org.hso.ecommerce.repos.shop.ArticleRepository;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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.servlet.http.HttpSession;
|
|
import java.util.List;
|
|
|
|
@Controller
|
|
@RequestMapping("/")
|
|
public class ShopIndexController {
|
|
|
|
@Autowired
|
|
private final ArticleRepository articleRepository = null;
|
|
|
|
@GetMapping("/")
|
|
public String home() {
|
|
return "redirect:/shop/";
|
|
}
|
|
|
|
@GetMapping("/shop/")
|
|
public String shop(Model model, HttpSession session) {
|
|
|
|
List<Article> commercialArticles = articleRepository.getAdvertisedArticles();
|
|
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 (isLoggedIn) {
|
|
List<Article> suggestedArticles = articleRepository.getLastOrderedArticles("4");
|
|
if(suggestedArticles.size() > 0) {
|
|
model.addAttribute("suggestedArticles", suggestedArticles);
|
|
hasOrders = true;
|
|
}
|
|
}
|
|
|
|
model.addAttribute("isLoggedIn", isLoggedIn);
|
|
model.addAttribute("hasOrders", hasOrders);
|
|
|
|
return "shop/index";
|
|
}
|
|
|
|
@GetMapping("/about")
|
|
public String about() {
|
|
return "about";
|
|
}
|
|
|
|
@GetMapping("/terms")
|
|
public String terms() {
|
|
return "terms";
|
|
}
|
|
|
|
@GetMapping("/privacy")
|
|
public String privacy() {
|
|
return "privacy";
|
|
}
|
|
|
|
}
|