diff --git a/build.gradle b/build.gradle
index a804775..53b7de7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -31,6 +31,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.mariadb.jdbc:mariadb-java-client:2.2.0'
+ //Mail
+ implementation 'org.springframework.boot:spring-boot-starter-mail'
+ implementation 'jakarta.mail:jakarta.mail-api'
+ implementation 'jakarta.activation:jakarta.activation-api'
//Securité
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
@@ -40,6 +44,8 @@ dependencies {
//test
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
+ //data
+ implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
}
tasks.named('test') {
diff --git a/src/main/java/fr/eni/enchere/bll/ArticleService.java b/src/main/java/fr/eni/enchere/bll/ArticleService.java
index c64477d..f87c72b 100644
--- a/src/main/java/fr/eni/enchere/bll/ArticleService.java
+++ b/src/main/java/fr/eni/enchere/bll/ArticleService.java
@@ -2,6 +2,8 @@ package fr.eni.enchere.bll;
import fr.eni.enchere.bo.Article;
import fr.eni.enchere.bo.SearchArticleCritere;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import java.util.List;
@@ -13,5 +15,5 @@ public interface ArticleService {
void deleteArticle(int id);
void updateArticle(int id);
List findArticleByTitle(String title);
- List searchArticle(SearchArticleCritere critere);
+ Page searchArticlePageable(SearchArticleCritere critere, Pageable pageable);
}
diff --git a/src/main/java/fr/eni/enchere/bll/ArticleServiceImpl.java b/src/main/java/fr/eni/enchere/bll/ArticleServiceImpl.java
index ffdf089..7f22302 100644
--- a/src/main/java/fr/eni/enchere/bll/ArticleServiceImpl.java
+++ b/src/main/java/fr/eni/enchere/bll/ArticleServiceImpl.java
@@ -3,6 +3,8 @@ package fr.eni.enchere.bll;
import fr.eni.enchere.bo.Article;
import fr.eni.enchere.bo.SearchArticleCritere;
import fr.eni.enchere.dal.ArticleRepository;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
@@ -45,8 +47,9 @@ public class ArticleServiceImpl implements ArticleService{
return articleRepository.findArticleByTitle(title);
}
+
@Override
- public List searchArticle(SearchArticleCritere critere) {
- return articleRepository.searchArticle(critere);
+ public Page searchArticlePageable(SearchArticleCritere critere, Pageable pageable) {
+ return articleRepository.searchArticlePageable(critere, pageable);
}
}
diff --git a/src/main/java/fr/eni/enchere/bll/ForgotPasswordService.java b/src/main/java/fr/eni/enchere/bll/ForgotPasswordService.java
new file mode 100644
index 0000000..0cb80c2
--- /dev/null
+++ b/src/main/java/fr/eni/enchere/bll/ForgotPasswordService.java
@@ -0,0 +1,12 @@
+package fr.eni.enchere.bll;
+
+import fr.eni.enchere.bo.ForgotPassword;
+
+import java.util.List;
+
+public interface ForgotPasswordService {
+
+ ForgotPassword getForgotPassword(String link);
+ void setForgotPassword(String email);
+
+}
diff --git a/src/main/java/fr/eni/enchere/bll/ForgotPasswordServiceImpl.java b/src/main/java/fr/eni/enchere/bll/ForgotPasswordServiceImpl.java
new file mode 100644
index 0000000..129421a
--- /dev/null
+++ b/src/main/java/fr/eni/enchere/bll/ForgotPasswordServiceImpl.java
@@ -0,0 +1,27 @@
+package fr.eni.enchere.bll;
+
+import fr.eni.enchere.bo.ForgotPassword;
+import fr.eni.enchere.dal.ForgotPasswordRepository;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service("ForgotPasswordService")
+public class ForgotPasswordServiceImpl implements ForgotPasswordService {
+
+ private ForgotPasswordRepository forgotPasswordRepository;
+
+ public ForgotPasswordServiceImpl(ForgotPasswordRepository forgotPasswordRepository) {
+ this.forgotPasswordRepository = forgotPasswordRepository;
+ }
+
+ @Override
+ public ForgotPassword getForgotPassword(String link) {
+ return forgotPasswordRepository.getForgotPasswordByLink(link);
+ }
+
+ @Override
+ public void setForgotPassword(String email) {
+ forgotPasswordRepository.setForgotPasswords(email);
+ }
+}
diff --git a/src/main/java/fr/eni/enchere/bll/UserService.java b/src/main/java/fr/eni/enchere/bll/UserService.java
index ac4a39a..9ef0f83 100644
--- a/src/main/java/fr/eni/enchere/bll/UserService.java
+++ b/src/main/java/fr/eni/enchere/bll/UserService.java
@@ -1,6 +1,7 @@
package fr.eni.enchere.bll;
import fr.eni.enchere.bo.UserProfil;
+import org.apache.catalina.User;
import java.util.List;
@@ -8,8 +9,10 @@ public interface UserService {
List listeUtilisateurs();
UserProfil utilisateurById(int id);
UserProfil utilisateurByName(String username);
+ UserProfil utilisateurByEmail(String email);
List listPseudo();
List listEmail();
+ String getUserByMail(String mail);
void setUtilisateur(UserProfil utilisateur);
void setCredit(float credit, int id);
void deleteUtilisateur(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 4bae2df..52a4140 100644
--- a/src/main/java/fr/eni/enchere/bll/UserServiceImpl.java
+++ b/src/main/java/fr/eni/enchere/bll/UserServiceImpl.java
@@ -30,6 +30,11 @@ public class UserServiceImpl implements UserService {
return userRepository.findByUsername(username);
}
+ @Override
+ public UserProfil utilisateurByEmail(String email) {
+ return userRepository.findUserByEmail(email);
+ }
+
@Override
public List listPseudo() {
return userRepository.findAllUsernames();
@@ -40,6 +45,11 @@ public class UserServiceImpl implements UserService {
return userRepository.findAllEmail();
}
+ @Override
+ public String getUserByMail(String mail) {
+ return userRepository.findByEmail(mail);
+ }
+
@Override
public void setUtilisateur(UserProfil utilisateur) {
userRepository.save(utilisateur);
diff --git a/src/main/java/fr/eni/enchere/bo/ForgotPassword.java b/src/main/java/fr/eni/enchere/bo/ForgotPassword.java
new file mode 100644
index 0000000..0a16389
--- /dev/null
+++ b/src/main/java/fr/eni/enchere/bo/ForgotPassword.java
@@ -0,0 +1,64 @@
+package fr.eni.enchere.bo;
+
+import java.time.LocalDate;
+import java.util.Calendar;
+
+public class ForgotPassword {
+
+ private int id;
+ private String email;
+ private String link;
+ private Calendar dateCreate;
+ private Calendar dateExpire;
+
+ public ForgotPassword() {}
+
+ public ForgotPassword(int id, String email, String link, Calendar dateCreate, Calendar dateExpire) {
+ setId(id);
+ setEmail(email);
+ setLink(link);
+ setDateCreate(dateCreate);
+ setDateExpire(dateExpire);
+ }
+
+ public String getLink() {
+ return link;
+ }
+
+ public void setLink(String link) {
+ this.link = link;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public Calendar getDateCreate() {
+ return dateCreate;
+ }
+
+ public void setDateCreate(Calendar dateCreate) {
+ this.dateCreate = dateCreate;
+ }
+
+ public Calendar getDateExpire() {
+ return dateExpire;
+ }
+
+ public void setDateExpire(Calendar dateExpire) {
+ this.dateExpire = dateExpire;
+ }
+
+}
diff --git a/src/main/java/fr/eni/enchere/config/WebConfig.java b/src/main/java/fr/eni/enchere/config/WebConfig.java
index 74388f7..c1e2bfd 100644
--- a/src/main/java/fr/eni/enchere/config/WebConfig.java
+++ b/src/main/java/fr/eni/enchere/config/WebConfig.java
@@ -4,14 +4,9 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil;
import org.apache.commons.validator.routines.EmailValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.AuthenticationException;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.filter.RequestContextFilter;
import org.springframework.web.servlet.LocaleResolver;
-import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
diff --git a/src/main/java/fr/eni/enchere/controllers/AccueilController.java b/src/main/java/fr/eni/enchere/controllers/AccueilController.java
index 21fb32c..31c1773 100644
--- a/src/main/java/fr/eni/enchere/controllers/AccueilController.java
+++ b/src/main/java/fr/eni/enchere/controllers/AccueilController.java
@@ -10,6 +10,8 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
@@ -44,7 +46,7 @@ public class AccueilController {
}
@GetMapping({"/", "/accueil"})
- public String viewAccueil(HttpServletRequest request, @AuthenticationPrincipal UserDetails userDetails, @RequestParam(required = false) String searchTitle, @RequestParam(required = false) Integer searchCategory, Model model, @RequestParam(value = "venteOption", required = false) String[] venteOptions, @RequestParam(value = "achatOption", required = false) String[] achatOptions) {
+ 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) {
model.addAttribute("categories", categorieService.findAllCategories());
model.addAttribute("requestURI", request.getRequestURI());
SearchArticleCritere critere = new SearchArticleCritere();
@@ -55,15 +57,21 @@ public class AccueilController {
}
critere.setVenteOptions(venteOptions);
critere.setAchatOptions(achatOptions);
- model.addAttribute("articles", articleService.searchArticle(critere));
+
+ // Pagination
+ Page articlePage = articleService.searchArticlePageable(critere, PageRequest.of(page, size));
+ model.addAttribute("articles", articlePage.getContent());
+ model.addAttribute("currentPage", page);
+ model.addAttribute("totalPages", articlePage.getTotalPages());
+
return "accueil";
}
@PostMapping("/accueil")
- public String handleSearch(HttpServletRequest request, @AuthenticationPrincipal UserDetails userDetails, @RequestParam("searchTitle") String searchTitle, @RequestParam(value = "searchCategory", required = false) Integer searchCategory, Model model, @RequestParam(value = "venteOption", required = false) String[] venteOptions, @RequestParam(value = "achatOption", required = false) String[] achatOptions ) {
+ 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) {
- return viewAccueil(request, userDetails, searchTitle, searchCategory, model, venteOptions, achatOptions);
+ return viewAccueil(request, userDetails, searchTitle, searchCategory, page, size, model, venteOptions, achatOptions);
}
diff --git a/src/main/java/fr/eni/enchere/controllers/ArticleController.java b/src/main/java/fr/eni/enchere/controllers/ArticleController.java
index 2dbf051..9f0d968 100644
--- a/src/main/java/fr/eni/enchere/controllers/ArticleController.java
+++ b/src/main/java/fr/eni/enchere/controllers/ArticleController.java
@@ -68,6 +68,12 @@ public class ArticleController {
Optional maxMontantEnchere = lastEnchere.stream()
.map(Enchere::getMontantEnchere) // Récupère seulement les montants d'enchère
.max(Float::compareTo);
+ UserProfil currentUser = userService.utilisateurByName(authentication.getName());
+ boolean isArticleCurrentUser = false;
+ if (currentUser.getId() == user.getId()) {
+ isArticleCurrentUser = true;
+ }
+ model.addAttribute("isArticleCurrentUser", isArticleCurrentUser);
model.addAttribute("article", article);
model.addAttribute("username", user);
model.addAttribute("cate", cate.getLibelle());
diff --git a/src/main/java/fr/eni/enchere/controllers/BankController.java b/src/main/java/fr/eni/enchere/controllers/BankController.java
new file mode 100644
index 0000000..bb3b740
--- /dev/null
+++ b/src/main/java/fr/eni/enchere/controllers/BankController.java
@@ -0,0 +1,44 @@
+package fr.eni.enchere.controllers;
+
+import fr.eni.enchere.bll.ArticleService;
+import fr.eni.enchere.bll.UserService;
+import fr.eni.enchere.bo.UserProfil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller()
+@RequestMapping("/bank")
+public class BankController {
+
+ @Autowired
+ private final UserService userService;
+
+ public BankController(UserService userService) {
+ this.userService = userService;
+ }
+
+ @GetMapping("/home")
+ public String homeCredit(Model model) {
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ if (!authentication.getName().equals("anonymousUser")){
+ return "redirect:/accueil";
+ }
+ String username = authentication.getName();
+ UserProfil userProfile = userService.utilisateurByName(username);
+ model.addAttribute("userProfile", userProfile);
+ return "bank";
+ }
+
+ @PostMapping("/checkout")
+ public String addCreditCheckout() {
+
+ return "bank";
+ }
+
+}
diff --git a/src/main/java/fr/eni/enchere/controllers/ForgotPasswordController.java b/src/main/java/fr/eni/enchere/controllers/ForgotPasswordController.java
new file mode 100644
index 0000000..e1b1dca
--- /dev/null
+++ b/src/main/java/fr/eni/enchere/controllers/ForgotPasswordController.java
@@ -0,0 +1,153 @@
+package fr.eni.enchere.controllers;
+
+import fr.eni.enchere.bll.ForgotPasswordService;
+import fr.eni.enchere.bll.UserService;
+import fr.eni.enchere.bo.ForgotPassword;
+import fr.eni.enchere.bo.UserProfil;
+import org.apache.commons.validator.routines.EmailValidator;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.Calendar;
+import java.util.regex.Pattern;
+
+@Controller()
+@RequestMapping("/forgotPassword")
+public class ForgotPasswordController {
+
+ @Autowired
+ private final UserService userService;
+ private EmailValidator emailValidator;
+ private ForgotPasswordService forgotPasswordService;
+
+ public ForgotPasswordController(EmailValidator emailValidator, ForgotPasswordService forgotPasswordService, UserService userService) {
+ this.userService = userService;
+ this.emailValidator = emailValidator;
+ this.forgotPasswordService = forgotPasswordService;
+ }
+
+ @GetMapping
+ public String forgotPassword(Model model, @RequestParam(value = "link", required = false) String link) {
+ // Vérifier si l'utilisateur est déjà authentifié
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ if (!authentication.getName().equals("anonymousUser")){
+ return "redirect:/accueil";
+ }
+ if (link != null) {
+ ForgotPassword forgotPassword = forgotPasswordService.getForgotPassword(link);
+ if (forgotPassword != null) {
+ Calendar dateNow = Calendar.getInstance();
+ if (dateNow.before(forgotPassword.getDateExpire())){
+ return "redirect:/forgotPassword/changePassword?link=" + forgotPassword.getLink();
+ }else{
+ return "redirect:/forgotPassword/changePasswordExpired?link=" + forgotPassword.getLink();
+ }
+ }else{
+ return "redirect:/security/forgotPassword";
+ }
+ }else{
+ return "security/forgotPassword";
+ }
+ }
+
+ @PostMapping
+ public String createLinkForgotPassword(@RequestParam("email") String email) {
+ if (email.isEmpty()){
+ return "redirect:/forgotPassword?error";
+ }else{
+ if (!emailValidator.isValid(email)) {
+ return "redirect:/forgotPassword?error";
+ }
+ }
+ //Vérification de l'email dans la base de donnée
+ if (userService.getUserByMail(email) == null){
+ return "redirect:/forgotPassword?error";
+ }
+ forgotPasswordService.setForgotPassword(email);
+ return "redirect:/forgotPassword?mailSend";
+ }
+
+ @GetMapping("/changePassword")
+ public String forgotPasswordChangePassword(Model model, @RequestParam(value = "link", required = true) String link) {
+ // Vérifier si l'utilisateur est déjà authentifié
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ if (!authentication.getName().equals("anonymousUser")){
+ return "redirect:/accueil";
+ }
+ ForgotPassword forgotPassword = forgotPasswordService.getForgotPassword(link);
+ if (forgotPassword != null) {
+ Calendar dateNow = Calendar.getInstance();
+ if (dateNow.before(forgotPassword.getDateExpire())){
+ return "security/changePassword";
+ }else{
+ return "redirect:/forgotPassword/changePasswordExpired?link=" + forgotPassword.getLink();
+ }
+ }else{
+ return "security/forgotPassword";
+ }
+ }
+
+ @PostMapping("/changePassword/check")
+ public String changePassword(@RequestParam("email") String email,
+ @RequestParam("password") String password,
+ @RequestParam("confirmPassword") String confirmPassword,
+ @RequestParam("link") String link) {
+ ForgotPassword forgotPassword = forgotPasswordService.getForgotPassword(link);
+ if (forgotPassword != null) {
+ Calendar dateNow = Calendar.getInstance();
+ if (dateNow.before(forgotPassword.getDateExpire())){
+ if (email.equalsIgnoreCase(forgotPassword.getEmail())){
+ if (password.equals(confirmPassword)){
+ String passwordRegex = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@?*#$%^&+=_!\\-])(?=\\S+$).{8,}$";
+ Pattern pattern = Pattern.compile(passwordRegex);
+ // Vérifier si le mot de passe correspond à l'expression régulière
+ if (pattern.matcher(password).matches()){
+ UserProfil userForgotPassword = userService.utilisateurByEmail(email);
+ userForgotPassword.setNewPassword(password);
+ userService.setUtilisateur(userForgotPassword);
+ return "redirect:/login";
+ }else{
+ return "redirect:/forgotPassword/changePassword?link=" + forgotPassword.getLink() + "&passwordSecurity";
+ }
+ }else{
+ return "redirect:/forgotPassword/changePassword?link=" + forgotPassword.getLink() + "&passwordNotIdentique";
+ }
+ }else{
+ return "redirect:/forgotPassword/changePassword?link=" + forgotPassword.getLink() + "&emailError";
+ }
+ }else{
+ return "redirect:/forgotPassword/changePasswordExpired?link=" + forgotPassword.getLink();
+ }
+ }else{
+ return "security/forgotPassword";
+ }
+ }
+
+ @GetMapping("/changePasswordExpired")
+ public String forgotPasswordLinkExpired(Model model, @RequestParam(value = "link", required = true) String link) {
+ // Vérifier si l'utilisateur est déjà authentifié
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ if (!authentication.getName().equals("anonymousUser")){
+ return "redirect:/accueil";
+ }
+ ForgotPassword forgotPassword = forgotPasswordService.getForgotPassword(link);
+ if (forgotPassword != null) {
+ Calendar dateNow = Calendar.getInstance();
+ if (dateNow.before(forgotPassword.getDateExpire())){
+ return "redirect:/forgotPassword/changePassword?link=" + forgotPassword.getLink();
+ }else{
+ return "security/changePasswordExpired";
+ }
+ }else{
+ return "security/forgotPassword";
+ }
+ }
+
+}
diff --git a/src/main/java/fr/eni/enchere/controllers/LanguageController.java b/src/main/java/fr/eni/enchere/controllers/LanguageController.java
index 71f4eb3..90549ad 100644
--- a/src/main/java/fr/eni/enchere/controllers/LanguageController.java
+++ b/src/main/java/fr/eni/enchere/controllers/LanguageController.java
@@ -23,7 +23,6 @@ public class LanguageController {
@GetMapping("/change-language")
public String changeLanguage(HttpServletRequest request, HttpServletResponse response, Locale locale) {
LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
- System.out.println(locale.getLanguage());
if (localeResolver != null) {
if (locale.getLanguage().equals("en")) {
localeResolver.setLocale(request, response, Locale.FRENCH); // Changer la langue en français
@@ -31,7 +30,15 @@ public class LanguageController {
localeResolver.setLocale(request, response, Locale.ENGLISH); // Changer la langue en anglais
}
}
- return "redirect:/";
+
+ String referer = request.getHeader("Referer");
+
+ if (referer != null && !referer.isEmpty()) {
+ return "redirect:" + referer;
+ } else {
+ return "redirect:/";
+ }
}
+
}
diff --git a/src/main/java/fr/eni/enchere/dal/ArticleRepository.java b/src/main/java/fr/eni/enchere/dal/ArticleRepository.java
index 61a1bcb..5d6c084 100644
--- a/src/main/java/fr/eni/enchere/dal/ArticleRepository.java
+++ b/src/main/java/fr/eni/enchere/dal/ArticleRepository.java
@@ -2,12 +2,14 @@ package fr.eni.enchere.dal;
import fr.eni.enchere.bo.Article;
import fr.eni.enchere.bo.SearchArticleCritere;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import java.util.List;
public interface ArticleRepository {
List findAllArticle();
- List searchArticle(SearchArticleCritere critere);
+ Page searchArticlePageable(SearchArticleCritere critere, Pageable pageable);
Article findArticleById(int id);
List findArticleByTitle(String title);
int saveArticle(Article article);
diff --git a/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java b/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java
index dc9f0f6..016c4f4 100644
--- a/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java
+++ b/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java
@@ -8,6 +8,9 @@ import fr.eni.enchere.controllers.AccueilController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Primary;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -87,7 +90,7 @@ public class ArticleRepositoryImpl implements ArticleRepository {
}
@Override
- public List searchArticle(SearchArticleCritere critere) {
+ public Page searchArticlePageable(SearchArticleCritere critere, Pageable pageable) {
StringBuilder sql = new StringBuilder("SELECT DISTINCT a.*, u.* FROM ARTICLES_VENDUS a ");
sql.append("JOIN UTILISATEURS u ON a.no_utilisateur = u.no_utilisateur ");
sql.append("LEFT JOIN ENCHERES e ON a.no_article = e.no_article ");
@@ -165,8 +168,104 @@ public class ArticleRepositoryImpl implements ArticleRepository {
sql.append(")");
}
+ System.out.println();
+ // Compte le nombre total d'articles
+ int totalCount = countArticlePageable(critere);
+
+ // Ajoute la pagination à la requête SQL
+ sql.append(" LIMIT ? OFFSET ?");
+ params.add(pageable.getPageSize());
+ params.add(pageable.getOffset());
+
+ // Exécute la requête paginée
List articles = jdbcTemplate.query(sql.toString(), new HomeArticleRowMapper(), params.toArray());
+ // Crée une Page à partir des résultats et des informations de pagination
+ return new PageImpl<>(articles, pageable, totalCount);
+ }
+
+ public int countArticlePageable(SearchArticleCritere critere) {
+ StringBuilder sql = new StringBuilder("SELECT COUNT(a.no_article) FROM ARTICLES_VENDUS a ");
+ sql.append("JOIN UTILISATEURS u ON a.no_utilisateur = u.no_utilisateur ");
+ sql.append("LEFT JOIN ENCHERES e ON a.no_article = e.no_article ");
+ sql.append("WHERE 1 = 1 AND a.isDelete = 0");
+ List
-
-
Liste des catégories modifiées
-
-
-
- | Nom |
- Action |
-
-
-
-
- |
-
- |
-
-
- |
-
-
-
-