feat: restrict license creation to only one license per adherent
This commit is contained in:
@@ -48,6 +48,12 @@ public class LicenceController {
|
|||||||
|
|
||||||
Adherent adherent = adherentRepository.findById(id)
|
Adherent adherent = adherentRepository.findById(id)
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Invalid Adherent ID"));
|
.orElseThrow(() -> new IllegalArgumentException("Invalid Adherent ID"));
|
||||||
|
|
||||||
|
List<Licence> existingLicences = licenceRepository.findByAdherentId(id);
|
||||||
|
if (!existingLicences.isEmpty()) {
|
||||||
|
return "redirect:/adherents/" + id + "/edit";
|
||||||
|
}
|
||||||
|
|
||||||
Categorie categorie = categorieRepository.findById(categorieId)
|
Categorie categorie = categorieRepository.findById(categorieId)
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Invalid Categorie ID"));
|
.orElseThrow(() -> new IllegalArgumentException("Invalid Categorie ID"));
|
||||||
|
|
||||||
|
|||||||
@@ -144,7 +144,7 @@
|
|||||||
<div th:if="${adherent.id != null}" class="max-w-3xl mx-auto bg-white rounded-xl shadow-sm border border-gray-100 p-8 mt-6">
|
<div th:if="${adherent.id != null}" class="max-w-3xl mx-auto bg-white rounded-xl shadow-sm border border-gray-100 p-8 mt-6">
|
||||||
<div class="flex justify-between items-center mb-6">
|
<div class="flex justify-between items-center mb-6">
|
||||||
<h3 class="text-xl font-bold text-gray-900">Licences de l'adhérent</h3>
|
<h3 class="text-xl font-bold text-gray-900">Licences de l'adhérent</h3>
|
||||||
<button onclick="openLicenceModal()" class="bg-green-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-green-700 transition-colors">
|
<button th:if="${#lists.isEmpty(licences)}" onclick="openLicenceModal()" class="bg-green-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-green-700 transition-colors">
|
||||||
+ Ajouter une Licence
|
+ Ajouter une Licence
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user