filtres articles
This commit is contained in:
@@ -2,9 +2,11 @@ package fr.eni.enchere.bll;
|
|||||||
|
|
||||||
import fr.eni.enchere.bo.Enchere;
|
import fr.eni.enchere.bo.Enchere;
|
||||||
import fr.eni.enchere.dal.EnchereRepository;
|
import fr.eni.enchere.dal.EnchereRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class EnchereServiceImpl implements EnchereService{
|
public class EnchereServiceImpl implements EnchereService{
|
||||||
|
|
||||||
private EnchereRepository enchereRepository;
|
private EnchereRepository enchereRepository;
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ 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, @RequestParam(value = "achatOption", required = false) String[] achatOptions) {
|
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("" + Arrays.toString(venteOptions));
|
|
||||||
SearchArticleCritere critere = new SearchArticleCritere();
|
SearchArticleCritere critere = new SearchArticleCritere();
|
||||||
critere.setNoCategorie(searchCategory);
|
critere.setNoCategorie(searchCategory);
|
||||||
critere.setTitle(searchTitle);
|
critere.setTitle(searchTitle);
|
||||||
@@ -54,7 +53,7 @@ public class AccueilController {
|
|||||||
critere.setNoVendeur(userService.utilisateurByName(userDetails.getUsername()).getId());
|
critere.setNoVendeur(userService.utilisateurByName(userDetails.getUsername()).getId());
|
||||||
}
|
}
|
||||||
critere.setVenteOptions(venteOptions);
|
critere.setVenteOptions(venteOptions);
|
||||||
critere.setAchatOptions(venteOptions);
|
critere.setAchatOptions(achatOptions);
|
||||||
model.addAttribute("articles", articleService.searchArticle(critere));
|
model.addAttribute("articles", articleService.searchArticle(critere));
|
||||||
return "accueil";
|
return "accueil";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,8 +88,9 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Article> searchArticle(SearchArticleCritere critere) {
|
public List<Article> searchArticle(SearchArticleCritere critere) {
|
||||||
StringBuilder sql = new StringBuilder("SELECT a.*, u.* FROM ARTICLES_VENDUS a ");
|
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("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");
|
sql.append("WHERE 1 = 1 AND a.isDelete = 0");
|
||||||
List<Object> params = new ArrayList<>();
|
List<Object> params = new ArrayList<>();
|
||||||
|
|
||||||
@@ -147,33 +148,33 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
|||||||
if (!isFirstCondition) {
|
if (!isFirstCondition) {
|
||||||
sql.append(" OR ");
|
sql.append(" OR ");
|
||||||
}
|
}
|
||||||
sql.append(" /* Ajoutez votre condition ici */ ");
|
sql.append(" (e.no_utilisateur = ? AND a.date_debut_encheres <= NOW() AND a.date_fin_encheres >= NOW()) ");
|
||||||
isFirstCondition = false;
|
isFirstCondition = false;
|
||||||
|
params.add(critere.getNoVendeur());
|
||||||
}
|
}
|
||||||
if (option.equals("enchereRemportees")) {
|
if (option.equals("enchereRemportees")) {
|
||||||
if (!isFirstCondition) {
|
if (!isFirstCondition) {
|
||||||
sql.append(" OR ");
|
sql.append(" OR ");
|
||||||
}
|
}
|
||||||
sql.append(" /* Ajoutez votre condition ici */ ");
|
sql.append(" (e.no_utilisateur = ? AND e.montant_enchere = (SELECT MAX(montant_enchere) FROM ENCHERES WHERE no_article = a.no_article)) ");
|
||||||
isFirstCondition = false;
|
isFirstCondition = false;
|
||||||
|
params.add(critere.getNoVendeur());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.append(") AND a.no_utilisateur = ?");
|
sql.append(")");
|
||||||
params.add(critere.getNoVendeur());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Article> articles = jdbcTemplate.query(sql.toString(), new HomeArticleRowMapper(), params.toArray());
|
List<Article> articles = jdbcTemplate.query(sql.toString(), new HomeArticleRowMapper(), params.toArray());
|
||||||
|
|
||||||
for (Article article : articles) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return articles;
|
return articles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Article findArticleById(int id) {
|
public Article findArticleById(int id) {
|
||||||
String sql = "SELECT * FROM ARTICLES_VENDUS a WHERE a.no_article = ?";
|
String sql = "SELECT * FROM ARTICLES_VENDUS a WHERE a.no_article = ?";
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package fr.eni.enchere.dal;
|
package fr.eni.enchere.dal;
|
||||||
|
|
||||||
import fr.eni.enchere.bo.Enchere;
|
import fr.eni.enchere.bo.Enchere;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@Repository
|
||||||
public class EnchereRepositoryImpl implements EnchereRepository {
|
public class EnchereRepositoryImpl implements EnchereRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<button type="submit" class="btn btn-primary">Connexion</button>
|
<button type="submit" class="btn btn-primary">Connexion</button>
|
||||||
<button type="button" class="btn btn-warning text-light" href="/inscription">Créer un compte </button>
|
<a class="btn btn-warning text-light" href="/inscription">Créer un compte</a>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div th:if="${param.error}" class="text-danger">
|
<div th:if="${param.error}" class="text-danger">
|
||||||
|
|||||||
Reference in New Issue
Block a user