Merge remote-tracking branch 'origin/main'

# Conflicts:
#	src/main/resources/i18n/messages_en.properties
This commit is contained in:
mepiphana2023
2024-04-26 15:47:06 +02:00
19 changed files with 372 additions and 206 deletions

View File

@@ -35,7 +35,7 @@ public class CategorieServiceImpl implements CategorieService {
@Override
public void updateCategorie(Categorie categorie) {
categorieRepository.updateCategorie(categorie);
}
@Override

View File

@@ -11,6 +11,7 @@ public interface UserService {
List<String> listPseudo();
List<String> listEmail();
void setUtilisateur(UserProfil utilisateur);
void setCredit(float credit, int id);
void deleteUtilisateur(int id);
void disableUtilisateur(int id);
}

View File

@@ -45,6 +45,11 @@ public class UserServiceImpl implements UserService {
userRepository.save(utilisateur);
}
@Override
public void setCredit(float credit, int id) {
userRepository.updateCredit(credit, id);
}
@Override
public void deleteUtilisateur(int id) {
userRepository.delete(id);

View File

@@ -44,7 +44,31 @@ public class AdminController {
Categorie categorie = new Categorie();
categorie.setLibelle(libelle);
categorie.setId(idCategorie);
categorieService.updateCategorie(categorie);
return "redirect:/admin";
}
@PostMapping("/update/credit")
public String updateCreditUser(@RequestParam("newCredit") float credit, @RequestParam("idUser") int idUser) {
userService.setCredit(credit, idUser);
return "redirect:/admin";
}
@PostMapping("/deleteC")
public String deleteCategorie(@RequestParam("deleteIdCategorie") int id) {
categorieService.deleteCategorie(id);
return "redirect:/admin";
}
@PostMapping("/delete")
public String deleteUser(@RequestParam("userDelete") int id) {
userService.deleteUtilisateur(id);
return "redirect:/admin";
}
@PostMapping("/disabled")
public String disabledUser(@RequestParam("userDisabled") int id) {
userService.disableUtilisateur(id);
return "redirect:/admin";
}

View File

@@ -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,37 @@ 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());
article.setPseudoUtilisateur(user.getPseudo());
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());
if (maxMontantEnchere.isPresent()) {
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")
@@ -194,7 +202,6 @@ public class ArticleController {
for (JsonNode node : responseBody) {
String cityName = node.get("nomCommune").asText();
villeCodePostal.add(cityName);
System.out.println(cityName);
}
} else {
redirectAttributes.addAttribute("erreur", "Une erreur est survenue !");
@@ -219,4 +226,18 @@ public class ArticleController {
return "redirect:/accueil";
}
//Update d'un article
@GetMapping("/edit")
public String edit(Model model, @RequestParam()int id) {
Article article = this.articleService.findArticleById(id);
Retrait retrait = this.retraitService.retraitByNumarticle(id);
System.out.println(article.getNom());
model.addAttribute("article", article);
model.addAttribute("retrait", retrait);
model.addAttribute("categories", this.categorieService.findAllCategories());
return "editArticle";
}
}

View File

@@ -5,7 +5,9 @@ import fr.eni.enchere.bll.EnchereService;
import fr.eni.enchere.bll.UserService;
import fr.eni.enchere.bo.Article;
import fr.eni.enchere.bo.Enchere;
import fr.eni.enchere.bo.UserProfil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
@@ -34,7 +36,7 @@ public class EnchereController {
}
@PostMapping("/incEnchere")
public String incEnchere(@ModelAttribute("enchere") Enchere enchere, @RequestParam("articleId") int articleId, BindingResult result) {
public String incEnchere(@ModelAttribute("enchere") Enchere enchere, @RequestParam("articleId") int articleId, BindingResult result, HttpSession session) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
enchere.setNoArticle(articleId);
enchere.setNoUtilisateur(this.userService.utilisateurByName(authentication.getName()).getId());
@@ -54,12 +56,18 @@ public class EnchereController {
Optional<Float> maxMontantEnchere = lastEnchere.stream()
.map(Enchere::getMontantEnchere) // Récupère seulement les montants d'enchère
.max(Float::compareTo);
System.out.println(maxMontantEnchere);
if (maxMontantEnchere.isPresent() && encherePrice < maxMontantEnchere.get()) {
result.rejectValue("montantEnchere", "error.enchere", "Vous ne pouvez pas enchérir un montant inférieur à la dernière enchère");
}
//Empeche l'enchère si les crédits du user sont inférieur au prix initial de l'article
float userCredit = this.userService.utilisateurByName(authentication.getName()).getCredit();
if (userCredit < encherePrice) {
result.rejectValue("montantEnchere", "error.enchere", "Vous ne pouvez pas enchérir si vous n'avez pas les fonds suffisant");
}
if (result.hasErrors()) {
session.setAttribute("errors", result.getAllErrors());
return "redirect:/article/show?id=" + articleId;
}

View File

@@ -50,17 +50,19 @@ public class CategorieRepositoryImpl implements CategorieRepository {
@Override
public void saveCategorie(Categorie categorie) {
String sql = "INSERT INTO CATEGORIES (\t=libelle) VALUES (?)";
String sql = "INSERT INTO CATEGORIES (libelle) VALUES (?)";
jdbcTemplate.update(sql, categorie.getLibelle());
}
@Override
public void updateCategorie(Categorie categorie) {
String sql = "UPDATE CATEGORIES SET libelle = ? WHERE no_categorie = ?";
jdbcTemplate.update(sql, categorie.getLibelle(), categorie.getId());
}
@Override
public void deleteCategorie(int id) {
String sql = "UPDATE CATEGORIES SET isDelete = 1 WHERE no_categorie = ?";
jdbcTemplate.update(sql, id);
}
}

View File

@@ -43,7 +43,9 @@ public class EnchereRepositoryImpl implements EnchereRepository {
@Override
public List<Enchere> findByIdArticle(int idArticle) {
return List.of();
String sql = "SELECT * FROM ENCHERES WHERE no_article = ?";
List<Enchere> encheres = jdbcTemplate.query(sql, new EnchereRowMapper(), idArticle);
return encheres;
}
@Override

View File

@@ -11,6 +11,7 @@ public interface UserRepository {
List<String> findAllUsernames();
List<String> findAllEmail();
void save(UserProfil utilisateur);
void updateCredit(float credit, int id);
void delete(int id);
void disable(int id);
}

View File

@@ -134,6 +134,12 @@ public class UserRepositoryImpl implements UserRepository {
}
}
@Override
public void updateCredit(float credit, int id) {
String sql = "UPDATE UTILISATEURS SET credit = ? WHERE no_utilisateur = ?";
jdbcTemplate.update(sql, credit, id);
}
@Override
public void delete(int id) {
String sql = "UPDATE UTILISATEURS SET isDelete = 1 WHERE no_utilisateur = ?";

View File

@@ -28,7 +28,7 @@ public class UserInterceptor implements HandlerInterceptor {
if (authentication != null && authentication.isAuthenticated() && !authentication.getName().equals("anonymousUser")) {
UserProfil user = this.userService.utilisateurByName(authentication.getName());
if (modelAndView != null && modelAndView.getViewName() != null && !modelAndView.getViewName().startsWith("redirect:")) {
modelAndView.addObject("user", user.getCredit());
modelAndView.addObject("user", user);
}
}
}

View File

@@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

View File

@@ -1,7 +1,29 @@
home.search.title = Rechercher un article par nom...
home.search.cat = Toutes les cat\u00e9gories
home.search.button = Recherche
home.buy.title = Achats
home.buy.open = Ench\u00e8res ouvertes
home.buy.progress = Mes ench\u00E8res en cours
home.buy.success = Mes ench\u00E8res remport\u00e9es
home.sell.title = Mes Ventes
home.sell.progress = Mes ventes en cours
home.sell.nostarted = Mes ventes non d\u00e9but\u00e9es
home.sell.finish = Mes ventes termin\u00E9es
home.button.search = Recherche
home.button.lang = Switch to English
home.button.lang2 = FR
home.credit = Mes cr\u00e9dits :
home.nav.enchere = Encheres
home.nav.vend = Vendre un article
home.nav.login = S'inscrire / Se connecter
home.profil.profil = Profil
home.profil.logout = D\u00e9connexion
home.article.sellprice = Prix de vente:
home.article.seller = Vendeur:
home.article.end = Fin de l'ench\u00E8re:
footer.desc = Cr\u00e9\u00e9e par l'association "Les objets sont nos amis", ENI-Ench\u00e9res a pour objectif d'aider ses membres \u00E0 vendre ou acheter des objets de tout genre.
footer.
profil.title = Mon profile
profil.button = Modifier
@@ -44,4 +66,54 @@ register.ville.label = Ville:
register.password.label = Mot de passe:
register.confirm_password.label = Confirmation du mot de passe:
register.submit_button = Cr\u00E9er
register.cancel_button = Annuler
register.cancel_button = Annuler
admin.panel.title = Panel administrateur
admin.categories.title = Liste des cat\u00E9gories modifi\u00E9es
admin.categories.table.name = Nom
admin.categories.table.action = Action
admin.categories.table.save = Enregistrer
admin.categories.table.delete = Supprimer
admin.categories.table.add = Ajouter
admin.users.title = Liste des utilisateurs
admin.users.table.id = ID
admin.users.table.username = Pseudo
admin.users.table.lastname = Nom
admin.users.table.firstname = Pr\u00E9nom
admin.users.table.email = Email
admin.users.table.disable = D\u00E9sactiver
admin.users.table.delete = Supprimer
article.add.title = Ajouter un article
article.add.heading = Nouvelle vente
article.add.form.label.name = Article:
article.add.form.label.description = Description:
article.add.form.label.category = Cat\u00E9gorie:
article.add.form.label.photo = Photo de l'article:
article.add.form.label.starting_price = Mise \u00E0 prix:
article.add.form.label.start_date = Date d\u00E9but ench\u00E8re:
article.add.form.label.end_date = Date fin ench\u00E8re:
article.add.form.label.removal = Retrait
article.add.form.label.street = Rue:
article.add.form.label.postal_code = Code postal:
article.add.form.label.city = Ville:
article.add.form.validation.required = Ce champ est requis.
article.add.form.validation.category = Veuillez s\u00E9lectionner une cat\u00E9gorie.
article.add.form.button.save = Enregistrer
article.add.form.button.cancel = Annuler
article.details.title = Article - NOMARTICLE
article.details.heading = Article
article.details.label.description = Description
article.details.label.seller = Vendeur
article.details.label.category = Cat\u00E9gorie
article.details.label.sale_price = Prix de vente
article.details.label.end_date = Date fin ench\u00E8re
article.details.label.pickup = Retrait
article.details.label.amount = Montant
article.details.button.bid = Ench\u00E9rir
article.details.address.unknown = Adresse inconnue
article.details.validation.amount.required = Le montant de l'ench\u00E8re est requis.
edit.article.title = Modifier mon article

View File

@@ -52,22 +52,22 @@
<div class="mb-3">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="typeTransaction" id="achats" value="achats" onchange="toggleCheckbox(this.value)">
<label class="form-check-label" for="achats">Achats</label>
<label class="form-check-label" for="achats" th:text="#{home.sell.title}"></label>
</div>
</div>
<!-- Checkboxes pour Achats -->
<div id="achatsOptions">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="achatOption" id="encheresOuvertes" th:value="encheresOuvertes" disabled>
<label class="form-check-label" for="encheresOuvertes">Enchères ouvertes</label>
<label class="form-check-label" for="encheresOuvertes" th:text="#{home.buy.open}"></label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="achatOption" id="enchereEnCours" th:value="enchereEnCours" disabled>
<label class="form-check-label" for="enchereEnCours">Mes enchères en cours</label>
<label class="form-check-label" for="enchereEnCours" th:text="#{home.buy.progress}"></label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="achatOption" id="enchereRemportees" th:value="enchereRemportees" disabled>
<label class="form-check-label" for="enchereRemportees">Mes enchères remportées</label>
<label class="form-check-label" for="enchereRemportees" th:text="#{home.buy.success}"></label>
</div>
</div>
</div>
@@ -76,22 +76,22 @@
<div class="mb-3">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="typeTransaction" id="ventes" value="ventes" onchange="toggleCheckbox(this.value)">
<label class="form-check-label" for="ventes">Mes Ventes</label>
<label class="form-check-label" for="ventes" th:text="#{home.sell.title}"></label>
</div>
</div>
<!-- Checkboxes pour Ventes -->
<div id="ventesOptions">
<div class="form-check">
<input class="form-check-input" type="checkbox" th:name="venteOption" id="venteEnCours" th:value="venteEnCours" disabled>
<label class="form-check-label" for="venteEnCours">Mes ventes en cours</label>
<label class="form-check-label" for="venteEnCours" th:text="#{home.sell.progress}"></label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" th:name="venteOption" id="ventesNonDebutees" th:value="ventesNonDebutees" disabled>
<label class="form-check-label" for="ventesNonDebutees">Mes ventes non débutées</label>
<label class="form-check-label" for="ventesNonDebutees" th:text="#{home.sell.nostarted}"></label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" th:name="venteOption" id="ventesTerminees" th:value="ventesTerminees" disabled>
<label class="form-check-label" for="ventesTerminees">Mes ventes terminées</label>
<label class="form-check-label" for="ventesTerminees" th:text="#{home.sell.finish}"></label>
</div>
</div>
</div>
@@ -108,7 +108,7 @@
</div>
<div class="row">
<div class="col-md-12 col-12 d-flex justify-content-center align-items-center">
<button type="submit" style="font-size: 1em;" class="btn btn-primary btn-lg w-100">Recherche</button>
<button type="submit" style="font-size: 1em;" class="btn btn-primary btn-lg w-100" th:text="#{home.button.search}"></button>
</div>
</div>
</form>
@@ -126,16 +126,16 @@
</div>
<div class="col-md-8">
<div class="card-body d-flex flex-column ">
<h5 class="text-dark card-title text" th:text="${article.nom}">Nom de l'article</h5>
<p class="text-dark card-text mb-auto" th:text="${article.desc}">Description</p>
<h5 class="text-dark card-title text" th:text="${article.nom}"></h5>
<p class="text-dark card-text mb-auto" th:text="${article.desc}"></p>
<div class="text-dark d-flex justify-content-between align-items-center">
<div>
<h6>Prix de vente: <span th:text="${article.prixVente}"></span></h6>
<h6>Vendeur: <span th:text="${article.pseudoUtilisateur}"></span> </h6>
<h6 th:text="#{home.article.sellprice}"> <span th:text="${article.prixVente}"></span></h6>
<h6 th:text="#{home.article.seller}"> <span th:text="${article.pseudoUtilisateur}"></span> </h6>
</div>
</div>
<br>
<h6 class="text-muted">Fin de l'enchère: <span th:text="${#dates.format(article.dateFinEnch, 'dd/MM/yyyy')}"></span></h6>
<h6 class="text-muted"> <span th:text="${#dates.format(article.dateFinEnch, 'dd/MM/yyyy')}"></span></h6>
</div>
</div>
</div>

View File

@@ -1,71 +1,71 @@
<!DOCTYPE html>
<html th:replace="~{modele-page :: layout('Panel administrateur',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<html th:replace="~{modele-page :: layout('__${#messages.msg('admin.panel.title')}__',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css"> <!-- Ajoutez le lien vers votre fichier CSS si nécessaire -->
</head>
<body>
<div id="container-main">
<h2>Liste des catégories modifiées</h2>
<h2 th:text="#{admin.categories.title}">Liste des catégories modifiées</h2>
<table>
<thead>
<tr>
<th>Nom</th>
<th>Action</th>
</tr>
<tr>
<th th:text="#{admin.categories.table.name}">Nom</th>
<th th:text="#{admin.categories.table.action}">Action</th>
</tr>
</thead>
<tbody>
<tr th:each="categorie : ${categories}">
<td>
<form th:action="@{/admin/update}" method="post">
<input type="text" name="newCategorie" id="newCategorie" th:value="${categorie.libelle}">
<input type="hidden" name="IdCategorie" id="IdCategorie" th:value="${categorie.id}">
<button>Sauvegarder</button>
</form>
</td>
<td>
<form th:action="@{/admin/catDelete}" method="post">
<input type="hidden" name="deleteIdCategorie" id="deleteIdCategorie" th:value="${categorie.id}">
<button>Supprimer</button>
</form>
</td>
</tr>
<tr th:each="categorie : ${categories}">
<td>
<form th:action="@{/admin/update}" method="post">
<input type="text" name="newCategorie" id="newCategorie" th:value="${categorie.libelle}">
<input type="hidden" name="IdCategorie" id="IdCategorie" th:value="${categorie.id}">
<button th:text="#{admin.categories.table.save}">Sauvegarder</button>
</form>
</td>
<td>
<form th:action="@{/admin/catDelete}" method="post">
<input type="hidden" name="deleteIdCategorie" id="deleteIdCategorie" th:value="${categorie.id}">
<button th:text="#{admin.categories.table.delete}">Supprimer</button>
</form>
</td>
</tr>
</tbody>
</table>
<form th:action="@{/admin/new}" th:object="${categorie}" method="post">
<input type="text" th:field="*{libelle}" id="nom">
<button>Ajouter</button>
<button th:text="#{admin.categories.table.add}">Ajouter</button>
</form>
<h2>Liste des utilisateurs</h2>
<h2 th:text="#{admin.users.title}">Liste des utilisateurs</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Pseudo</th>
<th>Nom</th>
<th>Prénom</th>
<th>Email</th>
<th>Action</th>
</tr>
<tr>
<th th:text="#{admin.users.table.id}">ID</th>
<th th:text="#{admin.users.table.username}">Pseudo</th>
<th th:text="#{admin.users.table.lastname}">Nom</th>
<th th:text="#{admin.users.table.firstname}">Prénom</th>
<th th:text="#{admin.users.table.email}">Email</th>
<th th:text="#{admin.users.table.action}">Action</th>
</tr>
</thead>
<tbody>
<tr th:each="user : ${userProfil}">
<td th:text="${user.id}"></td>
<td th:text="${user.pseudo}"></td>
<td th:text="${user.nom}"></td>
<td th:text="${user.prenom}"></td>
<td th:text="${user.email}"></td>
<td>
<form th:action="@{/admin/disabled}" method="post">
<input type="hidden" name="userDisabled" id="userDisabled" th:value="${user.id}">
<button >Désactiver</button>
</form>
<form th:action="@{/admin/delete}" method="post">
<input type="hidden" name="userDelete" id="userDelete" th:value="${user.id}">
<button>Supprimer</button>
</form>
</td>
</tr>
<tr th:each="user : ${userProfil}">
<td th:text="${user.id}"></td>
<td th:text="${user.pseudo}"></td>
<td th:text="${user.nom}"></td>
<td th:text="${user.prenom}"></td>
<td th:text="${user.email}"></td>
<td>
<form th:action="@{/admin/disabled}" method="post">
<input type="hidden" name="userDisabled" id="userDisabled" th:value="${user.id}">
<button th:text="#{admin.users.table.disable}">Désactiver</button>
</form>
<form th:action="@{/admin/delete}" method="post">
<input type="hidden" name="userDelete" id="userDelete" th:value="${user.id}">
<button th:text="#{admin.users.table.delete}">Supprimer</button>
</form>
</td>
</tr>
</tbody>
</table>

View File

@@ -1,68 +1,68 @@
<!DOCTYPE html>
<html th:replace="~{modele-page :: layout('Article - NOMARTICLE',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<html th:replace="~{modele-page :: layout('${articleDetailsTitle}',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="container-main">
<div class="row mt-3">
<div class="col-md-6 offset-md-3">
<div class="card">
<div class="card-header">
<h4>Article</h4>
<body>
<div id="container-main">
<div class="row mt-3">
<div class="col-md-6 offset-md-3">
<div class="card">
<div class="card-header">
<h4 th:text="#{article.details.heading}"></h4>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-3">
<img th:src="@{'/images/articles/' + ${article.id} + '.jpg'}" alt="image-vente" class="img-thumbnail" style="width: 250px; height: auto;">
</div>
<div class="card-body">
<div class="row">
<div class="col-md-3">
<img th:src="@{'/images/articles/' + ${article.id} + '.jpg'}" alt="image-vente" class="img-thumbnail" style="width: 250px; height: auto;">
</div>
<div class="col-md-9 d-flex flex-column">
<div class="mt-2 d-flex flex-column align-items-center">
<h1 th:text="${article.nom}"></h1>
</div>
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label">Description</label></strong>
<span th:text="${article.desc}"></span>
</div>
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label">Vendeur</label></strong>
<span th:text="${username.pseudo}"></span>
</div>
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label">Catégorie</label></strong>
<span th:text="${cate}"></span>
</div>
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label">Prix de vente</label></strong>
<span th:text="${article.prixInitial}"></span>
</div>
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label">Date fin enchère</label></strong>
<span th:text="${article.dateFinEnch}"></span>
</div>
<!-- Rajouter une condition sur retrait pour l'afficher uniquement quand -->
<!-- la vente est gagné ET à l'utilisateur qui a remporté la vente-->
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label">Retrait</label></strong>
<span th:text="${retrait} ? ${retrait.rue} + ' ' + ${retrait.code_postale} + ' ' + ${retrait.ville} : 'Adresse inconnue'"></span>
</div>
<form th:action="@{/enchere/incEnchere}" method="post" th:object="${enchere}" class="mt-2 d-flex flex-row align-items-end justify-content-between">
<input type="hidden" id="articleId" name="articleId" th:value="${article.id}">
<label for="montantEnchere">Montant</label>
<input type="number" th:field="*{montantEnchere}" id="montantEnchere" step="0.01" min="0">
<span style="color: red;" th:if="${#fields.hasErrors('montantEnchere')}">
<div class="col-md-9 d-flex flex-column">
<div class="mt-2 d-flex flex-column align-items-center">
<h1 th:text="${article.nom}"></h1>
</div>
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label" th:text="#{article.details.label.description}"></label></strong>
<span th:text="${article.desc}"></span>
</div>
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label" th:text="#{article.details.label.seller}"></label></strong>
<span th:text="${username.pseudo}"></span>
</div>
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label" th:text="#{article.details.label.category}"></label></strong>
<span th:text="${cate}"></span>
</div>
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label" th:text="#{article.details.label.sale_price}"></label></strong>
<span th:text="${article.prixInitial}"></span>
</div>
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label" th:text="#{article.details.label.end_date}"></label></strong>
<span th:text="${article.dateFinEnch}"></span>
</div>
<!-- Rajouter une condition sur retrait pour l'afficher uniquement quand -->
<!-- la vente est gagné ET à l'utilisateur qui a remporté la vente-->
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
<strong><label class="col-form-label" th:text="#{article.details.label.pickup}"></label></strong>
<span th:text="${retrait} ? ${retrait.rue} + ' ' + ${retrait.code_postale} + ' ' + ${retrait.ville} : #{article.details.address.unknown}"></span>
</div>
<form th:action="@{/enchere/incEnchere}" method="post" th:object="${enchere}" class="mt-2 d-flex flex-row align-items-end justify-content-between">
<input type="hidden" id="articleId" name="articleId" th:value="${article.id}">
<label for="montantEnchere" th:text="#{article.details.label.amount}"></label>
<input type="number" th:field="*{montantEnchere}" id="montantEnchere" step="0.01" min="0">
<span style="color: red;" th:if="${#fields.hasErrors('montantEnchere')}">
<ul>
<li th:each="erreur: ${#fields.errors('montantEnchere')}" th:text="${erreur}"></li>
</ul>
</span>
<button type="submit" class="btn btn-primary">Enchérir</button>
</form>
</div>
</div>
<button type="submit" class="btn btn-primary" th:text="#{article.details.button.bid}"></button>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="fr" th:replace="~{modele-page :: layout('Modifier votre article' , ~{::#link}, ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="container-main" class="container mt-5">
<h1 th:text="#{edit.article.title}"></h1>
<form th:action="@{/article/new}" th:object="${article}">
<div class="mb-3">
<label for="nom" class="form-label">Titre</label>
<input type="text" class="form-control" th:field="*{nom}" id="nom">
</div>
<div class="mb-3">
<label for="categorie" class="form-label">Catégorie:</label>
<select class="form-control" th:field="*{numCategorie}" id="categorie" required>
<option th:each="categorie : ${categories}" th:value="${categorie.id}" th:text="${categorie.libelle}"></option>
</select>
<div class="invalid-feedback">Veuillez sélectionner une catégorie.</div>
</div>
</form>
</div>
</body>
</html>

View File

@@ -21,35 +21,38 @@
<header>
<nav class="navbar navbar-expand-lg navbar navbar-dark bg-dark navbar-">
<a class="navbar-brand" href="/accueil">
<img src="/img/logo.png" width="70" height="70" alt="Logo">
<label class="text-light"><strong>ENI-Encheres</strong></label>
<img href="/accueil" src="/img/logo.png" width="70" height="70" alt="Logo">
<label href="/accueil" class="text-light"><strong>ENI-Encheres</strong></label>
</a>
<div th:if="${#authentication.principal != 'anonymousUser'}" class="text-light text-center d-flex justify-content-center align-items-center" th:text="#{'Mes crédits : '} + ${user}"></div>
<div th:if="${#authentication.principal != 'anonymousUser'}" class="text-light text-center d-flex justify-content-center align-items-center" th:text="#{home.credit} + ${user.getCredit()}"></div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse " id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item" th:if="${#authentication.principal != 'anonymousUser'}" th:classappend="${requestURI == '/accueil'} ? 'active'">
<a class="nav-link" href="/accueil">Encheres <span class="sr-only" >(current)</span></a>
<a class="nav-link" href="/accueil" th:text="#{home.nav.enchere}"> <span class="sr-only" >(current)</span></a>
</li>
<li class="nav-item" th:if="${#authentication.principal != 'anonymousUser'}" th:classappend="${requestURI == '/article/new'} ? 'active'">
<a class="nav-link" href="/article/new">Vendre un article</a>
<a class="nav-link" href="/article/new" th:text="#{home.nav.vend}"></a>
</li>
<li class="nav-item" th:if="${#authentication.principal == 'anonymousUser'}">
<a class="btn btn-primary" href="/login" role="button" style="background-color: #1B4463;">S'inscrire / Se connecter</a>
<a class="btn btn-primary" href="/login" role="button" style="background-color: #1B4463;" th:text="#{home.nav.login}"></a>
</li>
<li class="nav-item dropdown" th:if="${#authentication.principal != 'anonymousUser'}">
<a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-user"></i> <!-- Icône de profil -->
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="/profil">Profil</a> <!-- Bouton de profil -->
<a class="dropdown-item" href="/logout">Déconnexion</a> <!-- Bouton de déconnexion -->
<a class="dropdown-item" href="/profil" th:text="#{home.profil.profil}"></a> <!-- Bouton de profil -->
<a class="dropdown-item" href="/logout" th:text="#{home.profil.logout}"></a> <!-- Bouton de déconnexion -->
<div class="dropdown-divider"></div> <!-- Diviseur -->
<a class="dropdown-item" th:href="@{/change-language}" th:text="#{home.button.lang}"></a> <!-- Option de changement de langue vers l'anglais --><!-- Option de changement de langue vers le français -->
</div>
</li>
<li class="nav-item" th:if="${#authentication.principal == 'anonymousUser'}">
<strong><a class="nav-link" href="#" th:href="@{/change-language}" th:text="#{home.button.lang2}"></a></strong>
</li>
</ul>
</div>
</nav>
@@ -66,8 +69,7 @@
<h6 class="text-uppercase fw-bold mb-4">
<i class="fas fa-gem me-3"></i>ENI-Encheres
</h6>
<p>
Créée par l'association "Les objets sont nos amis", ENI-Enchères a pour objectif d'aider ses membres à vendre ou acheter des objets de tout genre.
<p th:text="#{footer.desc}">
</p>
</div>
@@ -76,13 +78,13 @@
Menu
</h6>
<p>
<a href="#!" class="text-reset">Encheres</a>
<a href="/accueil" class="text-reset" th:text="#{home.nav.enchere}"></a>
</p>
<p>
<a href="#!" class="text-reset">Vendre un article</a>
<a href="/article/new" class="text-reset" th:text="#{home.nav.vend}"></a>
</p>
<p>
<a href="#!" class="text-reset">Mon profile</a>
<a href="/profil" class="text-reset" th:text="#{profil.title}"></a>
</p>
</div>

View File

@@ -2,97 +2,92 @@
<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" th:object="${article}" enctype="multipart/form-data">
<!-- Nom de l'article -->
<div>
<label for="nom">Article:</label>
<input type="text" id="nom" th:field="*{nom}" required>
<div id="container-main" class="container py-5">
<h1 class="mb-4" th:text="#{article.add.heading}">Nouvelle vente</h1>
<form th:action="@{/article/new}" method="post" th:object="${article}" enctype="multipart/form-data" class="needs-validation" novalidate>
<div class="mb-3">
<label for="nom" class="form-label" th:text="#{article.add.form.label.name}">Article:</label>
<input type="text" class="form-control" th:field="*{nom}" id="nom" required>
<div class="invalid-feedback" th:text="#{article.add.form.validation.required}">Ce champ est requis.</div>
</div>
<!-- Description -->
<div>
<label for="description">Description:</label>
<textarea id="description" th:field="*{desc}" required></textarea>
<div class="mb-3">
<label for="description" class="form-label" th:text="#{article.add.form.label.description}">Description:</label>
<textarea class="form-control" th:field="*{desc}" id="description" required></textarea>
<div class="invalid-feedback" th:text="#{article.add.form.validation.required}">Ce champ est requis.</div>
</div>
<!-- Catégorie -->
<div>
<label for="categorie">Catégorie:</label>
<select id="categorie" th:field="*{numCategorie}" required>
<!-- Boucle sur les catégories pour générer les options -->
<div class="mb-3">
<label for="categorie" class="form-label" th:text="#{article.add.form.label.category}">Catégorie:</label>
<select class="form-control" th:field="*{numCategorie}" id="categorie" required>
<option th:each="categorie : ${categories}" th:value="${categorie.id}" th:text="${categorie.libelle}"></option>
</select>
<div class="invalid-feedback" th:text="#{article.add.form.validation.category}">Veuillez sélectionner une catégorie.</div>
</div>
<!-- Photo -->
<div>
<label for="photo">Photo de l'article:</label>
<input type="file" id="photo" th:field="*{photo}" accept="image/jpeg">
<div class="mb-3">
<label for="photo" class="form-label" th:text="#{article.add.form.label.photo}">Photo de l'article:</label>
<input type="file" class="form-control" th:field="*{photo}" id="photo" accept="image/jpeg">
</div>
<!-- Mise à prix -->
<div>
<label for="prix">Mise à prix:</label>
<input type="number" id="prix" th:field="*{prixInitial}" min="0" max="2000000000" step="0.01" required>
<div class="mb-3">
<label for="prix" class="form-label" th:text="#{article.add.form.label.starting_price}">Mise à prix:</label>
<input type="number" class="form-control" th:field="*{prixInitial}" id="prix" min="0" max="2000000000" step="0.01" required>
<div class="invalid-feedback" th:text="#{article.add.form.validation.required}">Ce champ est requis.</div>
</div>
<!-- Date début enchère -->
<div>
<label for="dateDebut">Date début enchère:</label>
<input type="date" id="dateDebut" name="dateDebut" required>
<div class="mb-3">
<label for="dateDebut" class="form-label" th:text="#{article.add.form.label.start_date}">Date début enchère:</label>
<input type="date" class="form-control" id="dateDebut" name="dateDebut" required>
<div class="invalid-feedback" th:text="#{article.add.form.validation.required}">Ce champ est requis.</div>
</div>
<!-- Date fin enchère -->
<div>
<label for="dateFin">Date fin enchère:</label>
<input type="date" id="dateFin" name="dateFin" required>
<div class="mb-3">
<label for="dateFin" class="form-label" th:text="#{article.add.form.label.end_date}">Date fin enchère:</label>
<input type="date" class="form-control" id="dateFin" name="dateFin" required>
<div class="invalid-feedback" th:text="#{article.add.form.validation.required}">Ce champ est requis.</div>
</div>
<!-- Lieu de retrait -->
<h4>Retrait</h4>
<div>
<label for="rue">Rue:</label>
<input type="text" id="rue" name="rue" th:field="${user.rue}" required>
<h4 th:text="#{article.add.form.label.removal}">Retrait</h4>
<div class="mb-3">
<label for="rue" class="form-label" th:text="#{article.add.form.label.street}">Rue:</label>
<input type="text" class="form-control" id="rue" name="rue" th:field="${user.rue}" required>
<div class="invalid-feedback" th:text="#{article.add.form.validation.required}">Ce champ est requis.</div>
</div>
<div>
<label for="codePostal">Code postal:</label>
<input type="text" id="codePostal" name="code_postal" th:field="${user.code_postal}" required>
<div class="mb-3">
<label for="codePostal" class="form-label" th:text="#{article.add.form.label.postal_code}">Code postal:</label>
<input type="text" class="form-control" id="codePostal" name="code_postal" th:field="${user.code_postal}" required>
<div class="invalid-feedback" th:text="#{article.add.form.validation.required}">Ce champ est requis.</div>
</div>
<div>
<label for="ville">Ville:</label>
<input type="text" id="ville" name="ville" th:field="${user.ville}" required>
<div class="mb-3">
<label for="ville" class="form-label" th:text="#{article.add.form.label.city}">Ville:</label>
<input type="text" class="form-control" id="ville" name="ville" th:field="${user.ville}" required>
<div class="invalid-feedback" th:text="#{article.add.form.validation.required}">Ce champ est requis.</div>
</div>
<!-- Bouton Enregistrer -->
<div>
<button type="submit">Enregistrer</button>
</div>
<button type="submit" class="btn btn-primary" th:text="#{article.add.form.button.save}">Enregistrer</button>
<!-- En cas d'erreur -->
<div th:if="${param.erreur != null}">
<div th:if="${param.erreur != null}" class="mt-3">
<p style="color: red;" th:text="${param.erreur}"></p>
</div>
</form>
<form th:action="@{/accueil}" method="post">
<button type="submit">Annuler</button>
<form th:action="@{/accueil}" method="post" class="mt-3">
<button type="submit" class="btn btn-secondary" th:text="#{article.add.form.button.cancel}">Annuler</button>
</form>
<script>
// Obtenez la date actuelle et j+1
var today = new Date();
var tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
// Formatez la date au format YYYY-MM-DD pour l'attribut min
var formattedDateToday = today.toISOString().split('T')[0];
var formattedDateTomorrow = tomorrow.toISOString().split('T')[0];
// Attribuez la date formatée à l'attribut min de l'élément input
document.getElementById('dateDebut').min = formattedDateToday;
document.getElementById('dateFin').min = formattedDateTomorrow;
// Attribuez la date formatée à l'attribut min de l'élément input
</script>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
</body>
</html>