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;

View File

@@ -2,7 +2,6 @@
<html lang="fr" th:replace="~{modele-page :: layout('Accueil - ENI-Enchères',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Accueil</title>
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet">
<link href="assets/bootstrap-icons/bootstrap-icons.min.css" rel="stylesheet">
</head>

View File

@@ -1,12 +1,11 @@
<!DOCTYPE html>
<html lang="fr">
<html lang="fr" th:replace="~{modele-page :: layout('Panel administrateur',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Panel administrateur</title>
</head>
<body>
<!-- Ajouter la page de nav bar -->
<body>
<div id="container-main">
<!-- Ajouter le footer -->
</body>
</html>
</div>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="fr" th:replace="~{modele-page :: layout('Article - NOMARTICLE',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="container-main">
</div>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="fr" th:replace="~{modele-page :: layout('Ajouter un article',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="container-main">
</div>
</body>
</html>

View File

@@ -2,7 +2,6 @@
<html lang="fr" th:replace="~{modele-page :: layout('Profile',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Mon profile</title>
</head>
<body>
<div id="container-main">