filtre articles
This commit is contained in:
@@ -5,6 +5,7 @@ public class SearchArticleCritere {
|
|||||||
Integer noCategorie;
|
Integer noCategorie;
|
||||||
Integer noVendeur;
|
Integer noVendeur;
|
||||||
String[] venteOptions;
|
String[] venteOptions;
|
||||||
|
String[] achatOptions;
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
@@ -37,4 +38,12 @@ public class SearchArticleCritere {
|
|||||||
public void setVenteOptions(String[] venteOptions) {
|
public void setVenteOptions(String[] venteOptions) {
|
||||||
this.venteOptions = venteOptions;
|
this.venteOptions = venteOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] getAchatOptions() {
|
||||||
|
return achatOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAchatOptions(String[] achatOptions) {
|
||||||
|
this.achatOptions = achatOptions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,23 +44,24 @@ public class AccueilController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping({"/", "/accueil"})
|
@GetMapping({"/", "/accueil"})
|
||||||
public String viewAccueil(@AuthenticationPrincipal UserDetails userDetails, @RequestParam(required = false) String searchTitle, @RequestParam(required = false) Integer searchCategory, Model model, @RequestParam(value = "venteOption", required = false) String[] venteOptions) {
|
public String viewAccueil(@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) {
|
||||||
model.addAttribute("categories", categorieService.findAllCategories());
|
model.addAttribute("categories", categorieService.findAllCategories());
|
||||||
System.out.println("" + model.getAttribute("venteOption"));
|
System.out.println("" + Arrays.toString(venteOptions));
|
||||||
SearchArticleCritere critere = new SearchArticleCritere();
|
SearchArticleCritere critere = new SearchArticleCritere();
|
||||||
critere.setNoCategorie(searchCategory);
|
critere.setNoCategorie(searchCategory);
|
||||||
critere.setTitle(searchTitle);
|
critere.setTitle(searchTitle);
|
||||||
critere.setNoVendeur(userService.utilisateurByName(userDetails.getUsername()).getId());
|
critere.setNoVendeur(userService.utilisateurByName(userDetails.getUsername()).getId());
|
||||||
critere.setVenteOptions(venteOptions);
|
critere.setVenteOptions(venteOptions);
|
||||||
|
critere.setAchatOptions(venteOptions);
|
||||||
model.addAttribute("articles", articleService.searchArticle(critere));
|
model.addAttribute("articles", articleService.searchArticle(critere));
|
||||||
return "accueil";
|
return "accueil";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/accueil")
|
@PostMapping("/accueil")
|
||||||
public String handleSearch(@AuthenticationPrincipal UserDetails userDetails, @RequestParam("searchTitle") String searchTitle, @RequestParam(value = "searchCategory", required = false) Integer searchCategory, Model model, @RequestParam(value = "venteOption", required = false) String[] venteOptions ) {
|
public String handleSearch(@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 ) {
|
||||||
|
|
||||||
|
|
||||||
return viewAccueil(userDetails, searchTitle, searchCategory, model, venteOptions);
|
return viewAccueil(userDetails, searchTitle, searchCategory, model, venteOptions, achatOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,24 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class HomeArticleRowMapper implements RowMapper<Article> {
|
||||||
|
@Override
|
||||||
|
public Article mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||||
|
Article article = new Article();
|
||||||
|
article.setId(rs.getInt("a.no_article"));
|
||||||
|
article.setNom(rs.getString("a.nom_article"));
|
||||||
|
article.setDesc(rs.getString("a.description"));
|
||||||
|
article.setDateDebutEnch(rs.getDate("a.date_debut_encheres"));
|
||||||
|
article.setDateFinEnch(rs.getDate("a.date_fin_encheres"));
|
||||||
|
article.setPrixInitial(rs.getFloat("a.prix_initial"));
|
||||||
|
article.setPrixVente(rs.getFloat("a.prix_vente"));
|
||||||
|
article.setNoUtilisateur(rs.getInt("u.no_utilisateur"));
|
||||||
|
article.setPseudoUtilisateur(rs.getString("u.pseudo"));
|
||||||
|
article.setNumCategorie(rs.getInt("a.no_categorie"));
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ArticleRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate, UserService userService) {
|
public ArticleRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate, UserService userService) {
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
this.namedJdbcTemplate = namedJdbcTemplate;
|
this.namedJdbcTemplate = namedJdbcTemplate;
|
||||||
@@ -85,38 +103,78 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
|||||||
params.add('%' + critere.getTitle() + '%');
|
params.add('%' + critere.getTitle() + '%');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajouter les conditions supplémentaires basées sur les options de vente
|
if (critere.getVenteOptions() != null && critere.getVenteOptions().length > 0) {
|
||||||
sql.append(" AND ("); // Début du bloc des conditions supplémentaires
|
sql.append(" AND (");
|
||||||
boolean isFirstCondition = true; // Pour vérifier la première condition
|
boolean isFirstCondition = true;
|
||||||
for (String option : critere.getVenteOptions()) {
|
for (String option : critere.getVenteOptions()) {
|
||||||
if (option.equals("venteEnCours")) {
|
if (option.equals("venteEnCours")) {
|
||||||
if (!isFirstCondition) {
|
if (!isFirstCondition) {
|
||||||
sql.append(" OR "); // Ajouter un OR si ce n'est pas la première condition
|
sql.append(" OR ");
|
||||||
|
}
|
||||||
|
sql.append(" (a.date_debut_encheres <= NOW() AND a.date_fin_encheres >= NOW()) ");
|
||||||
|
isFirstCondition = false;
|
||||||
}
|
}
|
||||||
sql.append(" (a.date_debut_encheres <= NOW() AND a.date_fin_encheres >= NOW()) ");
|
if (option.equals("ventesNonDebutees")) {
|
||||||
isFirstCondition = false;
|
if (!isFirstCondition) {
|
||||||
}
|
sql.append(" OR ");
|
||||||
if (option.equals("ventesNonDebutees")) {
|
}
|
||||||
if (!isFirstCondition) {
|
sql.append(" (a.date_debut_encheres > NOW()) ");
|
||||||
sql.append(" OR "); // Ajouter un OR si ce n'est pas la première condition
|
isFirstCondition = false;
|
||||||
}
|
}
|
||||||
sql.append(" (a.date_debut_encheres > NOW()) ");
|
if (option.equals("ventesTerminees")) {
|
||||||
isFirstCondition = false;
|
if (!isFirstCondition) {
|
||||||
}
|
sql.append(" OR ");
|
||||||
if (option.equals("ventesTerminees")) {
|
}
|
||||||
if (!isFirstCondition) {
|
sql.append(" (a.date_fin_encheres < NOW()) ");
|
||||||
sql.append(" OR "); // Ajouter un OR si ce n'est pas la première condition
|
isFirstCondition = false;
|
||||||
}
|
}
|
||||||
sql.append(" (a.date_fin_encheres < NOW()) ");
|
|
||||||
isFirstCondition = false;
|
|
||||||
}
|
}
|
||||||
|
sql.append(") AND a.no_utilisateur = ?");
|
||||||
|
params.add(critere.getNoVendeur());
|
||||||
}
|
}
|
||||||
sql.append(")"); // Fin du bloc des conditions supplémentaires
|
|
||||||
|
|
||||||
return jdbcTemplate.query(sql.toString(), new ArticleRowMapper(), params.toArray());
|
if (critere.getAchatOptions() != null && critere.getAchatOptions().length > 0) {
|
||||||
|
sql.append(" AND (");
|
||||||
|
boolean isFirstCondition = true;
|
||||||
|
for (String option : critere.getAchatOptions()) {
|
||||||
|
if (option.equals("encheresOuvertes")) {
|
||||||
|
if (!isFirstCondition) {
|
||||||
|
sql.append(" OR ");
|
||||||
|
}
|
||||||
|
sql.append(" (a.date_debut_encheres <= NOW() AND a.date_fin_encheres >= NOW()) ");
|
||||||
|
isFirstCondition = false;
|
||||||
|
}
|
||||||
|
if (option.equals("enchereEnCours")) {
|
||||||
|
if (!isFirstCondition) {
|
||||||
|
sql.append(" OR ");
|
||||||
|
}
|
||||||
|
sql.append(" /* Ajoutez votre condition ici */ ");
|
||||||
|
isFirstCondition = false;
|
||||||
|
}
|
||||||
|
if (option.equals("enchereRemportees")) {
|
||||||
|
if (!isFirstCondition) {
|
||||||
|
sql.append(" OR ");
|
||||||
|
}
|
||||||
|
sql.append(" /* Ajoutez votre condition ici */ ");
|
||||||
|
isFirstCondition = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sql.append(") AND a.no_utilisateur = ?");
|
||||||
|
params.add(critere.getNoVendeur());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Article> articles = jdbcTemplate.query(sql.toString(), new HomeArticleRowMapper(), params.toArray());
|
||||||
|
|
||||||
|
for (Article article : articles) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return articles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Article findArticleById(int id) {
|
public Article findArticleById(int id) {
|
||||||
String sql = "SELECT * FROM ARTICLES_VENDUS a WHERE no_article = ?";
|
String sql = "SELECT * FROM ARTICLES_VENDUS a WHERE no_article = ?";
|
||||||
|
|||||||
@@ -71,11 +71,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input class="form-check-input" type="checkbox" th:name="venteOption" id="ventesNonDebutees" th:value="ventesNonDebutees" disabled>
|
<input class="form-check-input" type="checkbox" th:name="venteOption" id="ventesNonDebutees" th:value="ventesNonDebutees" disabled>
|
||||||
<label class="form-check-label" for="ventesNonDebutees">Ventes non débutées</label>
|
<label class="form-check-label" for="ventesNonDebutees">Mes ventes non débutées</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input class="form-check-input" type="checkbox" th:name="venteOption" id="ventesTerminees" th:value="ventesTerminees" disabled>
|
<input class="form-check-input" type="checkbox" th:name="venteOption" id="ventesTerminees" th:value="ventesTerminees" disabled>
|
||||||
<label class="form-check-label" for="ventesTerminees">Ventes terminées</label>
|
<label class="form-check-label" for="ventesTerminees">Mes ventes terminées</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user