feat: add category duplication functionality

This commit is contained in:
2026-07-07 21:54:38 +02:00
parent 29f9dc3bc2
commit a7c5b23198
4 changed files with 81 additions and 3 deletions
@@ -149,7 +149,18 @@ public class CategorieService {
newDotation.setTaille("");
newDotation.setNumero("");
if (licence.getAdherent() != null) {
newDotation.setFlocage(licence.getAdherent().getNom().toUpperCase() + " " + licence.getAdherent().getPrenom());
String defaultFlocage = "";
if (ce.getEquipement().isHasFlocagePrenom() && ce.getEquipement().isHasFlocageInitiales()) {
String firstInitial = licence.getAdherent().getNom() != null && !licence.getAdherent().getNom().isEmpty() ? licence.getAdherent().getNom().substring(0, 1).toUpperCase() + "." : "";
defaultFlocage = (licence.getAdherent().getPrenom() != null ? licence.getAdherent().getPrenom() + " " : "") + firstInitial;
} else if (ce.getEquipement().isHasFlocagePrenom()) {
defaultFlocage = licence.getAdherent().getPrenom() != null ? licence.getAdherent().getPrenom() : "";
} else if (ce.getEquipement().isHasFlocageInitiales()) {
String firstInitP = licence.getAdherent().getPrenom() != null && !licence.getAdherent().getPrenom().isEmpty() ? licence.getAdherent().getPrenom().substring(0, 1).toUpperCase() : "";
String firstInitN = licence.getAdherent().getNom() != null && !licence.getAdherent().getNom().isEmpty() ? licence.getAdherent().getNom().substring(0, 1).toUpperCase() : "";
defaultFlocage = firstInitP + firstInitN;
}
newDotation.setFlocage(defaultFlocage.trim());
}
currentDotations.add(newDotation);
}
@@ -157,4 +168,37 @@ public class CategorieService {
licenceRepository.save(licence);
}
@Transactional
public Categorie duplicateCategorie(Long id) {
Categorie existing = categorieRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid category ID: " + id));
Categorie duplicated = new Categorie();
// Appending ' (dupliqué)' and truncating if necessary since nom is max 20 chars
String newNom = existing.getNom() + " (dupliqué)";
if (newNom.length() > 20) {
newNom = newNom.substring(0, 20);
}
duplicated.setNom(newNom);
duplicated.setSexe(existing.getSexe());
duplicated.setAnneeMin(existing.getAnneeMin());
duplicated.setAnneeMax(existing.getAnneeMax());
duplicated.setTarifBase(existing.getTarifBase());
duplicated.setTarifExterieur(existing.getTarifExterieur());
duplicated.setSaison(existing.getSaison());
List<CategorieEquipement> nouveauxEquipements = new ArrayList<>();
for (CategorieEquipement ce : existing.getCategorieEquipements()) {
CategorieEquipement newCe = new CategorieEquipement();
newCe.setCategorie(duplicated);
newCe.setEquipement(ce.getEquipement());
newCe.setObligatoire(ce.getObligatoire());
newCe.setPrix(ce.getPrix() != null ? ce.getPrix() : java.math.BigDecimal.ZERO);
nouveauxEquipements.add(newCe);
}
duplicated.getCategorieEquipements().addAll(nouveauxEquipements);
return categorieRepository.save(duplicated);
}
}