feat: ajouter l'envoi par e-mail du planning hebdomadaire global aux éducateurs
This commit is contained in:
@@ -7,6 +7,7 @@ import com.astalange.core.repository.EducateurRepository;
|
||||
import com.astalange.core.repository.EquipeRepository;
|
||||
import com.astalange.core.repository.SaisonRepository;
|
||||
import com.astalange.core.repository.TerrainRepository;
|
||||
import com.astalange.core.service.PlanningEmailService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
@@ -25,19 +26,22 @@ public class PlanningController {
|
||||
private final SaisonRepository saisonRepository;
|
||||
private final EquipeRepository equipeRepository;
|
||||
private final EducateurRepository educateurRepository;
|
||||
private final PlanningEmailService planningEmailService;
|
||||
|
||||
public PlanningController(CreneauEntrainementRepository creneauRepository,
|
||||
TerrainRepository terrainRepository,
|
||||
CategorieRepository categorieRepository,
|
||||
SaisonRepository saisonRepository,
|
||||
EquipeRepository equipeRepository,
|
||||
EducateurRepository educateurRepository) {
|
||||
EducateurRepository educateurRepository,
|
||||
PlanningEmailService planningEmailService) {
|
||||
this.creneauRepository = creneauRepository;
|
||||
this.terrainRepository = terrainRepository;
|
||||
this.categorieRepository = categorieRepository;
|
||||
this.saisonRepository = saisonRepository;
|
||||
this.equipeRepository = equipeRepository;
|
||||
this.educateurRepository = educateurRepository;
|
||||
this.planningEmailService = planningEmailService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -202,4 +206,16 @@ public class PlanningController {
|
||||
redirectAttributes.addFlashAttribute("success", "Créneau d'entraînement supprimé avec succès.");
|
||||
return "redirect:/planning?jour=" + jour.name();
|
||||
}
|
||||
|
||||
@PostMapping("/envoyer-educateurs")
|
||||
public String envoyerPlanningEducateurs(@RequestParam(required = false) JourSemaine jour, RedirectAttributes redirectAttributes) {
|
||||
int count = planningEmailService.sendPlanningGlobalToEducateurs();
|
||||
if (count > 0) {
|
||||
redirectAttributes.addFlashAttribute("success", "Le planning global de la semaine a été envoyé par e-mail à " + count + " éducateur(s).");
|
||||
} else {
|
||||
redirectAttributes.addFlashAttribute("error", "Aucun e-mail n'a pu être envoyé. Vérifiez qu'une saison est active et que des éducateurs possèdent un e-mail valide.");
|
||||
}
|
||||
String returnJour = (jour != null) ? jour.name() : "LUNDI";
|
||||
return "redirect:/planning?jour=" + returnJour;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,13 +48,26 @@
|
||||
<div th:if="${success}" class="bg-green-50 border-l-4 border-green-500 p-4 mb-6 rounded-lg">
|
||||
<p class="text-sm text-green-700 font-medium" th:text="${success}"></p>
|
||||
</div>
|
||||
<div th:if="${error}" class="bg-red-50 border-l-4 border-red-500 p-4 mb-6 rounded-lg">
|
||||
<p class="text-sm text-red-700 font-medium" th:text="${error}"></p>
|
||||
</div>
|
||||
|
||||
<!-- Page actions -->
|
||||
<div class="flex justify-between items-center mb-6" th:if="${saisonActive != null}">
|
||||
<h3 class="text-xl font-bold text-gray-900">Planning Hebdomadaire</h3>
|
||||
<a th:href="@{/planning/new}" class="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-blue-700 shadow transition-colors">
|
||||
+ Ajouter un Créneau
|
||||
</a>
|
||||
<div class="flex items-center space-x-3">
|
||||
<form th:action="@{/planning/envoyer-educateurs(jour=${selectedDay != null ? selectedDay.name() : 'LUNDI'})}" method="post" onsubmit="return confirm('Êtes-vous sûr de vouloir envoyer le planning global de la semaine par e-mail à tous les éducateurs ?');">
|
||||
<button type="submit" class="bg-emerald-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-emerald-700 shadow transition-colors flex items-center space-x-2">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
|
||||
</svg>
|
||||
<span>Envoyer le planning aux éducateurs</span>
|
||||
</button>
|
||||
</form>
|
||||
<a th:href="@{/planning/new}" class="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-blue-700 shadow transition-colors">
|
||||
+ Ajouter un Créneau
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabs: Days of the week -->
|
||||
|
||||
Reference in New Issue
Block a user