Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
173e051af4 | ||
|
|
8a455d2b26 | ||
|
|
cdd7da676f | ||
|
|
5caac755f6 | ||
|
|
c41143d82f | ||
|
|
9578885d3a | ||
|
|
984acbdacc | ||
|
|
5aee628f28 |
@@ -2,6 +2,7 @@ package fr.eni.enchere.bll;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@@ -9,10 +10,9 @@ import java.nio.file.Paths;
|
||||
public class FileService {
|
||||
|
||||
public boolean fileExists(String filePath) {
|
||||
return Files.exists(Paths.get("src/main/resources/static"+filePath));
|
||||
filePath = "src/main/resources/static" + filePath;
|
||||
File file = new File(filePath).getAbsoluteFile();
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// src/main/resources/static/images/articles/12.jpg
|
||||
}
|
||||
@@ -10,6 +10,7 @@ public class Article {
|
||||
String nom;
|
||||
String desc;
|
||||
MultipartFile photo;
|
||||
String lienImg;
|
||||
Date dateDebutEnch;
|
||||
Date dateFinEnch;
|
||||
float prixInitial;
|
||||
@@ -23,11 +24,12 @@ public class Article {
|
||||
public Article() {
|
||||
}
|
||||
|
||||
public Article(int id, String nom, String desc, MultipartFile photo, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, int Utilisateur, String pseudoUtilisateur, int numCategorie, boolean isDelete) {
|
||||
public Article(int id, String nom, String desc, MultipartFile photo, String lienImg, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, int Utilisateur, String pseudoUtilisateur, int numCategorie, boolean isDelete) {
|
||||
setId(id);
|
||||
setNom(nom);
|
||||
setDesc(desc);
|
||||
setPhoto(photo);
|
||||
setLienImg(lienImg);
|
||||
setDateDebutEnch(dateDebutEnch);
|
||||
setDateFinEnch(dateFinEnch);
|
||||
setPrixInitial(prixInitial);
|
||||
@@ -65,6 +67,14 @@ public class Article {
|
||||
return photo;
|
||||
}
|
||||
|
||||
public String getLienImg() {
|
||||
return lienImg;
|
||||
}
|
||||
|
||||
public void setLienImg(String lienImg) {
|
||||
this.lienImg = lienImg;
|
||||
}
|
||||
|
||||
public void setPhoto(MultipartFile photo) {
|
||||
this.photo = photo;
|
||||
}
|
||||
|
||||
@@ -34,14 +34,12 @@ public class AccueilController {
|
||||
private ArticleService articleService;
|
||||
private CategorieService categorieService;
|
||||
private UserService userService;
|
||||
private FileService fileService;
|
||||
|
||||
public AccueilController(ArticleService articleService, CategorieService categorieService, UserService userService, FileService fileService) {
|
||||
public AccueilController(ArticleService articleService, CategorieService categorieService, UserService userService) {
|
||||
super();
|
||||
this.categorieService = categorieService;
|
||||
this.articleService = articleService;
|
||||
this.userService = userService;
|
||||
this.fileService = fileService;
|
||||
}
|
||||
|
||||
@GetMapping({"/", "/enchere"})
|
||||
@@ -77,7 +75,6 @@ public class AccueilController {
|
||||
Page<Article> articlePage = articleService.searchArticlePageable(critere, PageRequest.of(page, size));
|
||||
|
||||
model.addAttribute("articles", articlePage.getContent());
|
||||
model.addAttribute("fileService", fileService);
|
||||
int currentPage = page + 1;
|
||||
model.addAttribute("currentPage", currentPage);
|
||||
model.addAttribute("critere", critere);
|
||||
|
||||
@@ -62,6 +62,7 @@ public class ArticleController {
|
||||
UserProfil user = userService.utilisateurById(article.getUtilisateur());
|
||||
Categorie cate = categorieService.findCategorieById(article.getNumCategorie());
|
||||
Retrait retrait = retraitService.findByNumArticle(article.getId());
|
||||
|
||||
article.setPseudoUtilisateur(user.getPseudo());
|
||||
List<Enchere> lastEnchere = this.enchereService.enchereByArticle(article.getId());
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bll.EnchereService;
|
||||
import fr.eni.enchere.bll.FileService;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.Enchere;
|
||||
@@ -44,6 +45,7 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
private NamedParameterJdbcTemplate namedJdbcTemplate;
|
||||
private UserService userService;
|
||||
private EnchereService enchereService;
|
||||
private FileService fileService;
|
||||
|
||||
private class ArticleRowMapper implements RowMapper<Article> {
|
||||
@Override
|
||||
@@ -58,6 +60,14 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
article.setPrixVente(rs.getFloat("a.prix_vente"));
|
||||
article.setNoUtilisateur(rs.getInt("a.no_utilisateur"));
|
||||
article.setNumCategorie(rs.getInt("a.no_categorie"));
|
||||
String lienImgTest = "/images/articles/" + article.getId() + ".jpg";
|
||||
String lienImg;
|
||||
if (fileService.fileExists(lienImgTest)){
|
||||
lienImg = "/images/articles/" + article.getId() + ".jpg";
|
||||
}else{
|
||||
lienImg = "/images/articles/no-data.jpg";
|
||||
}
|
||||
article.setLienImg(lienImg);
|
||||
article.setIsDelete(rs.getBoolean("a.isDelete"));
|
||||
return article;
|
||||
}
|
||||
@@ -83,16 +93,25 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
if (maxMontantEnchere.isPresent()) {
|
||||
article.setPrixMaxEnchere(maxMontantEnchere.get());
|
||||
}
|
||||
String lienImgTest = "/images/articles/" + article.getId() + ".jpg";
|
||||
String lienImg;
|
||||
if (fileService.fileExists(lienImgTest)){
|
||||
lienImg = "/images/articles/" + article.getId() + ".jpg";
|
||||
}else{
|
||||
lienImg = "/images/articles/no-data.jpg";
|
||||
}
|
||||
article.setLienImg(lienImg);
|
||||
article.setNumCategorie(rs.getInt("a.no_categorie"));
|
||||
return article;
|
||||
}
|
||||
}
|
||||
|
||||
public ArticleRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate, UserService userService, EnchereService enchereService) {
|
||||
public ArticleRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate, UserService userService, EnchereService enchereService, FileService fileService) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.namedJdbcTemplate = namedJdbcTemplate;
|
||||
this.userService = userService;
|
||||
this.enchereService = enchereService;
|
||||
this.fileService = fileService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,7 +198,7 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
if (!isFirstCondition) {
|
||||
sql.append(" OR ");
|
||||
}
|
||||
sql.append(" (e.no_utilisateur = ? AND e.montant_enchere = (SELECT MAX(montant_enchere) FROM ENCHERES WHERE no_article = a.no_article)) ");
|
||||
sql.append(" (e.no_utilisateur = ? AND e.montant_enchere = (SELECT MAX(montant_enchere) FROM ENCHERES WHERE no_article = a.no_article) AND a.date_fin_encheres <= NOW()) ");
|
||||
isFirstCondition = false;
|
||||
params.add(critere.getNoVendeur());
|
||||
}
|
||||
|
||||
BIN
src/main/resources/static/images/articles/121.jpg
Normal file
BIN
src/main/resources/static/images/articles/121.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 339 KiB |
@@ -119,8 +119,7 @@
|
||||
<div class="card shadow-sm h-100 card-article">
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4 d-flex align-items-center justify-content-center p-3">
|
||||
<img th:if="${fileService.fileExists('/images/articles/' + article.id + '.jpg')}" th:src="'images/articles/' + ${article.id} + '.jpg'" alt="Image de l'article" class="img-fluid rounded">
|
||||
<img th:unless="${fileService.fileExists('/images/articles/' + article.id + '.jpg')}" th:src="@{/images/articles/no-data.jpg}" alt="Image de l'article" class="img-fluid rounded">
|
||||
<img th:src="${article.lienImg}" alt="Image de l'article" class="img-fluid rounded">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body d-flex flex-column">
|
||||
@@ -159,7 +158,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h6 class="text-muted"><strong><span th:text="#{article.details.label.end_date}"></span>: </strong></h6>
|
||||
<h6 class="text-muted"><strong><span th:text="#{article.details.label.end_date}"></span></strong></h6>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h6 class="text-muted"><span th:text="${#dates.format(article.dateFinEnch, 'dd/MM/yyyy')}"></span></h6>
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-4">
|
||||
<img th:if="${fileService.fileExists('/images/articles/' + article.id + '.jpg')}" th:src="'/images/articles/' + ${article.id} + '.jpg'" alt="Image de l'article" class="img-fluid rounded">
|
||||
<img th:unless="${fileService.fileExists('/images/articles/' + article.id + '.jpg')}" th:src="@{/images/articles/no-data.jpg}" alt="Image de l'article" class="img-fluid rounded">
|
||||
<img th:src="${article.lienImg}" alt="Image de l'article" class="img-fluid rounded">
|
||||
</div>
|
||||
<div class="col-12 col-md-8">
|
||||
<div class="mt-2 d-flex flex-column align-items-center">
|
||||
|
||||
Reference in New Issue
Block a user