Merge branch 'main' into Olivier
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package fr.eni.enchere.bll;
|
||||
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.SearchArticleCritere;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -12,4 +13,5 @@ public interface ArticleService {
|
||||
void deleteArticle(int id);
|
||||
void updateArticle(int id);
|
||||
List<Article> findArticleByTitle(String title);
|
||||
List<Article> searchArticle(SearchArticleCritere critere);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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.stereotype.Service;
|
||||
|
||||
@@ -43,4 +44,9 @@ public class ArticleServiceImpl implements ArticleService{
|
||||
public List<Article> findArticleByTitle(String title) {
|
||||
return articleRepository.findArticleByTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Article> searchArticle(SearchArticleCritere critere) {
|
||||
return articleRepository.searchArticle(critere);
|
||||
}
|
||||
}
|
||||
|
||||
13
src/main/java/fr/eni/enchere/bll/CategorieService.java
Normal file
13
src/main/java/fr/eni/enchere/bll/CategorieService.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package fr.eni.enchere.bll;
|
||||
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.Categorie;
|
||||
import fr.eni.enchere.bo.SearchArticleCritere;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CategorieService {
|
||||
List<fr.eni.enchere.bo.Categorie> findAllCategories();
|
||||
Categorie findCategorieById(int id);
|
||||
|
||||
}
|
||||
32
src/main/java/fr/eni/enchere/bll/CategorieServiceImpl.java
Normal file
32
src/main/java/fr/eni/enchere/bll/CategorieServiceImpl.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package fr.eni.enchere.bll;
|
||||
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.Categorie;
|
||||
import fr.eni.enchere.bo.SearchArticleCritere;
|
||||
import fr.eni.enchere.dal.ArticleRepositoryImpl;
|
||||
import fr.eni.enchere.dal.CategorieRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CategorieServiceImpl implements CategorieService {
|
||||
private final ArticleRepositoryImpl articleRepositoryImpl;
|
||||
private CategorieRepository categorieRepository;
|
||||
|
||||
public CategorieServiceImpl(CategorieRepository categorieRepository, ArticleRepositoryImpl articleRepositoryImpl) {
|
||||
this.categorieRepository = categorieRepository;
|
||||
this.articleRepositoryImpl = articleRepositoryImpl;
|
||||
}
|
||||
@Override
|
||||
public List<Categorie> findAllCategories() {
|
||||
return categorieRepository.findAllCategories();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Categorie findCategorieById(int id) {
|
||||
return categorieRepository.findCategorieById(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,13 +11,13 @@ public class Article {
|
||||
Date dateFinEnch;
|
||||
float prixInitial;
|
||||
float prixVente;
|
||||
int numUtilisateur;
|
||||
UserProfil Utilisateur;
|
||||
int numCategorie;
|
||||
|
||||
public Article() {
|
||||
}
|
||||
|
||||
public Article(int id, String nom, String desc, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, int numUtilisateur, int numCategorie) {
|
||||
public Article(int id, String nom, String desc, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, UserProfil Utilisateur, int numCategorie) {
|
||||
this.id = id;
|
||||
this.nom = nom;
|
||||
this.desc = desc;
|
||||
@@ -25,7 +25,7 @@ public class Article {
|
||||
this.dateFinEnch = dateFinEnch;
|
||||
this.prixInitial = prixInitial;
|
||||
this.prixVente = prixVente;
|
||||
this.numUtilisateur = numUtilisateur;
|
||||
this.Utilisateur = Utilisateur;
|
||||
this.numCategorie = numCategorie;
|
||||
}
|
||||
|
||||
@@ -85,12 +85,12 @@ public class Article {
|
||||
this.prixVente = prixVente;
|
||||
}
|
||||
|
||||
public int getNumUtilisateur() {
|
||||
return numUtilisateur;
|
||||
public UserProfil getUtilisateur() {
|
||||
return Utilisateur;
|
||||
}
|
||||
|
||||
public void setNumUtilisateur(int numUtilisateur) {
|
||||
this.numUtilisateur = numUtilisateur;
|
||||
public void setUtilisateur(UserProfil Utilisateur) {
|
||||
this.Utilisateur = Utilisateur;
|
||||
}
|
||||
|
||||
public int getNumCategorie() {
|
||||
|
||||
26
src/main/java/fr/eni/enchere/bo/Categorie.java
Normal file
26
src/main/java/fr/eni/enchere/bo/Categorie.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package fr.eni.enchere.bo;
|
||||
|
||||
public class Categorie {
|
||||
|
||||
int id;
|
||||
String libelle;
|
||||
|
||||
public Categorie() {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLibelle() {
|
||||
return libelle;
|
||||
}
|
||||
|
||||
public void setLibelle(String libelle) {
|
||||
this.libelle = libelle;
|
||||
}
|
||||
}
|
||||
22
src/main/java/fr/eni/enchere/bo/SearchArticleCritere.java
Normal file
22
src/main/java/fr/eni/enchere/bo/SearchArticleCritere.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package fr.eni.enchere.bo;
|
||||
|
||||
public class SearchArticleCritere {
|
||||
String title;
|
||||
Integer noCategorie;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Integer getNoCategorie() {
|
||||
return noCategorie;
|
||||
}
|
||||
|
||||
public void setNoCategorie(Integer noCategorie) {
|
||||
this.noCategorie = noCategorie;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bll.ArticleService;
|
||||
import fr.eni.enchere.bll.CategorieService;
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.SearchArticleCritere;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -10,6 +12,7 @@ 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.RequestParam;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,23 +22,30 @@ public class AccueilController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AccueilController.class);
|
||||
private ArticleService articleService;
|
||||
private CategorieService categorieService;
|
||||
|
||||
public AccueilController(ArticleService articleService) {
|
||||
public AccueilController(ArticleService articleService, CategorieService categorieService) {
|
||||
super();
|
||||
|
||||
this.categorieService = categorieService;
|
||||
this.articleService = articleService;
|
||||
}
|
||||
|
||||
@GetMapping({"/", "/accueil"})
|
||||
public String viewAccueil(Model model) {
|
||||
model.addAttribute("articles", articleService.findAllArticle());
|
||||
public String viewAccueil(@RequestParam(required = false) String searchTitle, @RequestParam(required = false) Integer searchCategory, Model model) {
|
||||
System.out.println("Liste cat: "+categorieService.findAllCategories());
|
||||
model.addAttribute("categories", categorieService.findAllCategories());
|
||||
SearchArticleCritere critere = new SearchArticleCritere();
|
||||
critere.setNoCategorie(searchCategory);
|
||||
critere.setTitle(searchTitle);
|
||||
|
||||
model.addAttribute("articles", articleService.searchArticle(critere));
|
||||
return "accueil";
|
||||
}
|
||||
|
||||
@PostMapping("/searchArticle")
|
||||
public String searchArticle(@ModelAttribute String title, Model model) {
|
||||
model.addAttribute("Articles", articleService.findArticleByTitle(title));
|
||||
return "accueil";
|
||||
@PostMapping("/accueil")
|
||||
public String handleSearch(@RequestParam("searchTitle") String searchTitle, @RequestParam(value = "searchCategory", required = false) Integer searchCategory, Model model) {
|
||||
System.out.println("test");
|
||||
return viewAccueil(searchTitle, searchCategory, model);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,9 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.SearchArticleCritere;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
import fr.eni.enchere.controllers.AccueilController;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -12,6 +15,7 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@@ -21,6 +25,7 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ArticleRepositoryImpl.class);
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private NamedParameterJdbcTemplate namedJdbcTemplate;
|
||||
private UserService userService;
|
||||
|
||||
private class ArticleRowMapper implements RowMapper<Article> {
|
||||
@Override
|
||||
@@ -33,15 +38,23 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
article.setDateFinEnch(rs.getDate("date_fin_encheres"));
|
||||
article.setPrixInitial(rs.getFloat("prix_initial"));
|
||||
article.setPrixVente(rs.getFloat("prix_vente"));
|
||||
article.setNumUtilisateur(rs.getInt("no_utilisateur"));
|
||||
|
||||
UserProfil user = userService.utilisateurById(rs.getInt("no_utilisateur"));
|
||||
if (user != null) {
|
||||
article.setUtilisateur(user);
|
||||
} else {
|
||||
logger.error("erreur de l'utilisateur");
|
||||
}
|
||||
|
||||
article.setNumCategorie(rs.getInt("no_categorie"));
|
||||
return article;
|
||||
}
|
||||
}
|
||||
|
||||
public ArticleRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate) {
|
||||
public ArticleRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate, UserService userService) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.namedJdbcTemplate = namedJdbcTemplate;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,6 +64,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 +89,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;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
import org.apache.catalina.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
@@ -11,6 +14,8 @@ import org.springframework.jdbc.support.KeyHolder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -30,22 +35,10 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserProfil> findAll() {
|
||||
return List.of();
|
||||
}
|
||||
public class UserRowMapper implements RowMapper<UserProfil> {
|
||||
|
||||
@Override
|
||||
public UserProfil findById(int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProfil findByUsername(String username) {
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE pseudo = :username OR email = :username AND isDelete = 0";
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("username", username);
|
||||
UserProfil user = namedParameterJdbcTemplate.queryForObject(sql, params, (rs, rowNum) -> {
|
||||
public UserProfil mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
UserProfil userProfile = new UserProfil();
|
||||
userProfile.setId(rs.getInt("no_utilisateur"));
|
||||
userProfile.setPrenom(rs.getString("prenom"));
|
||||
@@ -60,7 +53,28 @@ public class UserRepositoryImpl implements UserRepository {
|
||||
userProfile.setCredit(rs.getFloat("credit"));
|
||||
userProfile.setAdmin(rs.getBoolean("administrateur"));
|
||||
return userProfile;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProfil findByUsername(String username) {
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE pseudo = :username OR email = :username AND isDelete = 0";
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("username", username);
|
||||
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), params);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserProfil> findAll() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProfil findById(int id) {
|
||||
String sql = "SELECT * FROM UTILISATEURS WHERE no_utilisateur = ?";
|
||||
UserProfil user = jdbcTemplate.queryForObject(sql, new UserRowMapper(), id);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,20 @@
|
||||
<div class="container mt-4">
|
||||
<div class="row mb-4">
|
||||
<div class="col-12">
|
||||
<form th:action="@{/searchArticle}" method="post" class="input-group">
|
||||
<input type="text" class="form-control" placeholder="Rechercher un article par nom..." name="searchTerm" th:value="${titre}">
|
||||
<!-- Formulaire de recherche avec sélection de catégorie -->
|
||||
<form th:action="@{/accueil}" method="post" class="mb-3">
|
||||
<!-- Barre de recherche -->
|
||||
<div class="mb-3">
|
||||
<input type="text" class="form-control" placeholder="Rechercher un article par nom..." name="searchTitle">
|
||||
</div>
|
||||
<!-- Menu déroulant pour la sélection de la catégorie -->
|
||||
<div class="mb-3">
|
||||
<select class="form-control" name="searchCategory">
|
||||
<option value="">Toutes les catégories</option>
|
||||
<option th:each="category : ${categories}" th:value="${category.id}" th:text="${category.libelle}"></option>
|
||||
</select>
|
||||
</div>
|
||||
<!-- Bouton de soumission -->
|
||||
<button type="submit" class="btn btn-primary">Recherche</button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -31,6 +43,11 @@
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<h6>Prix de vente: <span th:text="${article.prixVente}"></span> €</h6>
|
||||
|
||||
<h6>Vendeur: <span th:text="${article.utilisateur.getPseudo()}"></span> </h6>
|
||||
</div>
|
||||
</div>
|
||||
</br>
|
||||
<h6 class="text-muted">Fin de l'enchere: <span th:text="${#dates.format(article.dateFinEnch, 'dd/MM/yyyy')}"></span></h6>
|
||||
</div>
|
||||
</div>
|
||||
@@ -40,8 +57,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="js/bootstrap/bootstrap.min.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-lg navbar navbar-dark bg-dark navbar-">
|
||||
<a class="navbar-brand" href="#">
|
||||
<a class="navbar-brand" href="/accueil">
|
||||
<img src="img/logo.png" width="70" height="70" alt="Logo">
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
|
||||
Reference in New Issue
Block a user