Merge branch 'Olivier'

This commit is contained in:
Parpaillax
2024-04-30 16:53:49 +02:00
4 changed files with 28 additions and 10 deletions

View File

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

View File

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

View File

@@ -8,8 +8,11 @@
<div class="row mt-3 justify-content-center">
<div class="col-12 col-md-8 col-lg-6"> <!-- Utilisation de classes Bootstrap pour rendre la colonne responsive -->
<div class="card" >
<div class="card-header">
<h4 th:text="#{article.details.heading}"></h4>
<div class="card-header" th:if="${#dates.format(article.dateFinEnch, 'yyyy-MM-dd')} > ${#dates.format(#dates.createNow(), 'yyyy-MM-dd')}">
<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:text="'Article - offre remporté par ' + (${#authentication.getName() == maxEncherePseudo ? 'vous' : maxEncherePseudo})"></h4>
</div>
<div class="card-body">
<div class="row">
@@ -51,13 +54,13 @@
<strong><label class="col-form-label" th:text="#{article.details.label.pickup}"></label></strong>
<span th:text="${retrait} ? ${retrait.rue} + ' ' + ${retrait.code_postale} + ' ' + ${retrait.ville} : #{article.details.address.unknown}"></span>
</div>
<form th:if="${!isArticleCurrentUser}" th:action="@{/enchere/incEnchere}" method="post" th:object="${enchere}" class="mt-2 d-flex flex-row align-items-end justify-content-between">
<form th:if="${!isArticleCurrentUser} and ${#dates.format(article.dateFinEnch, 'yyyy-MM-dd')} > ${#dates.format(#dates.createNow(), 'yyyy-MM-dd')}" th:action="@{/enchere/incEnchere}" method="post" th:object="${enchere}" class="mt-2 d-flex flex-row align-items-end justify-content-between">
<input type="hidden" id="articleId" name="articleId" th:value="${article.id}">
<label for="montantEnchere" th:text="#{article.details.label.amount}"></label>
<input type="number" th:field="*{montantEnchere}" id="montantEnchere" step="0.01" min="0">
<span style="color: red;" th:if="${#fields.hasErrors('montantEnchere')}">
<span style="color: red;" th:if="${errors != null}">
<ul>
<li th:each="erreur: ${#fields.errors('montantEnchere')}" th:text="${erreur}"></li>
<li th:each="erreur: ${errors[0]}" th:text="${erreur.defaultMessage}"></li>
</ul>
</span>
<button type="submit" class="btn btn-primary" th:text="#{article.details.button.bid}"></button>

View File

@@ -70,7 +70,7 @@
</div>
</form>
<div class="d-flex justify-content-end align-items-center mt-2">
<form th:action="@{/article/delete}" method="post" th:if="">
<form th:action="@{/article/delete}" method="post">
<input type="hidden" name="articleId" id="articleId" th:value="${article.id}">
<button type="submit" class="btn btn-danger" th:text="#{edit.article.delete}"></button>
</form>