Skip to content
Snippets Groups Projects
Commit c1a02578 authored by Jessie Ragot's avatar Jessie Ragot
Browse files

Implementation of the my patients and my doctor buttons on the 2 patient and...

Implementation of the my patients and my doctor buttons on the 2 patient and doctor dashboards, dynamic redirection according to role using the AuthController controller for the patients.html and doctors.html templates
parent d2ca23b4
Branches
No related tags found
No related merge requests found
package com.projet.projetIndu.controllers;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.util.Collection;
@Controller
public class AuthController {
@GetMapping("/redirect")
public String redirectUser(Authentication authentication, RedirectAttributes redirectAttributes) {
if (authentication != null) {
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
for (GrantedAuthority authority : authorities) {
String role = authority.getAuthority();
if ("ADMIN".equals(role)) {
return "redirect:/admin/dashboard";
} else if ("DOCTOR".equals(role)) {
return "redirect:/doctors/dashboard";
} else if ("PATIENT".equals(role)) {
return "redirect:/patients/dashboard";
}
}
}
return "redirect:/";
}
}
package com.projet.projetIndu.controllers;
import com.projet.projetIndu.entities.Doctor;
import com.projet.projetIndu.entities.Patient;
import com.projet.projetIndu.services.DoctorService;
import com.projet.projetIndu.services.PatientService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -14,10 +16,12 @@ import java.util.List;
@Controller
public class DoctorController {
private final DoctorService doctorService;
private final PatientService patientService;
public DoctorController(DoctorService doctorService) {
public DoctorController(DoctorService doctorService, PatientService patientService) {
this.doctorService = doctorService;
this.patientService = patientService;
}
@GetMapping
......@@ -38,4 +42,11 @@ public class DoctorController {
public String showDoctorDashboard(Model model) {
return "doctor-dashboard";
}
@GetMapping("/patients")
public String listPatients(Model model) {
List<Patient> patients = patientService.getAllPatients();
model.addAttribute("patients", patients);
return "patients";
}
}
package com.projet.projetIndu.controllers;
import com.projet.projetIndu.entities.Doctor;
import com.projet.projetIndu.entities.Patient;
import com.projet.projetIndu.services.DoctorService;
import com.projet.projetIndu.services.PatientService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -12,14 +14,14 @@ import java.util.Optional;
@RequestMapping("/patients")
@Controller
public class PatientController {
private final PatientService patientService;
private final DoctorService doctorService;
public PatientController(PatientService patientService) {
public PatientController(PatientService patientService, DoctorService doctorService) {
this.patientService = patientService;
this.doctorService = doctorService;
}
// Afficher tous les patients
@GetMapping
public String listPatients(Model model) {
List<Patient> patients = patientService.getAllPatients();
......@@ -27,21 +29,18 @@ public class PatientController {
return "patients"; // Page HTML contenant la liste des patients
}
//Afficher le formulaire de création d'un patient
@GetMapping("/create")
public String showCreateForm(Model model) {
model.addAttribute("patient", new Patient());
return "create-patient"; // Page HTML pour ajouter un patient
}
// Enregistrer un nouveau patient
@PostMapping
public String createPatient(@ModelAttribute Patient patient) {
patientService.savePatient(patient);
return "redirect:/patients";
}
// Rechercher un patient par ID
@GetMapping("/{id}")
public String getPatientById(@PathVariable Long id, Model model) {
Optional<Patient> patient = patientService.getPatientById(id);
......@@ -53,16 +52,21 @@ public class PatientController {
}
}
//Supprimer un patient par ID
@PostMapping("/{id}/delete")
public String deletePatient(@PathVariable Long id) {
patientService.deletePatientById(id);
return "redirect:/patients";
}
// Afficher le tableau de bord du patient
@GetMapping("/dashboard")
public String showPatientDashboard(Model model) {
return "patient-dashboard"; // Page HTML du tableau de bord patient
return "patient-dashboard";
}
@GetMapping("/doctors")
public String listDoctors(Model model) {
List<Doctor> doctors = doctorService.getAllDoctors();
model.addAttribute("doctors", doctors);
return "doctors";
}
}
......@@ -26,7 +26,7 @@
efficacement.</p>
<div class="mt-8 grid grid-cols-1 md:grid-cols-2 gap-6">
<a href="#" class="p-6 bg-white shadow-md rounded-lg hover:shadow-lg transition">
<a href="/doctors/patients" class="p-6 bg-white shadow-md rounded-lg hover:shadow-lg transition">
<h3 class="text-xl font-semibold text-gray-800">Mes Patients</h3>
<p class="mt-2 text-gray-600">Consulter et gérer la liste de vos patients.</p>
</a>
......
......@@ -33,7 +33,7 @@
</table>
<div class="text-center mt-4">
<a href="/" class="btn btn-primary">Retour à l'accueil</a>
<a th:href="@{/redirect}" class="btn btn-primary mt-3">Retour au tableau de bord</a>
</div>
</div>
......
......@@ -19,7 +19,7 @@
<p class="mt-4 text-lg text-center text-gray-600">Accédez à vos informations médicales.</p>
<div class="mt-8 grid grid-cols-1 md:grid-cols-2 gap-6">
<a href="#" class="p-6 bg-white shadow-md rounded-lg hover:shadow-lg transition">
<a href="/patients/doctors" class="p-6 bg-white shadow-md rounded-lg hover:shadow-lg transition">
<h3 class="text-xl font-semibold text-gray-800">Mon Médecin</h3>
<p class="mt-2 text-gray-600">Voir les informations de votre médecin.</p>
</a>
......
......@@ -28,7 +28,7 @@
</tbody>
</table>
<a href="/admin/dashboard" class="btn btn-primary mt-3">Retour à l'accueil</a>
<a th:href="@{/redirect}" class="btn btn-primary mt-3">Retour au tableau de bord</a>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment