diff --git a/src/main/java/fr/eni/enchere/bll/CategorieServiceImpl.java b/src/main/java/fr/eni/enchere/bll/CategorieServiceImpl.java index 2039e8a..8a9c358 100644 --- a/src/main/java/fr/eni/enchere/bll/CategorieServiceImpl.java +++ b/src/main/java/fr/eni/enchere/bll/CategorieServiceImpl.java @@ -35,7 +35,7 @@ public class CategorieServiceImpl implements CategorieService { @Override public void updateCategorie(Categorie categorie) { - + categorieRepository.updateCategorie(categorie); } @Override diff --git a/src/main/java/fr/eni/enchere/bll/UserService.java b/src/main/java/fr/eni/enchere/bll/UserService.java index ac9a9fb..1ea8f02 100644 --- a/src/main/java/fr/eni/enchere/bll/UserService.java +++ b/src/main/java/fr/eni/enchere/bll/UserService.java @@ -11,6 +11,7 @@ public interface UserService { List listPseudo(); List listEmail(); void setUtilisateur(UserProfil utilisateur); + void setCredit(float credit, int id); void deleteUtilisateur(int id); void disableUtilisateur(int id); } diff --git a/src/main/java/fr/eni/enchere/bll/UserServiceImpl.java b/src/main/java/fr/eni/enchere/bll/UserServiceImpl.java index 7bc026c..35a229f 100644 --- a/src/main/java/fr/eni/enchere/bll/UserServiceImpl.java +++ b/src/main/java/fr/eni/enchere/bll/UserServiceImpl.java @@ -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); diff --git a/src/main/java/fr/eni/enchere/controllers/AdminController.java b/src/main/java/fr/eni/enchere/controllers/AdminController.java index 3f93934..aab7d14 100644 --- a/src/main/java/fr/eni/enchere/controllers/AdminController.java +++ b/src/main/java/fr/eni/enchere/controllers/AdminController.java @@ -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"; } diff --git a/src/main/java/fr/eni/enchere/controllers/ArticleController.java b/src/main/java/fr/eni/enchere/controllers/ArticleController.java index 08de78a..4e90ad0 100644 --- a/src/main/java/fr/eni/enchere/controllers/ArticleController.java +++ b/src/main/java/fr/eni/enchere/controllers/ArticleController.java @@ -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 lastEnchere = this.enchereService.enchereByArticle(article.getId()); + Optional 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 errors = (List) 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"; + } + } diff --git a/src/main/java/fr/eni/enchere/controllers/EnchereController.java b/src/main/java/fr/eni/enchere/controllers/EnchereController.java index 155ee41..48066c4 100644 --- a/src/main/java/fr/eni/enchere/controllers/EnchereController.java +++ b/src/main/java/fr/eni/enchere/controllers/EnchereController.java @@ -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 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; } diff --git a/src/main/java/fr/eni/enchere/dal/CategorieRepositoryImpl.java b/src/main/java/fr/eni/enchere/dal/CategorieRepositoryImpl.java index f515228..9bdfed6 100644 --- a/src/main/java/fr/eni/enchere/dal/CategorieRepositoryImpl.java +++ b/src/main/java/fr/eni/enchere/dal/CategorieRepositoryImpl.java @@ -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); } } diff --git a/src/main/java/fr/eni/enchere/dal/EnchereRepositoryImpl.java b/src/main/java/fr/eni/enchere/dal/EnchereRepositoryImpl.java index 54b1b18..b82a99c 100644 --- a/src/main/java/fr/eni/enchere/dal/EnchereRepositoryImpl.java +++ b/src/main/java/fr/eni/enchere/dal/EnchereRepositoryImpl.java @@ -43,7 +43,9 @@ public class EnchereRepositoryImpl implements EnchereRepository { @Override public List findByIdArticle(int idArticle) { - return List.of(); + String sql = "SELECT * FROM ENCHERES WHERE no_article = ?"; + List encheres = jdbcTemplate.query(sql, new EnchereRowMapper(), idArticle); + return encheres; } @Override diff --git a/src/main/java/fr/eni/enchere/dal/UserRepository.java b/src/main/java/fr/eni/enchere/dal/UserRepository.java index 3f67a6a..ce76f1e 100644 --- a/src/main/java/fr/eni/enchere/dal/UserRepository.java +++ b/src/main/java/fr/eni/enchere/dal/UserRepository.java @@ -11,6 +11,7 @@ public interface UserRepository { List findAllUsernames(); List findAllEmail(); void save(UserProfil utilisateur); + void updateCredit(float credit, int id); void delete(int id); void disable(int id); } diff --git a/src/main/java/fr/eni/enchere/dal/UserRepositoryImpl.java b/src/main/java/fr/eni/enchere/dal/UserRepositoryImpl.java index d96c466..a37e7fd 100644 --- a/src/main/java/fr/eni/enchere/dal/UserRepositoryImpl.java +++ b/src/main/java/fr/eni/enchere/dal/UserRepositoryImpl.java @@ -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 = ?"; diff --git a/src/main/java/fr/eni/enchere/interceptor/UserInterceptor.java b/src/main/java/fr/eni/enchere/interceptor/UserInterceptor.java index b58d0ed..570a680 100644 --- a/src/main/java/fr/eni/enchere/interceptor/UserInterceptor.java +++ b/src/main/java/fr/eni/enchere/interceptor/UserInterceptor.java @@ -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); } } } diff --git a/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java b/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java index e48eccb..f1e366c 100644 --- a/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java +++ b/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java @@ -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; diff --git a/src/main/resources/i18n/messages_fr.properties b/src/main/resources/i18n/messages_fr.properties index a2dbae7..99c630e 100644 --- a/src/main/resources/i18n/messages_fr.properties +++ b/src/main/resources/i18n/messages_fr.properties @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/src/main/resources/templates/accueil.html b/src/main/resources/templates/accueil.html index 1b3ffcf..c07b3ed 100644 --- a/src/main/resources/templates/accueil.html +++ b/src/main/resources/templates/accueil.html @@ -52,22 +52,22 @@
- +
- +
- +
- +
@@ -76,22 +76,22 @@
- +
- +
- +
- +
@@ -108,7 +108,7 @@
- +
@@ -126,16 +126,16 @@
-
Nom de l'article
-

Description

+
+

-
Prix de vente:
-
Vendeur:
+
+

-
Fin de l'enchère:
+
diff --git a/src/main/resources/templates/admin.html b/src/main/resources/templates/admin.html index 37b1256..cf22666 100644 --- a/src/main/resources/templates/admin.html +++ b/src/main/resources/templates/admin.html @@ -1,71 +1,71 @@ - +
-

Liste des catégories modifiées

+

Liste des catégories modifiées

- - - - + + + + - - - - + + + +
NomAction
NomAction
-
- - - -
-
-
- - -
-
+
+ + + +
+
+
+ + +
+
- +
-

Liste des utilisateurs

+

Liste des utilisateurs

- - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + +
IDPseudoNomPrénomEmailAction
IDPseudoNomPrénomEmailAction
-
- - -
-
- - -
-
+
+ + +
+
+ + +
+
diff --git a/src/main/resources/templates/article.html b/src/main/resources/templates/article.html index 5487395..cfdecd9 100644 --- a/src/main/resources/templates/article.html +++ b/src/main/resources/templates/article.html @@ -1,68 +1,68 @@ - + - -
-
-
-
-
-

Article

+ +
+
+
+
+
+

+
+
+
+
+ image-vente
-
-
-
- image-vente -
-
-
-

-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - -
- - -
-
- - - - +
+
+

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+ + +
+ + + + +
- - -
-
+ +
- +
+
+ diff --git a/src/main/resources/templates/editArticle.html b/src/main/resources/templates/editArticle.html new file mode 100644 index 0000000..5423f26 --- /dev/null +++ b/src/main/resources/templates/editArticle.html @@ -0,0 +1,26 @@ + + + + + Title + + +
+

+
+
+ + +
+
+ + +
Veuillez sélectionner une catégorie.
+
+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/modele-page.html b/src/main/resources/templates/modele-page.html index 96aa420..fc45ee0 100644 --- a/src/main/resources/templates/modele-page.html +++ b/src/main/resources/templates/modele-page.html @@ -21,35 +21,38 @@
@@ -66,8 +69,7 @@
ENI-Encheres
-

- 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. +

@@ -76,13 +78,13 @@ Menu

- Encheres +

- Vendre un article +

- Mon profile +

diff --git a/src/main/resources/templates/newArticle.html b/src/main/resources/templates/newArticle.html index abe0abf..a3a0669 100644 --- a/src/main/resources/templates/newArticle.html +++ b/src/main/resources/templates/newArticle.html @@ -2,97 +2,92 @@ + -
-

Nouvelle vente

-
- -
- - +
+

Nouvelle vente

+ +
+ + +
Ce champ est requis.
- -
- - +
+ + +
Ce champ est requis.
- -
- - +
Veuillez sélectionner une catégorie.
- -
- - +
+ +
- -
- - +
+ + +
Ce champ est requis.
- -
- - +
+ + +
Ce champ est requis.
- -
- - +
+ + +
Ce champ est requis.
- -

Retrait

-
- - +

Retrait

+
+ + +
Ce champ est requis.
-
- - +
+ + +
Ce champ est requis.
-
- - +
+ + +
Ce champ est requis.
- -
- -
+ - -
+

-
- + +
+ +