merge conflict
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;
|
||||
}
|
||||
|
||||
@@ -63,9 +63,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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user