Merge branch 'refs/heads/marvin'
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.SearchArticleCritere;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ArticleRepository {
|
||||
List<Article> findAllArticle();
|
||||
List<Article> searchArticle(SearchArticleCritere critere);
|
||||
Article findArticleById(int id);
|
||||
List<Article> findArticleByTitle(String title);
|
||||
void saveArticle(Article article);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.SearchArticleCritere;
|
||||
import fr.eni.enchere.controllers.AccueilController;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -12,6 +13,7 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@@ -51,6 +53,24 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
return articles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Article> searchArticle(SearchArticleCritere critere) {
|
||||
StringBuilder sql = new StringBuilder("SELECT * FROM ARTICLES_VENDUS WHERE 1 = 1");
|
||||
|
||||
List<Object> params = new ArrayList<>();
|
||||
|
||||
if (critere.getNoCategorie() != null) {
|
||||
sql.append(" AND no_categorie = ?");
|
||||
params.add(critere.getNoCategorie());
|
||||
}
|
||||
if (critere.getTitle() != null && !critere.getTitle().isEmpty()) {
|
||||
sql.append(" AND nom_article LIKE ?");
|
||||
params.add( '%' + critere.getTitle() + "%");
|
||||
}
|
||||
|
||||
return jdbcTemplate.query(sql.toString(), new ArticleRowMapper(), params.toArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Article findArticleById(int id) {
|
||||
return null;
|
||||
@@ -58,8 +78,8 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
|
||||
@Override
|
||||
public List<Article> findArticleByTitle(String title) {
|
||||
String sql = "SELECT * FROM ARTICLES_VENDUS WHERE nom_article LIKE '?'";
|
||||
List<Article> articles = jdbcTemplate.query(sql, new ArticleRowMapper(), title);
|
||||
String sql = "SELECT * FROM ARTICLES_VENDUS WHERE nom_article LIKE ?";
|
||||
List<Article> articles = jdbcTemplate.query(sql, new ArticleRowMapper(), "%" + title + "%");
|
||||
return articles;
|
||||
}
|
||||
|
||||
|
||||
10
src/main/java/fr/eni/enchere/dal/CategorieRepository.java
Normal file
10
src/main/java/fr/eni/enchere/dal/CategorieRepository.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.Categorie;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CategorieRepository {
|
||||
List<Categorie> findAllCategories();
|
||||
Categorie findCategorieById(int id);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.Categorie;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
@Repository
|
||||
public class CategorieRepositoryImpl implements CategorieRepository {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private NamedParameterJdbcTemplate namedJdbcTemplate;
|
||||
|
||||
|
||||
private class CategorieRowMapper implements RowMapper<Categorie> {
|
||||
|
||||
@Override
|
||||
public Categorie mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
Categorie categorie = new Categorie();
|
||||
categorie.setId(rs.getInt("no_categorie"));
|
||||
categorie.setLibelle(rs.getString("libelle"));
|
||||
return categorie;
|
||||
}
|
||||
}
|
||||
|
||||
public CategorieRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.namedJdbcTemplate = namedJdbcTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Categorie> findAllCategories() {
|
||||
String sql = "SELECT * FROM CATEGORIES";
|
||||
List<Categorie> categories = jdbcTemplate.query(sql, new CategorieRowMapper());
|
||||
System.out.println(categories);
|
||||
return categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Categorie findCategorieById(int id) {
|
||||
String sql = "SELECT * FROM CATEGORIES WHERE no_categorie = :id";
|
||||
Categorie categorie = jdbcTemplate.queryForObject(sql, new CategorieRowMapper(), id);
|
||||
return categorie;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user