Ajout article v1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bll.ArticleService;
|
||||
import fr.eni.enchere.bll.CategorieService;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -13,10 +14,12 @@ public class ArticleController {
|
||||
|
||||
private final ArticleService articleService;
|
||||
private final UserService userService;
|
||||
private CategorieService categorieService;
|
||||
|
||||
public ArticleController(ArticleService articleService, UserService userService) {
|
||||
public ArticleController(ArticleService articleService, UserService userService, CategorieService categorieService) {
|
||||
this.articleService = articleService;
|
||||
this.userService = userService;
|
||||
this.categorieService = categorieService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -24,7 +27,8 @@ public class ArticleController {
|
||||
return "accueil";
|
||||
}
|
||||
|
||||
@GetMapping("/article")
|
||||
//Affichage d'un article
|
||||
@GetMapping("/show")
|
||||
public String showArticle(@RequestParam(name = "slug")int id, Model model) {
|
||||
Article article = articleService.findArticleById(id);
|
||||
return "article";
|
||||
@@ -39,14 +43,14 @@ public class ArticleController {
|
||||
|
||||
@GetMapping("/new")
|
||||
public String test(@PathVariable(name = "slug")int id, Model model) {
|
||||
|
||||
return "article";
|
||||
model.addAttribute("categories", categorieService.findAllCategories());
|
||||
return "newArticle";
|
||||
}
|
||||
|
||||
@PostMapping("/new/add")
|
||||
public String newArticle(@ModelAttribute("article") Article article) {
|
||||
articleService.saveArticle(article);
|
||||
return "redirect:/article";
|
||||
return "redirect:/accueil";
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
|
||||
@@ -5,7 +5,77 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="container-main">
|
||||
<h1>Nouvelle vente</h1>
|
||||
<form action="/articles/add" method="post" enctype="multipart/form-data">
|
||||
<!-- Nom de l'article -->
|
||||
<div>
|
||||
<label for="nom">Article:</label>
|
||||
<input type="text" id="nom" name="nom" required>
|
||||
</div>
|
||||
|
||||
<!-- Description -->
|
||||
<div>
|
||||
<label for="description">Description:</label>
|
||||
<textarea id="description" name="description" required></textarea>
|
||||
</div>
|
||||
|
||||
<!-- Catégorie -->
|
||||
<div>
|
||||
<label for="categorie">Catégorie:</label>
|
||||
<select id="categorie" name="categorie" required>
|
||||
<option value="categorie1">Catégorie 1</option>
|
||||
<option value="categorie2">Catégorie 2</option>
|
||||
<!-- Ajoutez d'autres options si nécessaire -->
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Photo -->
|
||||
<div>
|
||||
<label for="photo">Photo de l'article:</label>
|
||||
<input type="file" id="photo" name="photo" accept="image/jpeg" required>
|
||||
</div>
|
||||
|
||||
<!-- Mise à prix -->
|
||||
<div>
|
||||
<label for="prix">Mise à prix:</label>
|
||||
<input type="number" id="prix" name="prix" min="0" required>
|
||||
</div>
|
||||
|
||||
<!-- Date début enchère -->
|
||||
<div>
|
||||
<label for="dateDebut">Date début enchère:</label>
|
||||
<input type="date" id="dateDebut" name="dateDebut" min="<?php echo date('Y-m-d'); ?>" required>
|
||||
</div>
|
||||
|
||||
<!-- Date fin enchère -->
|
||||
<div>
|
||||
<label for="dateFin">Date fin enchère:</label>
|
||||
<input type="date" id="dateFin" name="dateFin" required>
|
||||
</div>
|
||||
|
||||
<!-- Lieu de retrait -->
|
||||
<h2>Retrait</h2>
|
||||
<div>
|
||||
<label for="rue">Rue:</label>
|
||||
<input type="text" id="rue" name="rue" required>
|
||||
</div>
|
||||
<div>
|
||||
<label for="codePostal">Code postal:</label>
|
||||
<input type="text" id="codePostal" name="codePostal" required>
|
||||
</div>
|
||||
<div>
|
||||
<label for="ville">Ville:</label>
|
||||
<input type="text" id="ville" name="ville" required>
|
||||
</div>
|
||||
|
||||
<!-- Bouton Enregistrer -->
|
||||
<div>
|
||||
<button type="submit">Enregistrer</button>
|
||||
</div>
|
||||
</form>
|
||||
<form th:action="@{/accueil}" method="post">
|
||||
<button type="submit">Annuler</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user