Ajout article v3
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package fr.eni.enchere.bo;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Article {
|
||||
@@ -7,18 +9,18 @@ public class Article {
|
||||
int id;
|
||||
String nom;
|
||||
String desc;
|
||||
String photo;
|
||||
MultipartFile photo;
|
||||
Date dateDebutEnch;
|
||||
Date dateFinEnch;
|
||||
float prixInitial;
|
||||
float prixVente;
|
||||
UserProfil Utilisateur;
|
||||
int Utilisateur;
|
||||
int numCategorie;
|
||||
|
||||
public Article() {
|
||||
}
|
||||
|
||||
public Article(int id, String nom, String desc, String photo, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, UserProfil Utilisateur, int numCategorie) {
|
||||
public Article(int id, String nom, String desc, MultipartFile photo, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, int Utilisateur, int numCategorie) {
|
||||
setId(id);
|
||||
setNom(nom);
|
||||
setDesc(desc);
|
||||
@@ -55,11 +57,11 @@ public class Article {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getPhoto() {
|
||||
public MultipartFile getPhoto() {
|
||||
return photo;
|
||||
}
|
||||
|
||||
public void setPhoto(String photo) {
|
||||
public void setPhoto(MultipartFile photo) {
|
||||
this.photo = photo;
|
||||
}
|
||||
|
||||
@@ -95,11 +97,11 @@ public class Article {
|
||||
this.prixVente = prixVente;
|
||||
}
|
||||
|
||||
public UserProfil getUtilisateur() {
|
||||
public int getUtilisateur() {
|
||||
return Utilisateur;
|
||||
}
|
||||
|
||||
public void setUtilisateur(UserProfil Utilisateur) {
|
||||
public void setUtilisateur(int Utilisateur) {
|
||||
this.Utilisateur = Utilisateur;
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class WebSecurityConfig{
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.authorizeHttpRequests((requests) -> requests
|
||||
.requestMatchers("/", "/accueil").permitAll()
|
||||
.requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/**", "/change-language").permitAll()
|
||||
.requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/show", "/change-language").permitAll()
|
||||
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**", "/assets/**").permitAll()
|
||||
.requestMatchers("/profil/**", "/article/new/**", "/article/update", "/article/delete").authenticated()
|
||||
.requestMatchers("/admin").hasRole("ADMIN")
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr" th:replace="~{modele-page :: layout('Ajouter un article',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
|
||||
<html 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">
|
||||
<h1>Nouvelle vente</h1>
|
||||
<form th:action="@{/article/new}" method="post" enctype="multipart/form-data">
|
||||
<form th:action="@{/article/new}" method="post" th:object="${article}" enctype="multipart/form-data">
|
||||
<!-- Nom de l'article -->
|
||||
<div>
|
||||
<label for="nom">Article:</label>
|
||||
<input type="text" id="nom" th:field="*{article.nom}" required>
|
||||
<input type="text" id="nom" th:field="*{nom}" required>
|
||||
</div>
|
||||
|
||||
<!-- Description -->
|
||||
<div>
|
||||
<label for="description">Description:</label>
|
||||
<textarea id="description" th:field="*{article.desc}" required></textarea>
|
||||
<textarea id="description" th:field="*{desc}" required></textarea>
|
||||
</div>
|
||||
|
||||
<!-- Catégorie -->
|
||||
<div>
|
||||
<label for="categorie">Catégorie:</label>
|
||||
<select id="categorie" th:field="*{article.numCategorie}" required>
|
||||
<select id="categorie" th:field="*{numCategorie}" required>
|
||||
<!-- Boucle sur les catégories pour générer les options -->
|
||||
<option th:each="categorie : ${categories}" th:value="${categorie.id}" th:text="${categorie.libelle}"></option>
|
||||
</select>
|
||||
@@ -31,40 +31,40 @@
|
||||
<!-- Photo -->
|
||||
<div>
|
||||
<label for="photo">Photo de l'article:</label>
|
||||
<input type="file" id="photo" th:field="*{article.photo}" accept="image/jpeg" required>
|
||||
<input type="file" id="photo" th:field="*{photo}" accept="image/jpeg">
|
||||
</div>
|
||||
|
||||
<!-- Mise à prix -->
|
||||
<div>
|
||||
<label for="prix">Mise à prix:</label>
|
||||
<input type="number" id="prix" th:field="*{article.prixInitial}" min="0" required>
|
||||
<input type="number" id="prix" th:field="*{prixInitial}" min="0" required>
|
||||
</div>
|
||||
|
||||
<!-- Date début enchère -->
|
||||
<div>
|
||||
<label for="dateDebut">Date début enchère:</label>
|
||||
<input type="date" id="dateDebut" th:field="*{article.dateDebutEnch}" min="today" required>
|
||||
<input type="date" id="dateDebut" name="dateDebut" required>
|
||||
</div>
|
||||
|
||||
<!-- Date fin enchère -->
|
||||
<div>
|
||||
<label for="dateFin">Date fin enchère:</label>
|
||||
<input type="date" id="dateFin" th:field="*{article.dateFinEnch}" min="today" required>
|
||||
<input type="date" id="dateFin" name="dateFin" required>
|
||||
</div>
|
||||
|
||||
<!-- Lieu de retrait -->
|
||||
<h4>Retrait</h4>
|
||||
<div>
|
||||
<label for="rue">Rue:</label>
|
||||
<input type="text" id="rue" th:field="*{retrait.rue}" required>
|
||||
<input type="text" id="rue" name="rue" required>
|
||||
</div>
|
||||
<div>
|
||||
<label for="codePostal">Code postal:</label>
|
||||
<input type="text" id="codePostal" th:field="*{retrait.code_postale}" required>
|
||||
<input type="text" id="codePostal" name="code_postal" required>
|
||||
</div>
|
||||
<div>
|
||||
<label for="ville">Ville:</label>
|
||||
<input type="text" id="ville" th:field="*{retrait.ville}" required>
|
||||
<input type="text" id="ville" name="ville" required>
|
||||
</div>
|
||||
|
||||
<!-- Bouton Enregistrer -->
|
||||
|
||||
Reference in New Issue
Block a user