From 882d9bede0d6f1b1932bfeda0e2f97bb2ce0b67d Mon Sep 17 00:00:00 2001 From: mepiphana2023 Date: Tue, 30 Apr 2024 13:14:37 +0200 Subject: [PATCH] Un peu de tout --- src/main/java/fr/eni/enchere/bo/Enchere.java | 12 +++- .../controllers/AccueilController.java | 21 +++++-- .../controllers/ArticleController.java | 20 ++++--- .../enchere/controllers/BankController.java | 2 +- .../controllers/ForgotPasswordController.java | 6 +- .../controllers/InscriptionController.java | 2 +- .../enchere/controllers/LoginController.java | 5 +- .../enchere/controllers/ProfilController.java | 18 ++++-- .../enchere/dal/EnchereRepositoryImpl.java | 10 +++- .../enchere/security/WebSecurityConfig.java | 6 +- .../resources/i18n/messages_fr.properties | 12 ++-- src/main/resources/static/css/style.css | 30 +++++++++- src/main/resources/templates/accueil.html | 40 ++++++++----- src/main/resources/templates/admin.html | 1 - src/main/resources/templates/article.html | 56 +++++++++++++------ src/main/resources/templates/bank.html | 2 +- src/main/resources/templates/editProfil.html | 2 +- src/main/resources/templates/inscription.html | 2 +- src/main/resources/templates/modele-page.html | 18 +++--- src/main/resources/templates/newArticle.html | 2 +- 20 files changed, 187 insertions(+), 80 deletions(-) diff --git a/src/main/java/fr/eni/enchere/bo/Enchere.java b/src/main/java/fr/eni/enchere/bo/Enchere.java index f2dd455..4b61c6d 100644 --- a/src/main/java/fr/eni/enchere/bo/Enchere.java +++ b/src/main/java/fr/eni/enchere/bo/Enchere.java @@ -6,14 +6,16 @@ public class Enchere { private int id; private int noUtilisateur; + private String pseudoUtilisateur; private int noArticle; private Date dateEnchere; private float montantEnchere; public Enchere(){} - public Enchere(int noUtilisateur, int noArticle, Date dateEnchere, float montantEnchere) { + public Enchere(int noUtilisateur, int noArticle, String pseudoUtilisateur, Date dateEnchere, float montantEnchere ) { setNoUtilisateur(noUtilisateur); + setPseudoUtilisateur(pseudoUtilisateur); setNoArticle(noArticle); setDateEnchere(dateEnchere); setMontantEnchere(montantEnchere); @@ -58,4 +60,12 @@ public class Enchere { public void setNoUtilisateur(int noUtilisateur) { this.noUtilisateur = noUtilisateur; } + + public String getPseudoUtilisateur() { + return pseudoUtilisateur; + } + + public void setPseudoUtilisateur(String pseudoUtilisateur) { + this.pseudoUtilisateur = pseudoUtilisateur; + } } diff --git a/src/main/java/fr/eni/enchere/controllers/AccueilController.java b/src/main/java/fr/eni/enchere/controllers/AccueilController.java index 31c1773..0bcbb26 100644 --- a/src/main/java/fr/eni/enchere/controllers/AccueilController.java +++ b/src/main/java/fr/eni/enchere/controllers/AccueilController.java @@ -45,8 +45,12 @@ public class AccueilController { this.userService = userService; } - @GetMapping({"/", "/accueil"}) - public String viewAccueil(HttpServletRequest request, @AuthenticationPrincipal UserDetails userDetails, @RequestParam(required = false) String searchTitle, @RequestParam(required = false) Integer searchCategory, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "6") int size, Model model, @RequestParam(value = "venteOption", required = false) String[] venteOptions, @RequestParam(value = "achatOption", required = false) String[] achatOptions) { + @GetMapping({"/", "/enchere"}) + public String viewAccueil(HttpServletRequest request, @AuthenticationPrincipal UserDetails userDetails, + @RequestParam(required = false) String searchTitle, @RequestParam(required = false) Integer searchCategory, + @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "6") int size, Model model, + @RequestParam(value = "venteOption", required = false) String[] venteOptions, + @RequestParam(value = "achatOption", required = false) String[] achatOptions) { model.addAttribute("categories", categorieService.findAllCategories()); model.addAttribute("requestURI", request.getRequestURI()); SearchArticleCritere critere = new SearchArticleCritere(); @@ -58,16 +62,25 @@ public class AccueilController { critere.setVenteOptions(venteOptions); critere.setAchatOptions(achatOptions); + // Si la page est 1 ou plus, décrémentez la valeur de la page de 1 + if (page > 0) { + page -= 1; + } + // Pagination Page
articlePage = articleService.searchArticlePageable(critere, PageRequest.of(page, size)); model.addAttribute("articles", articlePage.getContent()); - model.addAttribute("currentPage", page); + + // Ajoutez 1 à la valeur de la page actuelle pour l'affichage dans la vue + int currentPage = page + 1; + model.addAttribute("currentPage", currentPage); + model.addAttribute("totalPages", articlePage.getTotalPages()); return "accueil"; } - @PostMapping("/accueil") + @PostMapping("/enchere") public String handleSearch(HttpServletRequest request, @AuthenticationPrincipal UserDetails userDetails, @RequestParam(required = false) String searchTitle, @RequestParam(required = false) Integer searchCategory, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "6") int size, Model model, @RequestParam(value = "venteOption", required = false) String[] venteOptions, @RequestParam(value = "achatOption", required = false) String[] achatOptions) { diff --git a/src/main/java/fr/eni/enchere/controllers/ArticleController.java b/src/main/java/fr/eni/enchere/controllers/ArticleController.java index dd6f8d9..6665813 100644 --- a/src/main/java/fr/eni/enchere/controllers/ArticleController.java +++ b/src/main/java/fr/eni/enchere/controllers/ArticleController.java @@ -21,11 +21,9 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.regex.Pattern; +import java.util.stream.Collectors; @Controller() @RequestMapping("/article") @@ -50,7 +48,7 @@ public class ArticleController { @GetMapping public String viewArticle(Model model) { - return "redirect:/accueil"; + return "redirect:/enchere"; } //Affichage d'un article @@ -65,14 +63,20 @@ public class ArticleController { 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 + .map(Enchere::getMontantEnchere) .max(Float::compareTo); UserProfil currentUser = userService.utilisateurByName(authentication.getName()); boolean isArticleCurrentUser = false; if (currentUser.getId() == user.getId()) { isArticleCurrentUser = true; } + + lastEnchere = lastEnchere.stream() + .sorted(Comparator.comparing(Enchere::getMontantEnchere).reversed()) + .collect(Collectors.toList()); + model.addAttribute("encheres", lastEnchere); model.addAttribute("isArticleCurrentUser", isArticleCurrentUser); model.addAttribute("article", article); model.addAttribute("username", user); @@ -89,7 +93,7 @@ public class ArticleController { } return "article"; } else { - return "redirect:/accueil"; + return "redirect:/enchere"; } } @@ -229,7 +233,7 @@ public class ArticleController { //Validation du formulaire retrait.setNumArticle(articleService.saveArticle(article)); retraitService.setRetrait(retrait); - return "redirect:/accueil"; + return "redirect:/enchere"; } //Update d'un article diff --git a/src/main/java/fr/eni/enchere/controllers/BankController.java b/src/main/java/fr/eni/enchere/controllers/BankController.java index bb3b740..9382191 100644 --- a/src/main/java/fr/eni/enchere/controllers/BankController.java +++ b/src/main/java/fr/eni/enchere/controllers/BankController.java @@ -27,7 +27,7 @@ public class BankController { public String homeCredit(Model model) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!authentication.getName().equals("anonymousUser")){ - return "redirect:/accueil"; + return "redirect:/enchere"; } String username = authentication.getName(); UserProfil userProfile = userService.utilisateurByName(username); diff --git a/src/main/java/fr/eni/enchere/controllers/ForgotPasswordController.java b/src/main/java/fr/eni/enchere/controllers/ForgotPasswordController.java index e1b1dca..4091e27 100644 --- a/src/main/java/fr/eni/enchere/controllers/ForgotPasswordController.java +++ b/src/main/java/fr/eni/enchere/controllers/ForgotPasswordController.java @@ -38,7 +38,7 @@ public class ForgotPasswordController { // Vérifier si l'utilisateur est déjà authentifié Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!authentication.getName().equals("anonymousUser")){ - return "redirect:/accueil"; + return "redirect:/enchere"; } if (link != null) { ForgotPassword forgotPassword = forgotPasswordService.getForgotPassword(link); @@ -79,7 +79,7 @@ public class ForgotPasswordController { // Vérifier si l'utilisateur est déjà authentifié Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!authentication.getName().equals("anonymousUser")){ - return "redirect:/accueil"; + return "redirect:/enchere"; } ForgotPassword forgotPassword = forgotPasswordService.getForgotPassword(link); if (forgotPassword != null) { @@ -135,7 +135,7 @@ public class ForgotPasswordController { // Vérifier si l'utilisateur est déjà authentifié Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!authentication.getName().equals("anonymousUser")){ - return "redirect:/accueil"; + return "redirect:/enchere"; } ForgotPassword forgotPassword = forgotPasswordService.getForgotPassword(link); if (forgotPassword != null) { diff --git a/src/main/java/fr/eni/enchere/controllers/InscriptionController.java b/src/main/java/fr/eni/enchere/controllers/InscriptionController.java index eb3d513..8004b20 100644 --- a/src/main/java/fr/eni/enchere/controllers/InscriptionController.java +++ b/src/main/java/fr/eni/enchere/controllers/InscriptionController.java @@ -52,7 +52,7 @@ public class InscriptionController { // Vérifier si l'utilisateur est déjà authentifié Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!authentication.getName().equals("anonymousUser")){ - return "redirect:/accueil"; + return "redirect:/enchere"; } model.addAttribute("userProfile", new UserProfil()); return "inscription"; diff --git a/src/main/java/fr/eni/enchere/controllers/LoginController.java b/src/main/java/fr/eni/enchere/controllers/LoginController.java index 142ce6f..f8063bb 100644 --- a/src/main/java/fr/eni/enchere/controllers/LoginController.java +++ b/src/main/java/fr/eni/enchere/controllers/LoginController.java @@ -24,10 +24,9 @@ public class LoginController { @GetMapping("/login") public String login(Model modele) { - // Vérifier si l'utilisateur est déjà authentifié Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (!authentication.getName().equals("anonymousUser")){ - return "redirect:/accueil"; + return "redirect:/enchere"; } return "security/login"; } @@ -36,7 +35,7 @@ public class LoginController { public String login(@RequestParam("username") String username, @RequestParam("password") String password) { UserProfil user = userService.utilisateurByName(username); if (user != null && user.getPassword().equals(password)) { - return "redirect:/accueil"; + return "redirect:/enchere"; } else { return "redirect:/security/login?error"; } diff --git a/src/main/java/fr/eni/enchere/controllers/ProfilController.java b/src/main/java/fr/eni/enchere/controllers/ProfilController.java index ea9d2bf..1535397 100644 --- a/src/main/java/fr/eni/enchere/controllers/ProfilController.java +++ b/src/main/java/fr/eni/enchere/controllers/ProfilController.java @@ -6,10 +6,7 @@ import org.springframework.ui.Model; import fr.eni.enchere.bll.UserService; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.*; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -87,7 +84,7 @@ public class ProfilController { //Supprimer le compte userService.deleteUtilisateur(userProfile.getId()); //ATTENTION AJOUTER LA DECONNEXION - return "redirect:/accueil"; + return "redirect:/enchere"; } @PostMapping("/updateUser") @@ -127,4 +124,15 @@ public class ProfilController { return "accueil"; } } + + @GetMapping("/showProfil") + public String showOtherProfil(@RequestParam("userPseudo") String userPseudo, Model model) { + + model.addAttribute("userProfil", userService.utilisateurByName(userPseudo)); + + + + return "showProfil"; + } + } diff --git a/src/main/java/fr/eni/enchere/dal/EnchereRepositoryImpl.java b/src/main/java/fr/eni/enchere/dal/EnchereRepositoryImpl.java index b82a99c..55390b4 100644 --- a/src/main/java/fr/eni/enchere/dal/EnchereRepositoryImpl.java +++ b/src/main/java/fr/eni/enchere/dal/EnchereRepositoryImpl.java @@ -1,6 +1,10 @@ package fr.eni.enchere.dal; +import fr.eni.enchere.bll.EnchereService; +import fr.eni.enchere.bll.UserService; import fr.eni.enchere.bo.Enchere; +import fr.eni.enchere.bo.UserProfil; +import org.apache.catalina.User; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.support.GeneratedKeyHolder; @@ -14,9 +18,11 @@ import java.util.List; public class EnchereRepositoryImpl implements EnchereRepository { private final JdbcTemplate jdbcTemplate; + private UserService userService; - public EnchereRepositoryImpl(JdbcTemplate jdbcTemplate) { + public EnchereRepositoryImpl(JdbcTemplate jdbcTemplate, UserService userService) { this.jdbcTemplate = jdbcTemplate; + this.userService = userService; } public class EnchereRowMapper implements RowMapper { @@ -27,6 +33,8 @@ public class EnchereRepositoryImpl implements EnchereRepository { enchere.setNoArticle(rs.getInt("no_article")); enchere.setMontantEnchere(rs.getInt("montant_enchere")); enchere.setDateEnchere(rs.getDate("date_enchere")); + UserProfil user = userService.utilisateurById(rs.getInt("no_utilisateur")); + enchere.setPseudoUtilisateur(user.getPseudo()); return enchere; } } diff --git a/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java b/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java index c48d70b..ebd4b22 100644 --- a/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java +++ b/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java @@ -19,17 +19,17 @@ public class WebSecurityConfig{ @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests((requests) -> requests - .requestMatchers("/","/accueil", "/login", "/forgotPassword/**", "/inscription/**", "/searchArticle", "/article/show", "/change-language").permitAll() + .requestMatchers("/","/enchere", "/login", "/forgotPassword/**", "/inscription/**", "/searchArticle", "/article/show", "/change-language").permitAll() .requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**", "/assets/**", "/i18n/**").permitAll() .requestMatchers("/profil/**", "/article/new/**", "/article/update", "/article/delete").authenticated() .requestMatchers("/admin").hasRole("ADMIN") .anyRequest().authenticated()) .formLogin((form) -> form .loginPage("/login") - .defaultSuccessUrl("/", true)) + .defaultSuccessUrl("/enchere", true)) .logout((logout) -> logout .clearAuthentication(true).invalidateHttpSession(true) - .deleteCookies("JSESSIONID").logoutSuccessUrl("/login?logout") + .deleteCookies("JSESSIONID").logoutSuccessUrl("/enchere") .logoutRequestMatcher(new AntPathRequestMatcher("/logout")).permitAll()); return http.build(); diff --git a/src/main/resources/i18n/messages_fr.properties b/src/main/resources/i18n/messages_fr.properties index dac41d3..0b6ed9c 100644 --- a/src/main/resources/i18n/messages_fr.properties +++ b/src/main/resources/i18n/messages_fr.properties @@ -109,12 +109,12 @@ 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.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 diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index 5e6a048..fe2fcd0 100644 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -1,16 +1,21 @@ +/* Classe utilitaire Flexbox */ .v-center { display: flex; align-items: center; height: 100%; } + +/* Classe utilitaire pour supprimer la décoration du texte */ .text-decoration-none { text-decoration: none !important; } + +/* Classe utilitaire pour la couleur du texte */ .text-dark { color: black !important; } - +/* Styles de la carte d'article */ .card-article { transition: transform 0.3s ease; } @@ -19,18 +24,39 @@ transform: scale(1.05); } +/* Styles du bouton de langue */ #languageButton { margin-right: 20px; /* Espacement du bouton par rapport à la droite */ } - +/* Styles de la barre de navigation */ .navbar-nav { margin-right: 10px; } + .navbar-nav .nav-item.active .nav-link { color: white; } +/* Styles du conteneur principal */ #container-main { padding-bottom: 40px; } + +/* Styles du bouton principal */ +.btn-primary { + background-color: #0E314C; + border-color: #0E314C; +} + +.btn-primary:hover { + background-color: #1B4463 !important; + color: #EDCE86 !important; +} + +.btn-primary:after { + color: #1B4463 !important; + border-color: #EDCE86 !important; + background: #EDCE86 !important; + outline-color: #EDCE86 !important; +} diff --git a/src/main/resources/templates/accueil.html b/src/main/resources/templates/accueil.html index 5ceb2c8..e4f81dc 100644 --- a/src/main/resources/templates/accueil.html +++ b/src/main/resources/templates/accueil.html @@ -12,7 +12,7 @@
-
+
@@ -128,10 +128,23 @@

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

@@ -150,30 +163,29 @@
  • - +
  • -
  • +
  • - - - -
  • - + + +
  • +
  • -
  • +
  • @@ -182,7 +194,7 @@
  • - + diff --git a/src/main/resources/templates/admin.html b/src/main/resources/templates/admin.html index 8f21436..f720a56 100644 --- a/src/main/resources/templates/admin.html +++ b/src/main/resources/templates/admin.html @@ -2,7 +2,6 @@ -
    diff --git a/src/main/resources/templates/article.html b/src/main/resources/templates/article.html index 8761959..680914d 100644 --- a/src/main/resources/templates/article.html +++ b/src/main/resources/templates/article.html @@ -4,45 +4,45 @@ -
    -
    -
    +
    +
    +

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

    -
    +
    - +
    -
    +
    - + + +
    -
    +
    -
    +
    -
    +
    - - -
    +
    @@ -60,6 +60,30 @@
    +
    +
    +
    Enchérisseurs
    + + + + + + + + + + + + + +
    PseudoMontant Enchère
    + + + + + +
    +
    diff --git a/src/main/resources/templates/bank.html b/src/main/resources/templates/bank.html index b0c4d12..66cd939 100644 --- a/src/main/resources/templates/bank.html +++ b/src/main/resources/templates/bank.html @@ -74,7 +74,7 @@

    -
    +