implement errorhandling
This commit is contained in:
		@ -40,7 +40,7 @@ public class ShopArticleController {
 | 
			
		||||
                                   HttpServletRequest request,
 | 
			
		||||
                                   HttpServletResponse response
 | 
			
		||||
    ) {
 | 
			
		||||
        model.addAttribute("categories", categoryRepository.getCategories());
 | 
			
		||||
        model.addAttribute("categories", categoryRepository.getCategories());   //for sidebar
 | 
			
		||||
 | 
			
		||||
        Article article = articleRepository.findArticleById(id);
 | 
			
		||||
 | 
			
		||||
@ -104,5 +104,4 @@ public class ShopArticleController {
 | 
			
		||||
        response.setContentType(MediaType.IMAGE_JPEG_VALUE);
 | 
			
		||||
        IOUtils.copy(in, response.getOutputStream());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -8,6 +8,7 @@ import org.springframework.stereotype.Controller;
 | 
			
		||||
import org.springframework.ui.Model;
 | 
			
		||||
import org.springframework.web.bind.annotation.*;
 | 
			
		||||
 | 
			
		||||
import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@ -24,25 +25,24 @@ public class ShopSearchController {
 | 
			
		||||
    @GetMapping("")
 | 
			
		||||
    public String searchArticles(@RequestParam(required = false, value = "term") String term,
 | 
			
		||||
                                 @RequestParam(required = false, value = "category") String category,
 | 
			
		||||
                                 Model model
 | 
			
		||||
                                 Model model,
 | 
			
		||||
                                 HttpServletRequest request,
 | 
			
		||||
                                 HttpServletResponse response
 | 
			
		||||
    ) {
 | 
			
		||||
 | 
			
		||||
        model.addAttribute("categories", categoryRepository.getCategories());
 | 
			
		||||
        model.addAttribute("categories", categoryRepository.getCategories());   //for sidebar
 | 
			
		||||
 | 
			
		||||
        if (term != null) { //if search by Term
 | 
			
		||||
 | 
			
		||||
            List<Article> articles = articleRepository.getArticlesByTerm(term);
 | 
			
		||||
            model.addAttribute("articles", articles);
 | 
			
		||||
 | 
			
		||||
        } else if (category != null) {  //if search by Category
 | 
			
		||||
 | 
			
		||||
            List<Article> articles = articleRepository.getArticlesByCategory(category);
 | 
			
		||||
            model.addAttribute("articles", articles);
 | 
			
		||||
 | 
			
		||||
        } else {
 | 
			
		||||
            request.setAttribute("error", "Es wurden keine Suchparameter angegeben.");
 | 
			
		||||
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
 | 
			
		||||
            return "error/404";
 | 
			
		||||
        }
 | 
			
		||||
        //TODO: hier eventuell noch Errorhandling für nix von beidem
 | 
			
		||||
 | 
			
		||||
        return "/shop/search";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -26,12 +26,9 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {
 | 
			
		||||
    @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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Query("SELECT a FROM Article a WHERE a.title LIKE %:term%")
 | 
			
		||||
    List<Article> getArticlesByTerm(String term);
 | 
			
		||||
 | 
			
		||||
    @Query("SELECT a FROM Article a JOIN a.categories c WHERE :category = c.name")   //TODO: Wahrscheinlich falsch!
 | 
			
		||||
    List<Article>getArticlesByCategory(String category);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
    @Query("SELECT a FROM Article a JOIN a.categories c WHERE :category = c.name")
 | 
			
		||||
    List<Article> getArticlesByCategory(String category);
 | 
			
		||||
}
 | 
			
		||||
@ -39,6 +39,7 @@
 | 
			
		||||
                     document.getElementById(id).classList.toggle("invisible");
 | 
			
		||||
                  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                </script>
 | 
			
		||||
                <a class="secondary button error" href="javascript:void(0)" onclick="toggle('error-msg');">X</a>
 | 
			
		||||
            </div>
 | 
			
		||||
@ -55,6 +56,7 @@
 | 
			
		||||
                     document.getElementById(id).classList.toggle("invisible");
 | 
			
		||||
                  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                </script>
 | 
			
		||||
                <a class="secondary button info" href="javascript:void(0)" onclick="toggle('info-msg');">X</a>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
@ -23,7 +23,9 @@
 | 
			
		||||
                    <script th:src="@{/js/back.js}"></script>
 | 
			
		||||
                    <div class="back" data-group="shop" data-insert="true"></div>
 | 
			
		||||
 | 
			
		||||
                    <h2><span th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span></h2>
 | 
			
		||||
                    <h2><span
 | 
			
		||||
                            th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span>
 | 
			
		||||
                    </h2>
 | 
			
		||||
                    <p th:text="${article.description}"></p>
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="s">
 | 
			
		||||
@ -32,7 +34,9 @@
 | 
			
		||||
                <div class="s"></div>
 | 
			
		||||
                <form class="s" method="POST">
 | 
			
		||||
                    <div class="detailgrid m">
 | 
			
		||||
                        <h2><span th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span></h2>
 | 
			
		||||
                        <h2><span
 | 
			
		||||
                                th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span>
 | 
			
		||||
                        </h2>
 | 
			
		||||
                        <div>
 | 
			
		||||
                            <label class="nolinebreak">Menge:</label>
 | 
			
		||||
                            <select name="quantity" size="1">
 | 
			
		||||
@ -55,10 +59,13 @@
 | 
			
		||||
        <div>
 | 
			
		||||
            <h1>Weitere Schnäppchen</h1>
 | 
			
		||||
            <div class='grid m base shadow'>
 | 
			
		||||
                <section th:each="article: ${commercialArticles}"><a th:href="@{/shop/articles/{id}(id = ${article.id})}" class="section">
 | 
			
		||||
                <section th:each="article: ${commercialArticles}"><a
 | 
			
		||||
                        th:href="@{/shop/articles/{id}(id = ${article.id})}" class="section">
 | 
			
		||||
                    <img th:src="@{/shop/articles/{id}/image.jpg(id=${article.id})}"/>
 | 
			
		||||
                    <h2 th:text="${article.title}"></h2>
 | 
			
		||||
                    <p class='price'><span th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span></p>
 | 
			
		||||
                    <p class='price'><span
 | 
			
		||||
                            th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span>
 | 
			
		||||
                    </p>
 | 
			
		||||
                    <p th:text="${article.description}"></p>
 | 
			
		||||
                </a>
 | 
			
		||||
                </section>
 | 
			
		||||
 | 
			
		||||
@ -22,14 +22,16 @@
 | 
			
		||||
            </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">
 | 
			
		||||
                    <a th:href="@{/shop/articles/{id}(id=${article.id})}" class="section">
 | 
			
		||||
 | 
			
		||||
                    <img th:src="@{/shop/articles/{id}/image.jpg(id=${article.id})}"/>
 | 
			
		||||
                    <h2 th:text="${article.title}" />
 | 
			
		||||
                    <p class='price'><span th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span></p>
 | 
			
		||||
                    <p th:text="${article.description}" />
 | 
			
		||||
                </a>
 | 
			
		||||
            </section>
 | 
			
		||||
                        <img th:src="@{/shop/articles/{id}/image.jpg(id=${article.id})}"/>
 | 
			
		||||
                        <h2 th:text="${article.title}"/>
 | 
			
		||||
                        <p class='price'><span
 | 
			
		||||
                                th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span>
 | 
			
		||||
                        </p>
 | 
			
		||||
                        <p th:text="${article.description}"/>
 | 
			
		||||
                    </a>
 | 
			
		||||
                </section>
 | 
			
		||||
                <section class="spacer"></section>
 | 
			
		||||
                <section class="spacer"></section>
 | 
			
		||||
                <section class="spacer"></section>
 | 
			
		||||
@ -67,9 +69,11 @@
 | 
			
		||||
                        <a th:href="@{/shop/articles/{id}(id=${article.id})}" class="section">
 | 
			
		||||
 | 
			
		||||
                            <img th:src="@{/shop/articles/{id}/image.jpg(id=${article.id})}"/>
 | 
			
		||||
                            <h2 th:text="${article.title}" />
 | 
			
		||||
                            <p class='price'><span th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span></p>
 | 
			
		||||
                            <p th:text="${article.description}" />
 | 
			
		||||
                            <h2 th:text="${article.title}"/>
 | 
			
		||||
                            <p class='price'><span
 | 
			
		||||
                                    th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span>
 | 
			
		||||
                            </p>
 | 
			
		||||
                            <p th:text="${article.description}"/>
 | 
			
		||||
                        </a>
 | 
			
		||||
                    </section>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
@ -28,9 +28,11 @@
 | 
			
		||||
                <a th:href="@{/shop/articles/{id}(id=${article.id})}" class="section">
 | 
			
		||||
 | 
			
		||||
                    <img th:src="@{/shop/articles/{id}/image.jpg(id=${article.id})}"/>
 | 
			
		||||
                    <h2 th:text="${article.title}" />
 | 
			
		||||
                    <p class='price'><span th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span></p>
 | 
			
		||||
                    <p th:text="${article.description}" />
 | 
			
		||||
                    <h2 th:text="${article.title}"/>
 | 
			
		||||
                    <p class='price'><span
 | 
			
		||||
                            th:text="${#numbers.formatDecimal(article.getPriceGross() * 0.01, 1, 'POINT', 2, 'COMMA')}"></span><span> EUR</span>
 | 
			
		||||
                    </p>
 | 
			
		||||
                    <p th:text="${article.description}"/>
 | 
			
		||||
                </a>
 | 
			
		||||
            </section>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user