diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java index 34cb03d..843d9a0 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java @@ -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()); } -} - +} \ No newline at end of file diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java index 4819607..5a204bf 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopSearchController.java @@ -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
articles = articleRepository.getArticlesByTerm(term); model.addAttribute("articles", articles); - } else if (category != null) { //if search by Category - List
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"; } - } \ No newline at end of file diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java index 3a3f5d7..4520855 100644 --- a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java +++ b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java @@ -26,12 +26,9 @@ public interface ArticleRepository extends JpaRepository { @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
getOrderedArticles(long customerId); - @Query("SELECT a FROM Article a WHERE a.title LIKE %:term%") List
getArticlesByTerm(String term); - @Query("SELECT a FROM Article a JOIN a.categories c WHERE :category = c.name") //TODO: Wahrscheinlich falsch! - List
getArticlesByCategory(String category); - - -} + @Query("SELECT a FROM Article a JOIN a.categories c WHERE :category = c.name") + List
getArticlesByCategory(String category); +} \ No newline at end of file diff --git a/prototype/src/main/resources/templates/fragments/header.html b/prototype/src/main/resources/templates/fragments/header.html index 1ec92b4..4f14d7c 100644 --- a/prototype/src/main/resources/templates/fragments/header.html +++ b/prototype/src/main/resources/templates/fragments/header.html @@ -39,6 +39,7 @@ document.getElementById(id).classList.toggle("invisible"); } + X @@ -55,6 +56,7 @@ document.getElementById(id).classList.toggle("invisible"); } + X diff --git a/prototype/src/main/resources/templates/shop/articles/id.html b/prototype/src/main/resources/templates/shop/articles/id.html index ef18fb4..00d2c73 100644 --- a/prototype/src/main/resources/templates/shop/articles/id.html +++ b/prototype/src/main/resources/templates/shop/articles/id.html @@ -23,7 +23,9 @@
-

EUR

+

EUR +

@@ -32,7 +34,9 @@
-

EUR

+

EUR +