Ajout article v3
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package fr.eni.enchere.bo;
|
package fr.eni.enchere.bo;
|
||||||
|
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class Article {
|
public class Article {
|
||||||
@@ -7,18 +9,18 @@ public class Article {
|
|||||||
int id;
|
int id;
|
||||||
String nom;
|
String nom;
|
||||||
String desc;
|
String desc;
|
||||||
String photo;
|
MultipartFile photo;
|
||||||
Date dateDebutEnch;
|
Date dateDebutEnch;
|
||||||
Date dateFinEnch;
|
Date dateFinEnch;
|
||||||
float prixInitial;
|
float prixInitial;
|
||||||
float prixVente;
|
float prixVente;
|
||||||
UserProfil Utilisateur;
|
int Utilisateur;
|
||||||
int numCategorie;
|
int numCategorie;
|
||||||
|
|
||||||
public Article() {
|
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);
|
setId(id);
|
||||||
setNom(nom);
|
setNom(nom);
|
||||||
setDesc(desc);
|
setDesc(desc);
|
||||||
@@ -55,11 +57,11 @@ public class Article {
|
|||||||
this.desc = desc;
|
this.desc = desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPhoto() {
|
public MultipartFile getPhoto() {
|
||||||
return photo;
|
return photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPhoto(String photo) {
|
public void setPhoto(MultipartFile photo) {
|
||||||
this.photo = photo;
|
this.photo = photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,11 +97,11 @@ public class Article {
|
|||||||
this.prixVente = prixVente;
|
this.prixVente = prixVente;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserProfil getUtilisateur() {
|
public int getUtilisateur() {
|
||||||
return Utilisateur;
|
return Utilisateur;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUtilisateur(UserProfil Utilisateur) {
|
public void setUtilisateur(int Utilisateur) {
|
||||||
this.Utilisateur = 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.Retrait;
|
||||||
import fr.eni.enchere.bo.UserProfil;
|
import fr.eni.enchere.bo.UserProfil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@RequestMapping("/article")
|
@RequestMapping("/article")
|
||||||
@@ -31,7 +37,7 @@ public class ArticleController {
|
|||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public String viewArticle(Model model) {
|
public String viewArticle(Model model) {
|
||||||
return "accueil";
|
return "redirect:/accueil";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Affichage d'un article
|
//Affichage d'un article
|
||||||
@@ -60,15 +66,31 @@ public class ArticleController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/new")
|
@PostMapping("/new")
|
||||||
public String newArticle(@RequestParam("article") Article article, @RequestParam("retrait") Retrait retrait) {
|
public String newArticle(@ModelAttribute("article") Article article,
|
||||||
//Récupérer l'utilisateur pour set
|
@RequestParam("rue") String rue,
|
||||||
System.out.println(article.getNumCategorie());
|
@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){
|
if (article.getId() == 0){
|
||||||
//Création d'un article
|
//Création d'un article
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//Mise à jour d'un article
|
//Mise à jour d'un article
|
||||||
}
|
}
|
||||||
//articleService.saveArticle(article);
|
|
||||||
return "redirect:/accueil";
|
return "redirect:/accueil";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class WebSecurityConfig{
|
|||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http.authorizeHttpRequests((requests) -> requests
|
http.authorizeHttpRequests((requests) -> requests
|
||||||
.requestMatchers("/", "/accueil").permitAll()
|
.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("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**", "/assets/**").permitAll()
|
||||||
.requestMatchers("/profil/**", "/article/new/**", "/article/update", "/article/delete").authenticated()
|
.requestMatchers("/profil/**", "/article/new/**", "/article/update", "/article/delete").authenticated()
|
||||||
.requestMatchers("/admin").hasRole("ADMIN")
|
.requestMatchers("/admin").hasRole("ADMIN")
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
<!DOCTYPE html>
|
<!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>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="container-main">
|
<div id="container-main">
|
||||||
<h1>Nouvelle vente</h1>
|
<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 -->
|
<!-- Nom de l'article -->
|
||||||
<div>
|
<div>
|
||||||
<label for="nom">Article:</label>
|
<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>
|
</div>
|
||||||
|
|
||||||
<!-- Description -->
|
<!-- Description -->
|
||||||
<div>
|
<div>
|
||||||
<label for="description">Description:</label>
|
<label for="description">Description:</label>
|
||||||
<textarea id="description" th:field="*{article.desc}" required></textarea>
|
<textarea id="description" th:field="*{desc}" required></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Catégorie -->
|
<!-- Catégorie -->
|
||||||
<div>
|
<div>
|
||||||
<label for="categorie">Catégorie:</label>
|
<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 -->
|
<!-- 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>
|
<option th:each="categorie : ${categories}" th:value="${categorie.id}" th:text="${categorie.libelle}"></option>
|
||||||
</select>
|
</select>
|
||||||
@@ -31,40 +31,40 @@
|
|||||||
<!-- Photo -->
|
<!-- Photo -->
|
||||||
<div>
|
<div>
|
||||||
<label for="photo">Photo de l'article:</label>
|
<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>
|
</div>
|
||||||
|
|
||||||
<!-- Mise à prix -->
|
<!-- Mise à prix -->
|
||||||
<div>
|
<div>
|
||||||
<label for="prix">Mise à prix:</label>
|
<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>
|
</div>
|
||||||
|
|
||||||
<!-- Date début enchère -->
|
<!-- Date début enchère -->
|
||||||
<div>
|
<div>
|
||||||
<label for="dateDebut">Date début enchère:</label>
|
<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>
|
</div>
|
||||||
|
|
||||||
<!-- Date fin enchère -->
|
<!-- Date fin enchère -->
|
||||||
<div>
|
<div>
|
||||||
<label for="dateFin">Date fin enchère:</label>
|
<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>
|
</div>
|
||||||
|
|
||||||
<!-- Lieu de retrait -->
|
<!-- Lieu de retrait -->
|
||||||
<h4>Retrait</h4>
|
<h4>Retrait</h4>
|
||||||
<div>
|
<div>
|
||||||
<label for="rue">Rue:</label>
|
<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>
|
||||||
<div>
|
<div>
|
||||||
<label for="codePostal">Code postal:</label>
|
<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>
|
||||||
<div>
|
<div>
|
||||||
<label for="ville">Ville:</label>
|
<label for="ville">Ville:</label>
|
||||||
<input type="text" id="ville" th:field="*{retrait.ville}" required>
|
<input type="text" id="ville" name="ville" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Bouton Enregistrer -->
|
<!-- Bouton Enregistrer -->
|
||||||
|
|||||||
Reference in New Issue
Block a user