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

- Logic split for appointments: each role now has its own front, so controllers are simpler

- functional application
parent d5aa2dcb
No related branches found
No related tags found
1 merge request!21- Modification of the front for inscription, changeover to landscape
......@@ -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";
}
}
......@@ -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";
}
}
......@@ -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 ?');">
......
<!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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment