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