Ajout article final

This commit is contained in:
jleroy
2024-04-25 10:03:01 +02:00
parent 747c038050
commit c4020f1612
13 changed files with 170 additions and 17 deletions

View File

@@ -0,0 +1,12 @@
package fr.eni.enchere.bll;
import fr.eni.enchere.bo.Enchere;
import java.util.List;
public interface EnchereService {
Enchere enchereByUserAndArticle(int idUser, int idArticle);
List<Enchere> enchereByUser(int idUser);
List<Enchere> enchereByArticle(int idArticle);
void setEnchere(Enchere enchere);
}

View File

@@ -0,0 +1,35 @@
package fr.eni.enchere.bll;
import fr.eni.enchere.bo.Enchere;
import fr.eni.enchere.dal.EnchereRepository;
import java.util.List;
public class EnchereServiceImpl implements EnchereService{
private EnchereRepository enchereRepository;
public EnchereServiceImpl(EnchereRepository enchereRepository) {
this.enchereRepository = enchereRepository;
}
@Override
public Enchere enchereByUserAndArticle(int idUser, int idArticle) {
return enchereRepository.findByIdUserAndIdArticle(idUser, idArticle);
}
@Override
public List<Enchere> enchereByUser(int idUser) {
return enchereRepository.findByIdUser(idUser);
}
@Override
public List<Enchere> enchereByArticle(int idArticle) {
return enchereRepository.findByIdArticle(idArticle);
}
@Override
public void setEnchere(Enchere enchere) {
enchereRepository.save(enchere);
}
}

View File

@@ -1,10 +1,18 @@
package fr.eni.enchere.bll;
import fr.eni.enchere.bo.Retrait;
import fr.eni.enchere.dal.RetraitRepository;
import org.springframework.stereotype.Service;
@Service("RetraitService")
public class RetraitServiceImpl implements RetraitService {
public RetraitRepository retraitRepository;
public RetraitServiceImpl(RetraitRepository retraitRepository) {
this.retraitRepository = retraitRepository;
}
@Override
public Retrait retraitByNumarticle(int id) {
return null;
@@ -12,6 +20,6 @@ public class RetraitServiceImpl implements RetraitService {
@Override
public void setRetrait(Retrait retrait) {
retraitRepository.save(retrait);
}
}

View File

@@ -1,4 +1,52 @@
package fr.eni.enchere.bo;
import java.util.Date;
public class Enchere {
private int noUtilisateur;
private int noArticle;
private Date dateEnchere;
private float montantEnchere;
public Enchere(){}
public Enchere(int noUtilisateur, int noArticle, Date dateEnchere, float montantEnchere) {
setNoUtilisateur(noUtilisateur);
setNoArticle(noArticle);
setDateEnchere(dateEnchere);
setMontantEnchere(montantEnchere);
}
public float getMontantEnchere() {
return montantEnchere;
}
public void setMontantEnchere(float montantEnchere) {
this.montantEnchere = montantEnchere;
}
public Date getDateEnchere() {
return dateEnchere;
}
public void setDateEnchere(Date dateEnchere) {
this.dateEnchere = dateEnchere;
}
public int getNoArticle() {
return noArticle;
}
public void setNoArticle(int noArticle) {
this.noArticle = noArticle;
}
public int getNoUtilisateur() {
return noUtilisateur;
}
public void setNoUtilisateur(int noUtilisateur) {
this.noUtilisateur = noUtilisateur;
}
}

View File

@@ -70,6 +70,11 @@ public class ArticleController {
model.addAttribute("categories", categorieService.findAllCategories());
model.addAttribute("article", new Article());
model.addAttribute("retrait", new Retrait());
//Récupérer l'utilisateur pour set le retrait à son adresse par defaut
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String username = authentication.getName();
UserProfil userProfile = userService.utilisateurByName(username);
model.addAttribute("user", userProfile);
return "newArticle";
}

View File

@@ -0,0 +1,12 @@
package fr.eni.enchere.dal;
import fr.eni.enchere.bo.Enchere;
import java.util.List;
public interface EnchereRepository {
Enchere findByIdUserAndIdArticle(int idUser, int idArticle);
List<Enchere> findByIdUser(int idUser);
List<Enchere> findByIdArticle(int idArticle);
void save(Enchere enchere);
}

View File

@@ -0,0 +1,28 @@
package fr.eni.enchere.dal;
import fr.eni.enchere.bo.Enchere;
import java.util.List;
public class EnchereRepositoryImpl implements EnchereRepository {
@Override
public Enchere findByIdUserAndIdArticle(int idUser, int idArticle) {
return null;
}
@Override
public List<Enchere> findByIdUser(int idUser) {
return List.of();
}
@Override
public List<Enchere> findByIdArticle(int idArticle) {
return List.of();
}
@Override
public void save(Enchere enchere) {
}
}

View File

@@ -5,6 +5,8 @@ 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.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;
@Repository
@@ -26,16 +28,23 @@ public class RetraitRepositoryImpl implements RetraitRepository {
@Override
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);
String sqlIsUpdate = "SELECT COUNT(*) FROM RETRAITS WHERE no_article = :numArticle";
MapSqlParameterSource parametersIsUpdate = new MapSqlParameterSource();
parametersIsUpdate.addValue("numArticle", retrait.getNumArticle());
int count = namedJdbcTemplate.queryForObject(sqlIsUpdate, parametersIsUpdate, Integer.class);
System.out.println(count);
if (count > 0) {
//Mettre à jour les informations
} else {
//Ajouter le retrait
String sql = "INSERT INTO RETRAITS (no_article, rue, code_postal, ville) VALUES (:no_article, :rue, :code_postal, :ville)";
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("no_article", retrait.getNumArticle());
parameters.addValue("rue", retrait.getRue());
parameters.addValue("code_postal", retrait.getCode_postale());
parameters.addValue("ville", retrait.getVille());
namedJdbcTemplate.update(sql, parameters);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 KiB

View File

@@ -13,15 +13,11 @@
<div class="card-body">
<!-- Iteration over form fields -->
<div class="mb-3">
<label for="pseudo" class="form-label" th:text="#{profil.pseudo}"></label>
<input type="text" class="form-control" th:field="*{pseudo}" id="pseudo" required>
<div th="if=${#fields.hasErrors('pseudo')}" class="invalid-feedback">
<ul>
<li th:each="err : ${#fields.errors('pseudo')}" th:text="${err}"></li>
</ul>
<li class="list-group-item">
<strong><label class="col-form-label" th:text="#{profil.pseudo}"></label></strong>
<span th:text="${userProfile.pseudo}"></span>
</li>
</div>
</div>
<div class="mb-3">
<label for="prenom" class="form-label" th:text="#{profil.surname}">:</label>
<input type="text" class="form-control" th:field="*{prenom}" id="prenom" required>

View File

@@ -56,15 +56,15 @@
<h4>Retrait</h4>
<div>
<label for="rue">Rue:</label>
<input type="text" id="rue" name="rue" required>
<input type="text" id="rue" name="rue" th:field="${user.rue}" required>
</div>
<div>
<label for="codePostal">Code postal:</label>
<input type="text" id="codePostal" name="code_postal" required>
<input type="text" id="codePostal" name="code_postal" th:field="${user.code_postal}" required>
</div>
<div>
<label for="ville">Ville:</label>
<input type="text" id="ville" name="ville" required>
<input type="text" id="ville" name="ville" th:field="${user.ville}" required>
</div>
<!-- Bouton Enregistrer -->