From 94d672c0f606650b5f5e901c4e977102e8af7877 Mon Sep 17 00:00:00 2001 From: Youssef Date: Mon, 29 Jun 2026 14:54:36 +0200 Subject: [PATCH] feat: handle goalkeeper vs field player equipment differentiation --- .../com/astalange/core/entity/Equipement.java | 6 ++++ .../core/service/CategorieService.java | 24 ++++++++++++++-- .../V33__add_type_public_to_equipement.sql | 1 + .../web/controller/AdherentController.java | 28 ++++++++++++------- .../parametrage/equipements_form.html | 9 ++++++ 5 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 as-talange-core/src/main/resources/db/migration/V33__add_type_public_to_equipement.sql diff --git a/as-talange-core/src/main/java/com/astalange/core/entity/Equipement.java b/as-talange-core/src/main/java/com/astalange/core/entity/Equipement.java index 5ec1adc..e63fd76 100644 --- a/as-talange-core/src/main/java/com/astalange/core/entity/Equipement.java +++ b/as-talange-core/src/main/java/com/astalange/core/entity/Equipement.java @@ -23,6 +23,9 @@ public class Equipement { @Column(name = "gestion_sexe", nullable = false) private boolean gestionSexe = false; + @Column(name = "type_public", nullable = false, length = 20) + private String typePublic = "TOUS"; // JOUEUR, GARDIEN, TOUS + @Column(name = "tailles_disponibles", length = 500) private String taillesDisponibles; @@ -51,6 +54,9 @@ public class Equipement { public boolean isGestionSexe() { return gestionSexe; } public void setGestionSexe(boolean gestionSexe) { this.gestionSexe = gestionSexe; } + public String getTypePublic() { return typePublic; } + public void setTypePublic(String typePublic) { this.typePublic = typePublic; } + public String getTaillesDisponibles() { return taillesDisponibles; } public void setTaillesDisponibles(String taillesDisponibles) { this.taillesDisponibles = taillesDisponibles; } diff --git a/as-talange-core/src/main/java/com/astalange/core/service/CategorieService.java b/as-talange-core/src/main/java/com/astalange/core/service/CategorieService.java index 78dddbb..dae2fe7 100644 --- a/as-talange-core/src/main/java/com/astalange/core/service/CategorieService.java +++ b/as-talange-core/src/main/java/com/astalange/core/service/CategorieService.java @@ -86,12 +86,21 @@ public class CategorieService { List currentDotations = licence.getDotations(); List toRemove = new ArrayList<>(); - // Remove dotations for equipements no longer in the category + // Remove dotations for equipements no longer in the category or not matching public for (Dotation d : currentDotations) { boolean found = false; for (CategorieEquipement ce : categorieEquipements) { if (ce.getEquipement().getId().equals(d.getEquipement().getId())) { - found = true; + String typePublic = ce.getEquipement().getTypePublic(); + String typeMaillot = licence.getAdherent() != null ? licence.getAdherent().getTypeMaillot() : "JOUEUR"; + + boolean matchPublic = "TOUS".equals(typePublic) || + ("GARDIEN".equals(typePublic) && "GARDIEN".equals(typeMaillot)) || + ("JOUEUR".equals(typePublic) && "JOUEUR".equals(typeMaillot)); + + if (matchPublic) { + found = true; + } break; } } @@ -103,6 +112,17 @@ public class CategorieService { // Add missing dotations for (CategorieEquipement ce : categorieEquipements) { + String typePublic = ce.getEquipement().getTypePublic(); + String typeMaillot = licence.getAdherent() != null ? licence.getAdherent().getTypeMaillot() : "JOUEUR"; + + boolean matchPublic = "TOUS".equals(typePublic) || + ("GARDIEN".equals(typePublic) && "GARDIEN".equals(typeMaillot)) || + ("JOUEUR".equals(typePublic) && "JOUEUR".equals(typeMaillot)); + + if (!matchPublic) { + continue; + } + boolean found = false; for (Dotation d : currentDotations) { if (ce.getEquipement().getId().equals(d.getEquipement().getId())) { diff --git a/as-talange-core/src/main/resources/db/migration/V33__add_type_public_to_equipement.sql b/as-talange-core/src/main/resources/db/migration/V33__add_type_public_to_equipement.sql new file mode 100644 index 0000000..ed38a75 --- /dev/null +++ b/as-talange-core/src/main/resources/db/migration/V33__add_type_public_to_equipement.sql @@ -0,0 +1 @@ +ALTER TABLE equipement ADD COLUMN type_public VARCHAR(20) DEFAULT 'TOUS' NOT NULL; diff --git a/as-talange-web/src/main/java/com/astalange/web/controller/AdherentController.java b/as-talange-web/src/main/java/com/astalange/web/controller/AdherentController.java index 6ed6def..c5060a6 100644 --- a/as-talange-web/src/main/java/com/astalange/web/controller/AdherentController.java +++ b/as-talange-web/src/main/java/com/astalange/web/controller/AdherentController.java @@ -177,21 +177,29 @@ public class AdherentController { Adherent existing = adherentRepository.findById(adherent.getId()).orElse(null); if (existing != null) { boolean dateChanged = !existing.getDateNaissance().equals(adherent.getDateNaissance()); + boolean typeMaillotChanged = !existing.getTypeMaillot().equals(adherent.getTypeMaillot()); - if (dateChanged) { + if (dateChanged || typeMaillotChanged) { int newBirthYear = adherent.getDateNaissance().getYear(); List licences = licenceRepository.findByAdherentId(adherent.getId()); for (Licence licence : licences) { - Saison saison = licence.getSaison(); - Categorie newCat = categorieRepository.findBySaison(saison).stream() - .filter(c -> newBirthYear >= c.getAnneeMin() && newBirthYear <= c.getAnneeMax()) - .findFirst() - .orElse(null); - if (newCat != null) { - licence.setCategorie(newCat); - licence = licenceRepository.save(licence); - categorieService.syncDotationsForLicence(licence); + if (dateChanged) { + Saison saison = licence.getSaison(); + Categorie newCat = categorieRepository.findBySaison(saison).stream() + .filter(c -> newBirthYear >= c.getAnneeMin() && newBirthYear <= c.getAnneeMax()) + .findFirst() + .orElse(null); + if (newCat != null) { + licence.setCategorie(newCat); + licence = licenceRepository.save(licence); + } } + + // We need to update the entity's state before syncing dotations so it reads the new typeMaillot. + // We haven't updated 'existing' yet, so let's temporarily set it on the licence's adherent or wait. + // Actually, 'adherent' has the new typeMaillot. + licence.getAdherent().setTypeMaillot(adherent.getTypeMaillot()); + categorieService.syncDotationsForLicence(licence); } } diff --git a/as-talange-web/src/main/resources/templates/parametrage/equipements_form.html b/as-talange-web/src/main/resources/templates/parametrage/equipements_form.html index 053034a..0c2fb06 100644 --- a/as-talange-web/src/main/resources/templates/parametrage/equipements_form.html +++ b/as-talange-web/src/main/resources/templates/parametrage/equipements_form.html @@ -45,6 +45,15 @@ +
+ + +
+