Skip to content
Snippets Groups Projects
Select Git revision
  • 2390115ff8f3bc27cb0315cc61f7cca05f52ce84
  • main default
  • Hayat2
  • branch_aichatou
  • Hayat
5 results

PatientService.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    PatientService.java 1.05 KiB
    package com.projet.projetIndu.services;
    
    import com.projet.projetIndu.entities.Patient;
    import com.projet.projetIndu.repositories.PatientRepository;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    import java.util.List;
    import java.util.Optional;
    
    @Service
    public class PatientService {
    
        private final PatientRepository patientRepository;
    
        @Autowired
        public PatientService(PatientRepository patientRepository) {
            this.patientRepository = patientRepository;
        }
    
        public List<Patient> getAllPatients() {
            return patientRepository.findAll();
        }
    
        public Optional<Patient> getPatientById(Long id) {
            return patientRepository.findById(id);
        }
    
        public Optional<Patient> getPatientByEmail(String email) {
            return patientRepository.findByEmail(email);
        }
    
        public Patient savePatient(Patient patient) {
            return patientRepository.save(patient);
        }
    
        public void deletePatientById(Long id) {
            patientRepository.deleteById(id);
        }
    }