save enchere
This commit is contained in:
@@ -4,6 +4,7 @@ import java.util.Date;
|
||||
|
||||
public class Enchere {
|
||||
|
||||
private int id;
|
||||
private int noUtilisateur;
|
||||
private int noArticle;
|
||||
private Date dateEnchere;
|
||||
@@ -18,6 +19,14 @@ public class Enchere {
|
||||
setMontantEnchere(montantEnchere);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public float getMontantEnchere() {
|
||||
return montantEnchere;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,7 @@ import fr.eni.enchere.bll.ArticleService;
|
||||
import fr.eni.enchere.bll.CategorieService;
|
||||
import fr.eni.enchere.bll.RetraitService;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import fr.eni.enchere.bo.Categorie;
|
||||
import fr.eni.enchere.bo.Retrait;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
import fr.eni.enchere.bo.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@@ -51,9 +48,12 @@ public class ArticleController {
|
||||
Article article = articleService.findArticleById(id);
|
||||
UserProfil user = userService.utilisateurById(article.getUtilisateur());
|
||||
Categorie cate = categorieService.findCategorieById(article.getNumCategorie());
|
||||
Retrait retrait = retraitService.retraitByNumarticle(article.getId());
|
||||
model.addAttribute("article", article);
|
||||
model.addAttribute("username", user.getPseudo());
|
||||
model.addAttribute("username", user);
|
||||
model.addAttribute("cate", cate.getLibelle());
|
||||
model.addAttribute("retrait", retrait);
|
||||
model.addAttribute("enchere", new Enchere());
|
||||
return "article";
|
||||
} else {
|
||||
return "redirect:/accueil";
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bll.EnchereService;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.Enchere;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Controller()
|
||||
@RequestMapping("/enchere")
|
||||
public class EnchereController {
|
||||
|
||||
@Autowired
|
||||
private EnchereService enchereService;
|
||||
private UserService userService;
|
||||
|
||||
public EnchereController(EnchereService enchereService, UserService userService) {
|
||||
this.enchereService = enchereService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@PostMapping("/incEnchere")
|
||||
public String incEnchere(@ModelAttribute("enchere") Enchere enchere, @RequestParam("articleId") int articleId) {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
enchere.setNoArticle(articleId);
|
||||
enchere.setNoUtilisateur(this.userService.utilisateurByName(authentication.getName()).getId());
|
||||
enchere.setDateEnchere(new Date());
|
||||
enchere.setMontantEnchere(enchere.getMontantEnchere());
|
||||
this.enchereService.setEnchere(enchere);
|
||||
return "redirect:/article/show?id=" + articleId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -170,11 +170,6 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
return articles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Article findArticleById(int id) {
|
||||
String sql = "SELECT * FROM ARTICLES_VENDUS a WHERE a.no_article = ?";
|
||||
|
||||
@@ -1,12 +1,36 @@
|
||||
package fr.eni.enchere.dal;
|
||||
|
||||
import fr.eni.enchere.bo.Enchere;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.support.GeneratedKeyHolder;
|
||||
import org.springframework.jdbc.support.KeyHolder;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
@Repository
|
||||
public class EnchereRepositoryImpl implements EnchereRepository {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public EnchereRepositoryImpl(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public class EnchereRowMapper implements RowMapper<Enchere> {
|
||||
@Override
|
||||
public Enchere mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
Enchere enchere = new Enchere();
|
||||
enchere.setNoUtilisateur(rs.getInt("no_utilisateur"));
|
||||
enchere.setNoArticle(rs.getInt("no_article"));
|
||||
enchere.setMontantEnchere(rs.getInt("montant_enchere"));
|
||||
enchere.setDateEnchere(rs.getDate("date_enchere"));
|
||||
return enchere;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enchere findByIdUserAndIdArticle(int idUser, int idArticle) {
|
||||
return null;
|
||||
@@ -24,6 +48,11 @@ public class EnchereRepositoryImpl implements EnchereRepository {
|
||||
|
||||
@Override
|
||||
public void save(Enchere enchere) {
|
||||
|
||||
String sql = "INSERT INTO ENCHERES (no_utilisateur, no_article, date_enchere, montant_enchere) VALUES (?, ?, ?, ?)";
|
||||
KeyHolder keyHolder = new GeneratedKeyHolder();
|
||||
jdbcTemplate.update(sql, enchere.getNoUtilisateur(), enchere.getNoArticle(), enchere.getDateEnchere(), enchere.getMontantEnchere());
|
||||
if (keyHolder.getKey() != null) {
|
||||
enchere.setId(keyHolder.getKey().intValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</div>
|
||||
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
|
||||
<strong><label class="col-form-label">Vendeur</label></strong>
|
||||
<span th:text="${username}"></span>
|
||||
<span th:text="${username.pseudo}"></span>
|
||||
</div>
|
||||
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
|
||||
<strong><label class="col-form-label">Catégorie</label></strong>
|
||||
@@ -40,6 +40,18 @@
|
||||
<strong><label class="col-form-label">Date fin enchère</label></strong>
|
||||
<span th:text="${article.dateFinEnch}"></span>
|
||||
</div>
|
||||
<!-- Rajouter une condition sur retrait pour l'afficher uniquement quand -->
|
||||
<!-- la vente est gagné ET à l'utilisateur qui a remporté la vente-->
|
||||
<div class="mt-2 d-flex flex-row align-items-end justify-content-between">
|
||||
<strong><label class="col-form-label">Retrait</label></strong>
|
||||
<span th:text="${retrait} ? ${retrait.rue} + ' ' + ${retrait.code_postale} + ' ' + ${retrait.ville} : 'Adresse inconnue'"></span>
|
||||
</div>
|
||||
<form th:action="@{/enchere/incEnchere}" method="post" th:object="${enchere}" class="mt-2 d-flex flex-row align-items-end justify-content-between">
|
||||
<input type="hidden" id="articleId" name="articleId" th:value="${article.id}">
|
||||
<label for="montantEnchere">Montant</label>
|
||||
<input type="number" th:field="*{montantEnchere}" id="montantEnchere">
|
||||
<button type="submit" class="btn btn-primary">Enchérir</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user