Controller Article

This commit is contained in:
jleroy
2024-04-23 16:34:40 +02:00
parent d6351121f7
commit b69c283964
7 changed files with 90 additions and 10 deletions

View File

@@ -0,0 +1,62 @@
package fr.eni.enchere.controllers;
import fr.eni.enchere.bll.ArticleService;
import fr.eni.enchere.bll.UserService;
import fr.eni.enchere.bo.Article;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@Controller()
@RequestMapping("/article")
public class ArticleController {
private final ArticleService articleService;
private final UserService userService;
public ArticleController(ArticleService articleService, UserService userService) {
this.articleService = articleService;
this.userService = userService;
}
@GetMapping
public String viewArticle(Model model) {
return "accueil";
}
@GetMapping("/article")
public String showArticle(@RequestParam(name = "slug")int id, Model model) {
Article article = articleService.findArticleById(id);
return "article";
}
@GetMapping("/{slug}")
public String testShowArticle(@PathVariable(name = "slug")int id, Model model) {
Article article = articleService.findArticleById(id);
model.addAttribute("article", article);
return "article";
}
@GetMapping("/new")
public String test(@PathVariable(name = "slug")int id, Model model) {
return "article";
}
@PostMapping("/new/add")
public String newArticle(@ModelAttribute("article") Article article) {
articleService.saveArticle(article);
return "redirect:/article";
}
@PostMapping("/update")
public String updateArticle() {
return "redirect:/accueil";
}
@PostMapping("/delete")
public String deleteArticle() {
return "redirect:/accueil";
}
}

View File

@@ -5,7 +5,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;