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);
}
}

View File

@@ -133,6 +133,9 @@ article.details.ench = Bidders
article.details.lastof = Last Bid
article.details.label.last_price = Current sale price
article.details.label.start_date = Start date
article.details.noWin = Article - No one has made an offer
article.details.winBy = Article - offer won by
article.details.winByYou = you
edit.article.title = Edit my article
edit.article.update = Edit

View File

@@ -135,7 +135,9 @@ article.details.ench = Ench\u00E9risseurs
article.details.lastof = Derni\u00E9re offre
article.details.label.last_price = Prix de vente actuel
article.details.label.start_date = Date de debut
article.details.noWin = Article - Personne n'a fait d'offre
article.details.winBy = Article - offre remport\u00E9 par
article.details.winByYou = vous
edit.article.title = Modifier mon article

View File

@@ -12,8 +12,8 @@
<h4 th:text="'Article - offre en cours'"></h4>
</div>
<div class="card-header" th:unless="${#dates.format(article.dateFinEnch, 'yyyy-MM-dd')} > ${#dates.format(#dates.createNow(), 'yyyy-MM-dd')}">
<h4 th:if="${maxEncherePseudo} != null" th:text="'Article - offre remporté par ' + (${#authentication.getName() == maxEncherePseudo ? 'vous' : maxEncherePseudo})"></h4>
<h4 th:unless="${maxEncherePseudo} != null" th:text="'Article - Personne n\'a fait d\'offre'"></h4>
<h4 th:if="${maxEncherePseudo} != null" th:text="#{article.details.winBy} + ' ' + (${#authentication.getName() == maxEncherePseudo ? #{article.details.winByYou} : maxEncherePseudo})"></h4>
<h4 th:unless="${maxEncherePseudo} != null" th:text="#{article.details.noWin}"></h4>
</div>
<div class="card-body">
<div class="row">