filtre articles
This commit is contained in:
@@ -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) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.namedJdbcTemplate = namedJdbcTemplate;
|
||||
@@ -85,38 +103,78 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
params.add('%' + critere.getTitle() + '%');
|
||||
}
|
||||
|
||||
// Ajouter les conditions supplémentaires basées sur les options de vente
|
||||
sql.append(" AND ("); // Début du bloc des conditions supplémentaires
|
||||
boolean isFirstCondition = true; // Pour vérifier la première condition
|
||||
for (String option : critere.getVenteOptions()) {
|
||||
if (option.equals("venteEnCours")) {
|
||||
if (!isFirstCondition) {
|
||||
sql.append(" OR "); // Ajouter un OR si ce n'est pas la première condition
|
||||
if (critere.getVenteOptions() != null && critere.getVenteOptions().length > 0) {
|
||||
sql.append(" AND (");
|
||||
boolean isFirstCondition = true;
|
||||
for (String option : critere.getVenteOptions()) {
|
||||
if (option.equals("venteEnCours")) {
|
||||
if (!isFirstCondition) {
|
||||
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()) ");
|
||||
isFirstCondition = false;
|
||||
}
|
||||
if (option.equals("ventesNonDebutees")) {
|
||||
if (!isFirstCondition) {
|
||||
sql.append(" OR "); // Ajouter un OR si ce n'est pas la première condition
|
||||
if (option.equals("ventesNonDebutees")) {
|
||||
if (!isFirstCondition) {
|
||||
sql.append(" OR ");
|
||||
}
|
||||
sql.append(" (a.date_debut_encheres > NOW()) ");
|
||||
isFirstCondition = false;
|
||||
}
|
||||
sql.append(" (a.date_debut_encheres > NOW()) ");
|
||||
isFirstCondition = false;
|
||||
}
|
||||
if (option.equals("ventesTerminees")) {
|
||||
if (!isFirstCondition) {
|
||||
sql.append(" OR "); // Ajouter un OR si ce n'est pas la première condition
|
||||
if (option.equals("ventesTerminees")) {
|
||||
if (!isFirstCondition) {
|
||||
sql.append(" OR ");
|
||||
}
|
||||
sql.append(" (a.date_fin_encheres < NOW()) ");
|
||||
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
|
||||
public Article findArticleById(int id) {
|
||||
String sql = "SELECT * FROM ARTICLES_VENDUS a WHERE no_article = ?";
|
||||
|
||||
Reference in New Issue
Block a user