Skip to content
Snippets Groups Projects
Commit d93387c4 authored by COULIBALY Aichatou's avatar COULIBALY Aichatou
Browse files

patient controller

parent 2fe4c740
No related branches found
No related tags found
No related merge requests found
package com.projet.projetIndu.controllers;
import com.projet.projetIndu.entities.Patient;
import com.projet.projetIndu.services.PatientService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RequestMapping("/patients")
@Controller
public class PatientController {
private final PatientService patientService;
public PatientController(PatientService patientService) {
this.patientService = patientService;
}
// Afficher tous les patients
@GetMapping
public String listPatients(Model model) {
List<Patient> patients = patientService.getAllPatients();
model.addAttribute("patients", patients);
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);
if (patient.isPresent()) {
model.addAttribute("patient", patient.get());
return "patient-details"; // Page HTML avec les détails du patient
} else {
return "redirect:/patients?error=notfound";
}
}
//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
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment