package fr.eni.enchere.controllers;

import fr.eni.enchere.bll.ArticleService;
import fr.eni.enchere.bo.Article;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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 java.util.List;


@Controller
public class AccueilController {

    private static final Logger logger = LoggerFactory.getLogger(AccueilController.class);
    private ArticleService articleService;

    public AccueilController(ArticleService articleService) {
        super();

        this.articleService = articleService;
    }

    @GetMapping({"/", "/accueil"})
    public String viewAccueil(Model model) {
        model.addAttribute("articles", articleService.findAllArticle());
        return "accueil";
    }

    @PostMapping("/searchArticle")
    public String searchArticle(@ModelAttribute String title, Model model) {
        model.addAttribute("Articles", articleService.findArticleByTitle(title));
        return "accueil";
    }

    @GetMapping("/login")
    public String login(Model modele) {
        return "login";
    }

}
