Critere de recherche

This commit is contained in:
mepiphana2023
2024-04-23 14:58:56 +02:00
parent b7c4dc358c
commit 4d617f32c3
13 changed files with 217 additions and 21 deletions

View File

@@ -1,7 +1,9 @@
package fr.eni.enchere.controllers;
import fr.eni.enchere.bll.ArticleService;
import fr.eni.enchere.bll.CategorieService;
import fr.eni.enchere.bo.Article;
import fr.eni.enchere.bo.SearchArticleCritere;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
@@ -10,6 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.util.List;
@@ -19,23 +22,30 @@ public class AccueilController {
private static final Logger logger = LoggerFactory.getLogger(AccueilController.class);
private ArticleService articleService;
private CategorieService categorieService;
public AccueilController(ArticleService articleService) {
public AccueilController(ArticleService articleService, CategorieService categorieService) {
super();
this.categorieService = categorieService;
this.articleService = articleService;
}
@GetMapping({"/", "/accueil"})
public String viewAccueil(Model model) {
model.addAttribute("articles", articleService.findAllArticle());
public String viewAccueil(@RequestParam(required = false) String searchTitle, @RequestParam(required = false) Integer searchCategory, Model model) {
System.out.println("Liste cat: "+categorieService.findAllCategories());
model.addAttribute("categories", categorieService.findAllCategories());
SearchArticleCritere critere = new SearchArticleCritere();
critere.setNoCategorie(searchCategory);
critere.setTitle(searchTitle);
model.addAttribute("articles", articleService.searchArticle(critere));
return "accueil";
}
@PostMapping("/searchArticle")
public String searchArticle(@ModelAttribute String title, Model model) {
model.addAttribute("Articles", articleService.findArticleByTitle(title));
return "accueil";
@PostMapping("/accueil")
public String handleSearch(@RequestParam("searchTitle") String searchTitle, @RequestParam(value = "searchCategory", required = false) Integer searchCategory, Model model) {
System.out.println("test");
return viewAccueil(searchTitle, searchCategory, model);
}
@GetMapping("/login")