feat: ajout du système d'invitations SportEasy et suivi des emails
This commit is contained in:
@@ -24,14 +24,16 @@ public class AdherentController {
|
||||
private final com.astalange.core.repository.ModePaiementRepository modePaiementRepository;
|
||||
private final SaisonRepository saisonRepository;
|
||||
private final com.astalange.core.service.CategorieService categorieService;
|
||||
private final com.astalange.core.service.SportEasyEmailService sportEasyEmailService;
|
||||
|
||||
public AdherentController(AdherentRepository adherentRepository, CategorieRepository categorieRepository, com.astalange.core.repository.LicenceRepository licenceRepository, com.astalange.core.repository.ModePaiementRepository modePaiementRepository, SaisonRepository saisonRepository, com.astalange.core.service.CategorieService categorieService) {
|
||||
public AdherentController(AdherentRepository adherentRepository, CategorieRepository categorieRepository, com.astalange.core.repository.LicenceRepository licenceRepository, com.astalange.core.repository.ModePaiementRepository modePaiementRepository, SaisonRepository saisonRepository, com.astalange.core.service.CategorieService categorieService, com.astalange.core.service.SportEasyEmailService sportEasyEmailService) {
|
||||
this.adherentRepository = adherentRepository;
|
||||
this.categorieRepository = categorieRepository;
|
||||
this.licenceRepository = licenceRepository;
|
||||
this.modePaiementRepository = modePaiementRepository;
|
||||
this.saisonRepository = saisonRepository;
|
||||
this.categorieService = categorieService;
|
||||
this.sportEasyEmailService = sportEasyEmailService;
|
||||
}
|
||||
|
||||
@org.springframework.web.bind.annotation.ModelAttribute("equipes")
|
||||
@@ -48,6 +50,7 @@ public class AdherentController {
|
||||
@org.springframework.web.bind.annotation.RequestParam(required = false) String licence,
|
||||
@org.springframework.web.bind.annotation.RequestParam(required = false) String email,
|
||||
@org.springframework.web.bind.annotation.RequestParam(required = false) String paiement,
|
||||
@org.springframework.web.bind.annotation.RequestParam(required = false) String sporteasy,
|
||||
@org.springframework.web.bind.annotation.RequestParam(required = false, defaultValue = "nom") String sortField,
|
||||
@org.springframework.web.bind.annotation.RequestParam(required = false, defaultValue = "asc") String sortDirection,
|
||||
@org.springframework.web.bind.annotation.RequestParam(defaultValue = "0") int page,
|
||||
@@ -114,6 +117,21 @@ public class AdherentController {
|
||||
}).collect(java.util.stream.Collectors.toList());
|
||||
model.addAttribute("paiementFilter", paiement.trim());
|
||||
}
|
||||
if (sporteasy != null && !sporteasy.trim().isEmpty()) {
|
||||
adherents = adherents.stream().filter(a -> {
|
||||
Licence lic = a.getLicenceActuelle();
|
||||
if (lic == null) return false;
|
||||
if ("NON_INVITE".equalsIgnoreCase(sporteasy)) {
|
||||
return !lic.isRenouvellement() && !Boolean.TRUE.equals(lic.getSportEasyEmailSent());
|
||||
} else if ("INVITE".equalsIgnoreCase(sporteasy)) {
|
||||
return !lic.isRenouvellement() && Boolean.TRUE.equals(lic.getSportEasyEmailSent());
|
||||
} else if ("RENOUVELLEMENT".equalsIgnoreCase(sporteasy)) {
|
||||
return lic.isRenouvellement();
|
||||
}
|
||||
return true;
|
||||
}).collect(java.util.stream.Collectors.toList());
|
||||
model.addAttribute("sporteasyFilter", sporteasy.trim());
|
||||
}
|
||||
|
||||
// 3. Sort
|
||||
java.util.Comparator<Adherent> comparator = (a1, a2) -> 0;
|
||||
@@ -284,4 +302,57 @@ public class AdherentController {
|
||||
adherentRepository.delete(adherent);
|
||||
return "redirect:/adherents";
|
||||
}
|
||||
|
||||
@org.springframework.web.bind.annotation.PostMapping("/{id}/sporteasy-invite")
|
||||
public String sendSportEasyInvite(
|
||||
@org.springframework.web.bind.annotation.PathVariable Long id,
|
||||
@org.springframework.web.bind.annotation.RequestParam(required = false, defaultValue = "false") boolean force,
|
||||
org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes) {
|
||||
|
||||
Saison activeSaison = saisonRepository.findByEstActiveTrue().orElse(null);
|
||||
if (activeSaison == null) {
|
||||
redirectAttributes.addFlashAttribute("errorMessage", "Erreur : Aucune saison active trouvée.");
|
||||
return "redirect:/adherents";
|
||||
}
|
||||
|
||||
Licence licence = licenceRepository.findByAdherentIdAndSaison(id, activeSaison).orElse(null);
|
||||
if (licence == null) {
|
||||
redirectAttributes.addFlashAttribute("errorMessage", "Cet adhérent n'a pas de licence pour la saison active.");
|
||||
return "redirect:/adherents";
|
||||
}
|
||||
|
||||
if (licence.isRenouvellement()) {
|
||||
redirectAttributes.addFlashAttribute("infoMessage", "Les invitations SportEasy sont réservées aux nouveaux adhérents (nouvelle licence).");
|
||||
return "redirect:/adherents";
|
||||
}
|
||||
|
||||
try {
|
||||
boolean success = sportEasyEmailService.sendInvitationForLicence(licence.getId(), force);
|
||||
if (success) {
|
||||
redirectAttributes.addFlashAttribute("successMessage", "L'invitation SportEasy a été envoyée avec succès à l'adhérent.");
|
||||
} else {
|
||||
redirectAttributes.addFlashAttribute("infoMessage", "L'invitation SportEasy avait déjà été envoyée à cet adhérent.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
redirectAttributes.addFlashAttribute("errorMessage", "Erreur lors de l'envoi de l'invitation : " + e.getMessage());
|
||||
}
|
||||
|
||||
return "redirect:/adherents";
|
||||
}
|
||||
|
||||
@org.springframework.web.bind.annotation.PostMapping("/sporteasy-invite-batch")
|
||||
public String sendSportEasyInviteBatch(
|
||||
@org.springframework.web.bind.annotation.RequestParam(required = false) Long categoryId,
|
||||
org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes) {
|
||||
|
||||
try {
|
||||
com.astalange.core.service.SportEasyEmailService.BatchSendResult result =
|
||||
sportEasyEmailService.sendBatchInvitationsForActiveSaison(categoryId);
|
||||
redirectAttributes.addFlashAttribute("successMessage", result.message());
|
||||
} catch (Exception e) {
|
||||
redirectAttributes.addFlashAttribute("errorMessage", "Erreur lors de l'envoi des invitations SportEasy : " + e.getMessage());
|
||||
}
|
||||
|
||||
return "redirect:/adherents";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user