patch translate et retrait article non enchérie

This commit is contained in:
jleroy
2024-05-03 08:20:34 +02:00
parent 22ba905312
commit 4243b1ebdf
5 changed files with 38 additions and 29 deletions

View File

@@ -91,36 +91,40 @@ public class EnchereController {
@PostMapping("/enchereDone")
public String enchereDone(@RequestParam("id") int id) {
List<Enchere> listEncheres = this.enchereService.enchereByArticle(id);
if (!listEncheres.isEmpty()){
List<Enchere> encheres = listEncheres.stream()
.sorted(Comparator.comparing(Enchere::getMontantEnchere).reversed())
.collect(Collectors.toList());
Optional<String> pseudoMaxEnchere = encheres.stream()
.max(Comparator.comparing(Enchere::getMontantEnchere)) // Comparaison basée sur le montant d'enchère
.map(Enchere::getPseudoUtilisateur);
UserProfil user = this.userService.utilisateurByName(pseudoMaxEnchere.get());
//Get seller
Article articleSell = articleService.findArticleById(id);
UserProfil userSeller = userService.utilisateurById(articleSell.getUtilisateur());
Optional<Float> maxMontantEnchere = listEncheres.stream()
.map(Enchere::getMontantEnchere) // Récupère seulement les montants d'enchère
.max(Float::compareTo);
List<Enchere> encheres = listEncheres.stream()
.sorted(Comparator.comparing(Enchere::getMontantEnchere).reversed())
.collect(Collectors.toList());
Optional<String> pseudoMaxEnchere = encheres.stream()
.max(Comparator.comparing(Enchere::getMontantEnchere)) // Comparaison basée sur le montant d'enchère
.map(Enchere::getPseudoUtilisateur);
UserProfil user = this.userService.utilisateurByName(pseudoMaxEnchere.get());
//Get seller
Article articleSell = articleService.findArticleById(id);
UserProfil userSeller = userService.utilisateurById(articleSell.getUtilisateur());
Optional<Float> maxMontantEnchere = listEncheres.stream()
.map(Enchere::getMontantEnchere) // Récupère seulement les montants d'enchère
.max(Float::compareTo);
//setCredit user.
float newCredit = user.getCredit() - maxMontantEnchere.get();
this.userService.setCredit(newCredit, user.getId());
//setCredit user.
float newCredit = user.getCredit() - maxMontantEnchere.get();
this.userService.setCredit(newCredit, user.getId());
//set sell price
this.articleService.setSellPrice(id, maxMontantEnchere.get());
//Delete enchere
for (Enchere ench : listEncheres) {
this.enchereService.deleteEnchere(ench.getId());
//Crédit selleur
float sellerCredit = userSeller.getCredit() + maxMontantEnchere.get();
this.userService.setCredit(sellerCredit, userSeller.getId());
//Delete enchere
for (Enchere ench : listEncheres) {
this.enchereService.deleteEnchere(ench.getId());
}
}
//Delete article
this.articleService.setSellPrice(id, maxMontantEnchere.get());
//Crédit selleur
float sellerCredit = userSeller.getCredit() + maxMontantEnchere.get();
this.userService.setCredit(sellerCredit, userSeller.getId());
//Delete Article
this.articleService.deleteArticle(id);
return "redirect:/enchere";
}

View File

@@ -371,7 +371,7 @@ public class ArticleRepositoryImpl implements ArticleRepository {
@Override
public void setSellPrice(int id, float price) {
String sql = "UPDATE ARTICLES_VENDUS SET prix_vente = ?, isDelete = 1 WHERE no_article = ?";
String sql = "UPDATE ARTICLES_VENDUS SET prix_vente = ? WHERE no_article = ?";
jdbcTemplate.update(sql, price, id);
}
}