WIP feature/listedArticles #15
|
@ -74,11 +74,11 @@ public class ShopArticleController {
|
||||||
|
|
||||||
Article article = articleRepository.findArticleById(id);
|
Article article = articleRepository.findArticleById(id);
|
||||||
|
|
||||||
// if (!article.isPresent()) {
|
if (article == null) {
|
||||||
// request.setAttribute("error", "Der Artikel wurde nicht gefunden.");
|
request.setAttribute("error", "Der Artikel wurde nicht gefunden.");
|
||||||
// response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
// return "error/404";
|
return "error/404";
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (setAmount != null && setAmount) {
|
if (setAmount != null && setAmount) {
|
||||||
shoppingCart.setArticleCount(article, quantity);
|
shoppingCart.setArticleCount(article, quantity);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.hso.ecommerce.controller.shop;
|
||||||
|
|
||||||
import org.hso.ecommerce.action.shop.GetRandomArticlesAction;
|
import org.hso.ecommerce.action.shop.GetRandomArticlesAction;
|
||||||
import org.hso.ecommerce.entities.shop.Article;
|
import org.hso.ecommerce.entities.shop.Article;
|
||||||
|
import org.hso.ecommerce.entities.user.User;
|
||||||
import org.hso.ecommerce.repos.shop.ArticleRepository;
|
import org.hso.ecommerce.repos.shop.ArticleRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -31,7 +32,7 @@ public class ShopIndexController {
|
||||||
List<Article> commercialArticles = GetRandomArticlesAction.getRandomArticles(8, articleRepository.getAdvertisedArticles());
|
List<Article> commercialArticles = GetRandomArticlesAction.getRandomArticles(8, articleRepository.getAdvertisedArticles());
|
||||||
model.addAttribute("commercialArticles", commercialArticles);
|
model.addAttribute("commercialArticles", commercialArticles);
|
||||||
|
|
||||||
//check if logged in
|
|
||||||
boolean isLoggedIn = false;
|
boolean isLoggedIn = false;
|
||||||
boolean hasOrders = false;
|
boolean hasOrders = false;
|
||||||
if (session != null && session.getAttribute("id") != null) {
|
if (session != null && session.getAttribute("id") != null) {
|
||||||
|
@ -40,7 +41,8 @@ public class ShopIndexController {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
List<Article> suggestedArticles = articleRepository.getLastOrderedArticles("4");
|
List<Article> suggestedArticles = articleRepository.getLastOrderedArticles();
|
||||||
|
suggestedArticles = suggestedArticles.size() > 3 ? suggestedArticles.subList(0,3) : suggestedArticles; //only latest 4 articles
|
||||||
if (suggestedArticles.size() > 0) {
|
if (suggestedArticles.size() > 0) {
|
||||||
model.addAttribute("suggestedArticles", suggestedArticles);
|
model.addAttribute("suggestedArticles", suggestedArticles);
|
||||||
hasOrders = true;
|
hasOrders = true;
|
||||||
|
|
|
@ -13,16 +13,16 @@ import java.util.Optional;
|
||||||
@Repository
|
@Repository
|
||||||
public interface ArticleRepository extends JpaRepository<Article, Long> {
|
public interface ArticleRepository extends JpaRepository<Article, Long> {
|
||||||
|
|
||||||
@Query("Select a FROM Article a where a.id = :articleId")
|
@Query("SELECT a FROM Article a WHERE a.id = :articleId")
|
||||||
Article findArticleById(@Param("articleId") long articleId);
|
Article findArticleById(@Param("articleId") long articleId);
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT a from Article a join a.related ao where ao.should_be_advertised = true")
|
@Query("SELECT a FROM Article a JOIN a.related ao WHERE ao.should_be_advertised = true")
|
||||||
List<Article> getAdvertisedArticles();
|
List<Article> getAdvertisedArticles();
|
||||||
|
|
||||||
|
|
||||||
@Query("SELECT c FROM User c WHERE c.email = :quantity")
|
@Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a ORDER BY co.id DESC")
|
||||||
List<Article> getLastOrderedArticles(@Param("quantity") String quantity);
|
List<Article> getLastOrderedArticles();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue