fix only show ordered Articles from specific Customer
This commit is contained in:
		@ -34,14 +34,13 @@ public class ShopIndexController {
 | 
			
		||||
 | 
			
		||||
        boolean isLoggedIn = false;
 | 
			
		||||
        boolean hasOrders = false;
 | 
			
		||||
 | 
			
		||||
        if (session != null && session.getAttribute("userId") != null) {
 | 
			
		||||
            long userId = (long) session.getAttribute("userId");
 | 
			
		||||
            isLoggedIn = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (isLoggedIn) {
 | 
			
		||||
            List<Article> suggestedArticles = articleRepository.getOrderedArticles();
 | 
			
		||||
            suggestedArticles = suggestedArticles.size() > 3 ? suggestedArticles.subList(0,4) : suggestedArticles; //only latest 4 articles
 | 
			
		||||
            List<Article> suggestedArticles = articleRepository.getOrderedArticles(userId);
 | 
			
		||||
            suggestedArticles = suggestedArticles.size() > 3 ? suggestedArticles.subList(0, 4) : suggestedArticles; //only latest 4 articles
 | 
			
		||||
            if (suggestedArticles.size() > 0) {
 | 
			
		||||
                model.addAttribute("suggestedArticles", suggestedArticles);
 | 
			
		||||
                hasOrders = true;
 | 
			
		||||
 | 
			
		||||
@ -19,8 +19,8 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {
 | 
			
		||||
    List<Article> getAdvertisedArticles();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @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> getOrderedArticles();
 | 
			
		||||
    @Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a WHERE c.id = :customerId ORDER BY co.id DESC")
 | 
			
		||||
    List<Article> getOrderedArticles(long customerId);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,10 @@
 | 
			
		||||
            <h1>Angebote</h1>
 | 
			
		||||
            <script th:src="@{/js/back.js}"></script>
 | 
			
		||||
            <div class="back" data-group="shop" data-name="Zurück zur Startseite." data-insert="false"></div>
 | 
			
		||||
            <div class='grid m base shadow'>
 | 
			
		||||
            <div th:if="${commercialArticles.size() == 0}">
 | 
			
		||||
                <h1>Momentan gibt es keine Angebote</h1>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class='grid m base shadow' th:if="${commercialArticles.size() != 0}">
 | 
			
		||||
                <section th:each="article: ${commercialArticles}">
 | 
			
		||||
                    <a th:href="@{/shop/articles/{id}(id=${article.id})}" class="section">
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user