From e3939c672327f52e84154de7baa001de1f228a3b Mon Sep 17 00:00:00 2001
From: Jessie Ragot <jessie.ragot@hotmail.com>
Date: Tue, 11 Mar 2025 16:31:45 +0100
Subject: [PATCH] Remove role admin and doctor in registration

---
 .../projetIndu/services/DoctorService.java    |  2 +-
 .../projetIndu/services/UserService.java      | 41 +++++++------------
 src/main/resources/templates/register.html    | 10 -----
 3 files changed, 15 insertions(+), 38 deletions(-)

diff --git a/src/main/java/com/projet/projetIndu/services/DoctorService.java b/src/main/java/com/projet/projetIndu/services/DoctorService.java
index baf0f70..3b69c9f 100644
--- a/src/main/java/com/projet/projetIndu/services/DoctorService.java
+++ b/src/main/java/com/projet/projetIndu/services/DoctorService.java
@@ -54,6 +54,6 @@ public class DoctorService {
     }
 }
 
-//
+
 
 
diff --git a/src/main/java/com/projet/projetIndu/services/UserService.java b/src/main/java/com/projet/projetIndu/services/UserService.java
index ba62a2d..314af3e 100644
--- a/src/main/java/com/projet/projetIndu/services/UserService.java
+++ b/src/main/java/com/projet/projetIndu/services/UserService.java
@@ -1,9 +1,8 @@
 package com.projet.projetIndu.services;
 
 import com.projet.projetIndu.dto.UserRegistrationDTO;
-import com.projet.projetIndu.entities.Admin;
-import com.projet.projetIndu.entities.Doctor;
 import com.projet.projetIndu.entities.Patient;
+import com.projet.projetIndu.entities.Role;
 import com.projet.projetIndu.entities.User;
 import com.projet.projetIndu.repositories.UserRepository;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -14,6 +13,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.Objects;
 import java.util.Optional;
 
 
@@ -54,35 +54,22 @@ public class UserService implements UserDetailsService {
         }
 
         String encodedPassword = passwordEncoder.encode(userDTO.getPassword());
-        User user;
-
-        switch (userDTO.getRole()) {
-            case DOCTOR -> {
-                if (userDTO.getSpeciality() == null || userDTO.getSpeciality().isEmpty()) {
-                    throw new IllegalArgumentException("Speciality is required for doctors");
-                }
-                Doctor doctor = new Doctor();
-                doctor.setSpeciality(userDTO.getSpeciality());
-                user = doctor;
-            }
-            case PATIENT -> {
-                if (userDTO.getDateOfBirth() == null) {
-                    throw new IllegalArgumentException("Date of birth is required for patients");
-                }
-                if (userDTO.getAddress() == null || userDTO.getAddress().isBlank()) {
-                    throw new IllegalArgumentException("Address is required for patients");
-                }
-                Patient patient = new Patient();
-                patient.setDateOfBirth(userDTO.getDateOfBirth());
-                patient.setAddress(userDTO.getAddress());
-                user = patient;
+        User user = null;
+
+        if (Objects.requireNonNull(userDTO.getRole()) == Role.PATIENT) {
+            if (userDTO.getDateOfBirth() == null) {
+                throw new IllegalArgumentException("Date of birth is required for patients");
             }
-            case ADMIN -> {
-                user = new Admin();
+            if (userDTO.getAddress() == null || userDTO.getAddress().isBlank()) {
+                throw new IllegalArgumentException("Address is required for patients");
             }
-            default -> throw new IllegalArgumentException("Invalid role");
+            Patient patient = new Patient();
+            patient.setDateOfBirth(userDTO.getDateOfBirth());
+            patient.setAddress(userDTO.getAddress());
+            user = patient;
         }
 
+        assert user != null;
         user.setFirstName(userDTO.getFirstName());
         user.setLastName(userDTO.getLastName());
         user.setPhoneNumber(userDTO.getPhoneNumber());
diff --git a/src/main/resources/templates/register.html b/src/main/resources/templates/register.html
index df68dc5..6c93cfd 100644
--- a/src/main/resources/templates/register.html
+++ b/src/main/resources/templates/register.html
@@ -39,19 +39,9 @@
                 <label for="role" class="form-label">Rôle</label>
                 <select class="form-control" id="role" name="role" required onchange="toggleFields()">
                     <option value="PATIENT">Patient</option>
-                    <option value="DOCTOR">Médecin</option>
-                    <option value="ADMIN">Administrateur</option>
                 </select>
             </div>
 
-            <!-- Champs spécifiques pour Médecin -->
-            <div id="doctorFields" style="display: none;">
-                <div class="mb-3">
-                    <label for="speciality" class="form-label">Spécialité</label>
-                    <input type="text" class="form-control" id="speciality" name="speciality">
-                </div>
-            </div>
-
             <!-- Champs spécifiques pour Patient -->
             <div id="patientFields">
                 <div class="mb-3">
-- 
GitLab