Merge branch 'Johan'
This commit is contained in:
@@ -9,7 +9,7 @@ public interface ArticleService {
|
|||||||
|
|
||||||
List<Article> findAllArticle();
|
List<Article> findAllArticle();
|
||||||
Article findArticleById(int id);
|
Article findArticleById(int id);
|
||||||
void saveArticle(Article article);
|
int saveArticle(Article article);
|
||||||
void deleteArticle(int id);
|
void deleteArticle(int id);
|
||||||
void updateArticle(int id);
|
void updateArticle(int id);
|
||||||
List<Article> findArticleByTitle(String title);
|
List<Article> findArticleByTitle(String title);
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ public class ArticleServiceImpl implements ArticleService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveArticle(Article article) {
|
public int saveArticle(Article article) {
|
||||||
|
return articleRepository.saveArticle(article);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.springframework.ui.Model;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -78,7 +79,7 @@ public class ArticleController {
|
|||||||
@RequestParam("code_postal") String code_postal,
|
@RequestParam("code_postal") String code_postal,
|
||||||
@RequestParam("ville") String ville,
|
@RequestParam("ville") String ville,
|
||||||
@RequestParam("dateDebut") String dateDebut,
|
@RequestParam("dateDebut") String dateDebut,
|
||||||
@RequestParam("dateFin") String datefin) {
|
@RequestParam("dateFin") String dateFin) {
|
||||||
//Récupérer l'utilisateur pour set l'article
|
//Récupérer l'utilisateur pour set l'article
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
String username = authentication.getName();
|
String username = authentication.getName();
|
||||||
@@ -90,14 +91,19 @@ public class ArticleController {
|
|||||||
retrait.setCode_postale(code_postal);
|
retrait.setCode_postale(code_postal);
|
||||||
retrait.setVille(ville);
|
retrait.setVille(ville);
|
||||||
//Reste de l'article
|
//Reste de l'article
|
||||||
//Date dDateDebut = new SimpleDateFormat(dateDebut);
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
//article.setDateDebutEnch();
|
Date dDateDebut = null;
|
||||||
if (article.getId() == 0){
|
Date dDateFin = null;
|
||||||
//Création d'un article
|
try {
|
||||||
|
dDateDebut = format.parse(dateDebut);
|
||||||
} else {
|
dDateFin = format.parse(dateFin);
|
||||||
//Mise à jour d'un article
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
article.setDateDebutEnch(dDateDebut);
|
||||||
|
article.setDateFinEnch(dDateFin);
|
||||||
|
retrait.setNumArticle(articleService.saveArticle(article));
|
||||||
|
retraitService.setRetrait(retrait);
|
||||||
return "redirect:/accueil";
|
return "redirect:/accueil";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public interface ArticleRepository {
|
|||||||
List<Article> searchArticle(SearchArticleCritere critere);
|
List<Article> searchArticle(SearchArticleCritere critere);
|
||||||
Article findArticleById(int id);
|
Article findArticleById(int id);
|
||||||
List<Article> findArticleByTitle(String title);
|
List<Article> findArticleByTitle(String title);
|
||||||
void saveArticle(Article article);
|
int saveArticle(Article article);
|
||||||
void deleteArticle(int id);
|
void deleteArticle(int id);
|
||||||
void updateArticle(int id);
|
void updateArticle(int id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,19 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
|
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||||
|
import org.springframework.jdbc.support.KeyHolder;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -22,6 +32,7 @@ import java.util.List;
|
|||||||
@Primary
|
@Primary
|
||||||
public class ArticleRepositoryImpl implements ArticleRepository {
|
public class ArticleRepositoryImpl implements ArticleRepository {
|
||||||
|
|
||||||
|
private static final String UPLOAD_DIR = "src/main/resources/static/images/articles";
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ArticleRepositoryImpl.class);
|
private static final Logger logger = LoggerFactory.getLogger(ArticleRepositoryImpl.class);
|
||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
private NamedParameterJdbcTemplate namedJdbcTemplate;
|
private NamedParameterJdbcTemplate namedJdbcTemplate;
|
||||||
@@ -93,9 +104,49 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveArticle(Article article) {
|
public int saveArticle(Article article) {
|
||||||
|
if (article.getId() == 0) {
|
||||||
|
//Nouvel article
|
||||||
|
String sql = "INSERT INTO ARTICLES_VENDUS (nom_article, description, date_debut_encheres, date_fin_encheres, prix_initial, prix_vente, no_utilisateur, no_categorie, isDelete) " +
|
||||||
|
"VALUES (:nom_article, :description, :date_debut_encheres, :date_fin_encheres, :prix_initial, null, :no_utilisateur, :no_categorie, 0)";
|
||||||
|
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||||
|
parameters.addValue("nom_article", article.getNom());
|
||||||
|
parameters.addValue("description", article.getDesc());
|
||||||
|
parameters.addValue("date_debut_encheres", article.getDateDebutEnch());
|
||||||
|
parameters.addValue("date_fin_encheres", article.getDateFinEnch());
|
||||||
|
parameters.addValue("prix_initial", article.getPrixInitial());
|
||||||
|
parameters.addValue("no_utilisateur", article.getUtilisateur());
|
||||||
|
parameters.addValue("no_categorie", article.getNumCategorie());
|
||||||
|
KeyHolder keyHolder = new GeneratedKeyHolder();
|
||||||
|
namedJdbcTemplate.update(sql, parameters, keyHolder, new String[] {"no_article"});
|
||||||
|
if (keyHolder.getKey() != null) {
|
||||||
|
article.setId(keyHolder.getKey().intValue());
|
||||||
|
}
|
||||||
|
//Enregistrement du fichier
|
||||||
|
MultipartFile file = article.getPhoto();
|
||||||
|
if (file != null && !file.isEmpty()) {
|
||||||
|
try {
|
||||||
|
// Renommer le fichier avec l'ID de l'article
|
||||||
|
String newFileName = article.getId() + ".jpg";
|
||||||
|
// Chemin du dossier de destination
|
||||||
|
Path uploadPath = Paths.get(UPLOAD_DIR);
|
||||||
|
// Créer le dossier s'il n'existe pas
|
||||||
|
Files.createDirectories(uploadPath);
|
||||||
|
// Chemin complet du fichier de destination
|
||||||
|
Path filePath = uploadPath.resolve(newFileName);
|
||||||
|
// Copier le fichier dans le dossier de destination
|
||||||
|
FileCopyUtils.copy(file.getInputStream(), Files.newOutputStream(filePath));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// Gérer l'erreur
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
//Mettre à jour l'article
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return article.getId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteArticle(int id) {
|
public void deleteArticle(int id) {
|
||||||
|
|||||||
@@ -2,12 +2,23 @@ package fr.eni.enchere.dal;
|
|||||||
|
|
||||||
import fr.eni.enchere.bo.Retrait;
|
import fr.eni.enchere.bo.Retrait;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||||
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@Primary
|
@Primary
|
||||||
public class RetraitRepositoryImpl implements RetraitRepository {
|
public class RetraitRepositoryImpl implements RetraitRepository {
|
||||||
|
|
||||||
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
private NamedParameterJdbcTemplate namedJdbcTemplate;
|
||||||
|
|
||||||
|
public RetraitRepositoryImpl(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedJdbcTemplate) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
this.namedJdbcTemplate = namedJdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Retrait findById(int id) {
|
public Retrait findById(int id) {
|
||||||
return null;
|
return null;
|
||||||
@@ -15,6 +26,16 @@ public class RetraitRepositoryImpl implements RetraitRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(Retrait retrait) {
|
public void save(Retrait retrait) {
|
||||||
|
String sql = "SELECT COUNT(*) FROM RETRAITS WHERE no_article = :numArticle";
|
||||||
|
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||||
|
parameters.addValue("numArticle", retrait.getNumArticle());
|
||||||
|
int count = namedJdbcTemplate.queryForObject(sql, parameters, Integer.class);
|
||||||
|
if (count > 0) {
|
||||||
|
//Mettre à jour les informations
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//Ajouter le retrait
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
BIN
src/main/resources/static/images/articles/21.jpg
Normal file
BIN
src/main/resources/static/images/articles/21.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 365 KiB |
@@ -37,7 +37,7 @@
|
|||||||
<!-- Mise à prix -->
|
<!-- Mise à prix -->
|
||||||
<div>
|
<div>
|
||||||
<label for="prix">Mise à prix:</label>
|
<label for="prix">Mise à prix:</label>
|
||||||
<input type="number" id="prix" th:field="*{prixInitial}" min="0" required>
|
<input type="number" id="prix" th:field="*{prixInitial}" min="0" step="0.01" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Date début enchère -->
|
<!-- Date début enchère -->
|
||||||
@@ -75,6 +75,19 @@
|
|||||||
<form th:action="@{/accueil}" method="post">
|
<form th:action="@{/accueil}" method="post">
|
||||||
<button type="submit">Annuler</button>
|
<button type="submit">Annuler</button>
|
||||||
</form>
|
</form>
|
||||||
|
<script>
|
||||||
|
// Obtenez la date actuelle et j+1
|
||||||
|
var today = new Date();
|
||||||
|
var tomorrow = new Date(today);
|
||||||
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||||
|
// Formatez la date au format YYYY-MM-DD pour l'attribut min
|
||||||
|
var formattedDateToday = today.toISOString().split('T')[0];
|
||||||
|
var formattedDateTomorrow = tomorrow.toISOString().split('T')[0];
|
||||||
|
// Attribuez la date formatée à l'attribut min de l'élément input
|
||||||
|
document.getElementById('dateDebut').min = formattedDateToday;
|
||||||
|
document.getElementById('dateFin').min = formattedDateTomorrow;
|
||||||
|
// Attribuez la date formatée à l'attribut min de l'élément input
|
||||||
|
</script>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user