error enchere

This commit is contained in:
Parpaillax
2024-04-26 11:28:09 +02:00
parent dd938c52b8
commit b2175b7f96
4 changed files with 18 additions and 7 deletions

View File

@@ -43,7 +43,9 @@ public class EnchereController {
//Empeche une enchere inférieur au prix de base de l'article
Article article = this.articleService.findArticleById(articleId);
if (enchere.getMontantEnchere() < article.getPrixInitial()) {
float articlePrice = article.getPrixInitial();
float encherePrice = enchere.getMontantEnchere();
if (encherePrice < articlePrice) {
result.rejectValue("montantEnchere", "error.enchere", "Vous ne pouvez pas enchérir un montant inférieur au prix initial");
}
@@ -53,10 +55,14 @@ public class EnchereController {
.map(Enchere::getMontantEnchere) // Récupère seulement les montants d'enchère
.max(Float::compareTo);
System.out.println(maxMontantEnchere);
if (enchere.getMontantEnchere() < maxMontantEnchere.get()) {
if (maxMontantEnchere.isPresent() && encherePrice < maxMontantEnchere.get()) {
result.rejectValue("montantEnchere", "error.enchere", "Vous ne pouvez pas enchérir un montant inférieur à la dernière enchère");
}
if (result.hasErrors()) {
return "redirect:/article/show?id=" + articleId;
}
this.enchereService.setEnchere(enchere);
return "redirect:/article/show?id=" + articleId;
}