diff --git a/src/main/java/com/projet/projetIndu/controllers/DoctorAppointmentController.java b/src/main/java/com/projet/projetIndu/controllers/DoctorAppointmentController.java index 2935ac62a615355ec6e2b6c1821f0b2da546f1a1..39396c59420eb17730947ea26ea4a3afc1a80968 100644 --- a/src/main/java/com/projet/projetIndu/controllers/DoctorAppointmentController.java +++ b/src/main/java/com/projet/projetIndu/controllers/DoctorAppointmentController.java @@ -7,6 +7,7 @@ import com.projet.projetIndu.entities.Patient; import com.projet.projetIndu.services.AppointmentService; import com.projet.projetIndu.services.DoctorService; import com.projet.projetIndu.services.PatientService; +import org.springframework.security.core.Authentication; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; @@ -29,11 +30,11 @@ public class DoctorAppointmentController { } @GetMapping - public String showDoctorAppointments(Model model) { + public String showDoctorAppointments(Model model, Authentication authentication) { Long doctorId = doctorService.getAuthenticatedDoctorId(); List<Appointment> appointments = appointmentService.getAppointmentsByDoctor(doctorId); model.addAttribute("appointments", appointments); - return "appointments"; + return "doctor-appointments"; } @GetMapping("/create") @@ -50,7 +51,6 @@ public class DoctorAppointmentController { return "create-appointment"; } - @PostMapping("/create") public String createAppointment(@RequestParam("patientId") Long patientId, @RequestParam("dateTime") String dateTime, @@ -81,12 +81,9 @@ public class DoctorAppointmentController { return "redirect:/doctors/appointments"; } - @PostMapping("/{id}/cancel") public String cancelAppointment(@PathVariable Long id) { appointmentService.cancelAppointment(id); return "redirect:/doctors/appointments"; } } - - diff --git a/src/main/java/com/projet/projetIndu/controllers/PatientAppointmentController.java b/src/main/java/com/projet/projetIndu/controllers/PatientAppointmentController.java index ed97a4bfe2f7c9ce6cab6db6211406900b3442c8..2df3dd863e8175d87abc586943ca81cc62ff5956 100644 --- a/src/main/java/com/projet/projetIndu/controllers/PatientAppointmentController.java +++ b/src/main/java/com/projet/projetIndu/controllers/PatientAppointmentController.java @@ -3,15 +3,18 @@ package com.projet.projetIndu.controllers; import com.projet.projetIndu.entities.Appointment; import com.projet.projetIndu.services.AppointmentService; import com.projet.projetIndu.services.PatientService; +import org.springframework.security.core.Authentication; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import java.util.List; @Controller -@RequestMapping("/patients/appointments") // L'URL commence bien par /patients/ +@RequestMapping("/patients/appointments") public class PatientAppointmentController { private final AppointmentService appointmentService; @@ -23,11 +26,16 @@ public class PatientAppointmentController { } @GetMapping - public String showPatientAppointments(Model model) { - Long patientId = patientService.getAuthenticatedPatientId(); // Récupère l'ID du patient connecté + public String showPatientAppointments(Model model, Authentication authentication) { + Long patientId = patientService.getAuthenticatedPatientId(); List<Appointment> appointments = appointmentService.getAppointmentsByPatient(patientId); model.addAttribute("appointments", appointments); - return "appointments"; + return "patient-appointments"; // Utilisez la vue spécifique pour les patients } -} + @PostMapping("/{id}/cancel") + public String cancelAppointment(@PathVariable Long id) { + appointmentService.cancelAppointment(id); + return "redirect:/patients/appointments"; + } +} diff --git a/src/main/resources/templates/appointments.html b/src/main/resources/templates/doctor-appointments.html similarity index 91% rename from src/main/resources/templates/appointments.html rename to src/main/resources/templates/doctor-appointments.html index cafccf15abb5b279f795a64cddaaded069ab25d7..9ca2713eb1e5bfbabe71463659c9babe0bb8db28 100644 --- a/src/main/resources/templates/appointments.html +++ b/src/main/resources/templates/doctor-appointments.html @@ -26,7 +26,8 @@ <td th:text="${#temporals.format(appointment.dateTime, 'dd/MM/yyyy HH:mm')}"></td> <td th:text="${appointment.status}"></td> <td> - <form method="post" th:action="@{/appointments/{id}/cancel(id=${appointment.id})}" class="d-inline"> + <form method="post" th:action="@{/doctors/appointments/{id}/cancel(id=${appointment.id})}" + class="d-inline"> <input type="hidden" name="_method" value="post"/> <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Voulez-vous annuler ce rendez-vous ?');"> diff --git a/src/main/resources/templates/patient-appointments.html b/src/main/resources/templates/patient-appointments.html new file mode 100644 index 0000000000000000000000000000000000000000..a523337b5bf870117cb737bf07be78ad8245724c --- /dev/null +++ b/src/main/resources/templates/patient-appointments.html @@ -0,0 +1,45 @@ +<!DOCTYPE html> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Mes Rendez-vous</title> + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"> +</head> +<body class="bg-light"> + +<div class="container mt-5"> + <h1 class="text-center mb-4">Liste de mes rendez-vous</h1> + + <table class="table table-bordered table-striped"> + <thead class="table-dark"> + <tr> + <th>Médecin</th> + <th>Date et heure</th> + <th>Statut</th> + <th>Actions</th> + </tr> + </thead> + <tbody> + <tr th:each="appointment : ${appointments}"> + <td th:text="${appointment.doctor.firstName + ' ' + appointment.doctor.lastName}"></td> + <td th:text="${#temporals.format(appointment.dateTime, 'dd/MM/yyyy HH:mm')}"></td> + <td th:text="${appointment.status}"></td> + <td> + <form method="post" th:action="@{/patients/appointments/{id}/cancel(id=${appointment.id})}" + class="d-inline"> + <input type="hidden" name="_method" value="post"/> + <button type="submit" class="btn btn-danger btn-sm" + onclick="return confirm('Voulez-vous annuler ce rendez-vous ?');"> + Annuler + </button> + </form> + </td> + </tr> + </tbody> + </table> +</div> + +<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> +</body> +</html>