better article
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import fr.eni.enchere.bll.ArticleService;
|
||||
import fr.eni.enchere.bll.CategorieService;
|
||||
import fr.eni.enchere.bll.RetraitService;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bll.*;
|
||||
import fr.eni.enchere.bo.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -14,6 +12,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -25,6 +24,7 @@ import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Controller()
|
||||
@@ -38,12 +38,14 @@ public class ArticleController {
|
||||
private final UserService userService;
|
||||
private CategorieService categorieService;
|
||||
private RetraitService retraitService;
|
||||
private EnchereService enchereService;
|
||||
|
||||
public ArticleController(ArticleService articleService, UserService userService, CategorieService categorieService, RetraitService retraitService) {
|
||||
public ArticleController(ArticleService articleService, UserService userService, CategorieService categorieService, RetraitService retraitService, EnchereService enchereService) {
|
||||
this.articleService = articleService;
|
||||
this.userService = userService;
|
||||
this.categorieService = categorieService;
|
||||
this.retraitService = retraitService;
|
||||
this.enchereService = enchereService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -54,31 +56,34 @@ public class ArticleController {
|
||||
//Affichage d'un article
|
||||
|
||||
@GetMapping("/show")
|
||||
public String showArticle(@RequestParam()int id, Model model) {
|
||||
public String showArticle(@RequestParam()int id, Model model, HttpSession session) {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (!authentication.getName().equals("anonymousUser")) {
|
||||
Article article = articleService.findArticleById(id);
|
||||
UserProfil user = userService.utilisateurById(article.getUtilisateur());
|
||||
Categorie cate = categorieService.findCategorieById(article.getNumCategorie());
|
||||
Retrait retrait = retraitService.retraitByNumarticle(article.getId());
|
||||
List<Enchere> lastEnchere = this.enchereService.enchereByArticle(article.getId());
|
||||
Optional<Float> maxMontantEnchere = lastEnchere.stream()
|
||||
.map(Enchere::getMontantEnchere) // Récupère seulement les montants d'enchère
|
||||
.max(Float::compareTo);
|
||||
model.addAttribute("article", article);
|
||||
model.addAttribute("username", user);
|
||||
model.addAttribute("cate", cate.getLibelle());
|
||||
model.addAttribute("retrait", retrait);
|
||||
model.addAttribute("enchere", new Enchere());
|
||||
model.addAttribute("maxEnchere", maxMontantEnchere.get());
|
||||
List<ObjectError> errors = (List<ObjectError>) session.getAttribute("errors");
|
||||
if (errors != null) {
|
||||
model.addAttribute("errors", errors);
|
||||
session.removeAttribute("errors"); // Supprimer les erreurs de la session après utilisation
|
||||
}
|
||||
return "article";
|
||||
} else {
|
||||
return "redirect:/accueil";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{slug}")
|
||||
public String testShowArticle(@PathVariable(name = "slug")int id, Model model) {
|
||||
Article article = articleService.findArticleById(id);
|
||||
model.addAttribute("article", article);
|
||||
return "article";
|
||||
}
|
||||
|
||||
//Création d'un article
|
||||
|
||||
@GetMapping("/new")
|
||||
|
||||
Reference in New Issue
Block a user