diff --git a/src/main/java/com/projet/projetIndu/services/DoctorService.java b/src/main/java/com/projet/projetIndu/services/DoctorService.java index baf0f70a6fe0ac9668704ae7085cbb25f6e2ded6..3b69c9ffbc848ddf524258f6acf3eb3a7f013c68 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 ba62a2d3a93967a42ad289ac9ffd1c6572841ab7..314af3edf80e44c1436ca2b5b1934ab8a239e496 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 df68dc55dc35dfb0a8efb016397f11a902c4402f..6c93cfd2c827633d344754c2c53e2c3ac9f5e808 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">