Ajout article v3

This commit is contained in:
jleroy
2024-04-24 14:58:28 +02:00
parent 62d2de271e
commit be83631053
4 changed files with 49 additions and 25 deletions

View File

@@ -8,9 +8,15 @@ import fr.eni.enchere.bo.Article;
import fr.eni.enchere.bo.Retrait;
import fr.eni.enchere.bo.UserProfil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.text.SimpleDateFormat;
import java.util.Date;
@Controller()
@RequestMapping("/article")
@@ -31,7 +37,7 @@ public class ArticleController {
@GetMapping
public String viewArticle(Model model) {
return "accueil";
return "redirect:/accueil";
}
//Affichage d'un article
@@ -60,15 +66,31 @@ public class ArticleController {
}
@PostMapping("/new")
public String newArticle(@RequestParam("article") Article article, @RequestParam("retrait") Retrait retrait) {
//Récupérer l'utilisateur pour set
System.out.println(article.getNumCategorie());
public String newArticle(@ModelAttribute("article") Article article,
@RequestParam("rue") String rue,
@RequestParam("code_postal") String code_postal,
@RequestParam("ville") String ville,
@RequestParam("dateDebut") String dateDebut,
@RequestParam("dateFin") String datefin) {
//Récupérer l'utilisateur pour set l'article
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String username = authentication.getName();
UserProfil userProfile = userService.utilisateurByName(username);
article.setUtilisateur(userProfile.getId());
//Récupérer le lieu de retrait
Retrait retrait = new Retrait();
retrait.setRue(rue);
retrait.setCode_postale(code_postal);
retrait.setVille(ville);
//Reste de l'article
Date dDateDebut = new SimpleDateFormat(dateDebut);
article.setDateDebutEnch();
if (article.getId() == 0){
//Création d'un article
} else {
//Mise à jour d'un article
}
//articleService.saveArticle(article);
return "redirect:/accueil";
}