Merge branch 'Johan'

This commit is contained in:
Parpaillax
2024-04-24 12:15:40 +02:00
10 changed files with 222 additions and 101 deletions

View File

@@ -0,0 +1,8 @@
package fr.eni.enchere.bll;
import fr.eni.enchere.bo.Retrait;
public interface RetraitService {
Retrait retraitByNumarticle(int id);
void setRetrait(Retrait retrait);
}

View File

@@ -0,0 +1,17 @@
package fr.eni.enchere.bll;
import fr.eni.enchere.bo.Retrait;
import org.springframework.stereotype.Service;
@Service("RetraitService")
public class RetraitServiceImpl implements RetraitService {
@Override
public Retrait retraitByNumarticle(int id) {
return null;
}
@Override
public void setRetrait(Retrait retrait) {
}
}

View File

@@ -7,6 +7,7 @@ public class Article {
int id;
String nom;
String desc;
String photo;
Date dateDebutEnch;
Date dateFinEnch;
float prixInitial;
@@ -17,16 +18,17 @@ public class Article {
public Article() {
}
public Article(int id, String nom, String desc, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, UserProfil Utilisateur, int numCategorie) {
this.id = id;
this.nom = nom;
this.desc = desc;
this.dateDebutEnch = dateDebutEnch;
this.dateFinEnch = dateFinEnch;
this.prixInitial = prixInitial;
this.prixVente = prixVente;
this.Utilisateur = Utilisateur;
this.numCategorie = numCategorie;
public Article(int id, String nom, String desc, String photo, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, UserProfil Utilisateur, int numCategorie) {
setId(id);
setNom(nom);
setDesc(desc);
setPhoto(photo);
setDateDebutEnch(dateDebutEnch);
setDateFinEnch(dateFinEnch);
setPrixInitial(prixInitial);
setPrixVente(prixVente);
setUtilisateur(Utilisateur);
setNumCategorie(numCategorie);
}
public int getId() {
@@ -53,6 +55,14 @@ public class Article {
this.desc = desc;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public Date getDateDebutEnch() {
return dateDebutEnch;
}

View File

@@ -0,0 +1,50 @@
package fr.eni.enchere.bo;
public class Retrait {
private int numArticle;
private String rue;
private String code_postale;
private String ville;
public Retrait(){}
public Retrait(int numArticle, String rue, String code_postale, String ville) {
setNumArticle(numArticle);
setRue(rue);
setCode_postale(code_postale);
setVille(ville);
}
public String getVille() {
return ville;
}
public void setVille(String ville) {
this.ville = ville;
}
public String getCode_postale() {
return code_postale;
}
public void setCode_postale(String code_postale) {
this.code_postale = code_postale;
}
public String getRue() {
return rue;
}
public void setRue(String rue) {
this.rue = rue;
}
public int getNumArticle() {
return numArticle;
}
public void setNumArticle(int numArticle) {
this.numArticle = numArticle;
}
}

View File

@@ -2,8 +2,12 @@ package fr.eni.enchere.controllers;
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.bo.Article;
import fr.eni.enchere.bo.Retrait;
import fr.eni.enchere.bo.UserProfil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@@ -12,14 +16,17 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/article")
public class ArticleController {
@Autowired
private final ArticleService articleService;
private final UserService userService;
private CategorieService categorieService;
private RetraitService retraitService;
public ArticleController(ArticleService articleService, UserService userService, CategorieService categorieService) {
public ArticleController(ArticleService articleService, UserService userService, CategorieService categorieService, RetraitService retraitService) {
this.articleService = articleService;
this.userService = userService;
this.categorieService = categorieService;
this.retraitService = retraitService;
}
@GetMapping
@@ -28,6 +35,7 @@ public class ArticleController {
}
//Affichage d'un article
@GetMapping("/show")
public String showArticle(@RequestParam(name = "slug")int id, Model model) {
Article article = articleService.findArticleById(id);
@@ -41,25 +49,26 @@ public class ArticleController {
return "article";
}
//Création d'un article
@GetMapping("/new")
public String test(@PathVariable(name = "slug")int id, Model model) {
public String newArticleForm(Model model) {
model.addAttribute("categories", categorieService.findAllCategories());
model.addAttribute("article", new Article());
model.addAttribute("retrait", new Retrait());
return "newArticle";
}
@PostMapping("/new/add")
public String newArticle(@ModelAttribute("article") Article article) {
articleService.saveArticle(article);
return "redirect:/accueil";
@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());
if (article.getId() == 0){
//Création d'un article
} else {
//Mise à jour d'un article
}
@PostMapping("/update")
public String updateArticle() {
return "redirect:/accueil";
}
@PostMapping("/delete")
public String deleteArticle() {
//articleService.saveArticle(article);
return "redirect:/accueil";
}

View File

@@ -66,7 +66,7 @@ public class ArticleRepositoryImpl implements ArticleRepository {
@Override
public List<Article> searchArticle(SearchArticleCritere critere) {
StringBuilder sql = new StringBuilder("SELECT * FROM ARTICLES_VENDUS WHERE 1 = 1");
StringBuilder sql = new StringBuilder("SELECT * FROM ARTICLES_VENDUS WHERE 1 = 1 AND isDelete = 0");
List<Object> params = new ArrayList<>();

View File

@@ -0,0 +1,8 @@
package fr.eni.enchere.dal;
import fr.eni.enchere.bo.Retrait;
public interface RetraitRepository {
Retrait findById(int id);
void save(Retrait retrait);
}

View File

@@ -0,0 +1,20 @@
package fr.eni.enchere.dal;
import fr.eni.enchere.bo.Retrait;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;
@Repository
@Primary
public class RetraitRepositoryImpl implements RetraitRepository {
@Override
public Retrait findById(int id) {
return null;
}
@Override
public void save(Retrait retrait) {
}
}

View File

@@ -19,7 +19,7 @@ public class WebSecurityConfig{
.requestMatchers("/", "/accueil").permitAll()
.requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/**", "/change-language").permitAll()
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**", "/assets/**").permitAll()
.requestMatchers("/profil/**", "/article/new/**", "/article/update", "/article/delete").authenticated()
.requestMatchers("/profil/**", "/article/new/**").authenticated()
.requestMatchers("/admin").hasRole("ADMIN")
.anyRequest().authenticated())
.formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true))

View File

@@ -3,69 +3,68 @@
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="container-main">
<body>
<div id="container-main">
<h1>Nouvelle vente</h1>
<form action="/articles/add" method="post" enctype="multipart/form-data">
<form th:action="@{/article/new}" method="post" enctype="multipart/form-data">
<!-- Nom de l'article -->
<div>
<label for="nom">Article:</label>
<input type="text" id="nom" name="nom" required>
<input type="text" id="nom" th:field="*{article.nom}" required>
</div>
<!-- Description -->
<div>
<label for="description">Description:</label>
<textarea id="description" name="description" required></textarea>
<textarea id="description" th:field="*{article.desc}" 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 id="categorie" th:field="*{article.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>
</div>
<!-- Photo -->
<div>
<label for="photo">Photo de l'article:</label>
<input type="file" id="photo" name="photo" accept="image/jpeg" required>
<input type="file" id="photo" th:field="*{article.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>
<input type="number" id="prix" th:field="*{article.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" name="dateDebut" min="<?php echo date('Y-m-d'); ?>" required>
<input type="date" id="dateDebut" th:field="*{article.dateDebutEnch}" min="today" required>
</div>
<!-- Date fin enchère -->
<div>
<label for="dateFin">Date fin enchère:</label>
<input type="date" id="dateFin" name="dateFin" required>
<input type="date" id="dateFin" th:field="*{article.dateFinEnch}" min="today" required>
</div>
<!-- Lieu de retrait -->
<h2>Retrait</h2>
<h4>Retrait</h4>
<div>
<label for="rue">Rue:</label>
<input type="text" id="rue" name="rue" required>
<input type="text" id="rue" th:field="*{retrait.rue}" required>
</div>
<div>
<label for="codePostal">Code postal:</label>
<input type="text" id="codePostal" name="codePostal" required>
<input type="text" id="codePostal" th:field="*{retrait.code_postale}" required>
</div>
<div>
<label for="ville">Ville:</label>
<input type="text" id="ville" name="ville" required>
<input type="text" id="ville" th:field="*{retrait.ville}" required>
</div>
<!-- Bouton Enregistrer -->
@@ -76,6 +75,6 @@
<form th:action="@{/accueil}" method="post">
<button type="submit">Annuler</button>
</form>
</div>
</body>
</div>
</body>
</html>