Merge branch 'Olivier'
This commit is contained in:
@@ -74,7 +74,12 @@ public class ArticleController {
|
||||
lastEnchere = lastEnchere.stream()
|
||||
.sorted(Comparator.comparing(Enchere::getMontantEnchere).reversed())
|
||||
.collect(Collectors.toList());
|
||||
Optional<String> pseudoMaxEnchere = lastEnchere.stream()
|
||||
.max(Comparator.comparing(Enchere::getMontantEnchere)) // Comparaison basée sur le montant d'enchère
|
||||
.map(Enchere::getPseudoUtilisateur);
|
||||
|
||||
model.addAttribute("encheres", lastEnchere);
|
||||
model.addAttribute("maxEncherePseudo", pseudoMaxEnchere.orElse(""));
|
||||
model.addAttribute("isArticleCurrentUser", isArticleCurrentUser);
|
||||
model.addAttribute("article", article);
|
||||
model.addAttribute("username", user);
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -66,12 +67,21 @@ public class EnchereController {
|
||||
result.rejectValue("montantEnchere", "error.enchere", "Vous ne pouvez pas enchérir si vous n'avez pas les fonds suffisant");
|
||||
}
|
||||
|
||||
Optional<String> pseudoMaxEnchere = lastEnchere.stream()
|
||||
.max(Comparator.comparing(Enchere::getMontantEnchere)) // Comparaison basée sur le montant d'enchère
|
||||
.map(Enchere::getPseudoUtilisateur);
|
||||
if (pseudoMaxEnchere.get().equals(authentication.getName())) {
|
||||
result.rejectValue("montantEnchere", "error.enchere", "Vous ne pouvez pas enchèrir sur votre propre offre");
|
||||
}
|
||||
|
||||
if (result.hasErrors()) {
|
||||
session.setAttribute("errors", result.getAllErrors());
|
||||
return "redirect:/article/show?id=" + articleId;
|
||||
}
|
||||
|
||||
this.enchereService.setEnchere(enchere);
|
||||
float newCredit = userCredit - enchere.getMontantEnchere();
|
||||
this.userService.setCredit(newCredit, this.userService.utilisateurByName(authentication.getName()).getId());
|
||||
return "redirect:/article/show?id=" + articleId;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user