[R5] Patient use case for Save and FindById

This commit is contained in:
Mirna Gama 2024-01-06 18:05:36 -03:00 committed by Mirna Gama
parent 1bced128e5
commit 48f296ad59
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,32 @@
package com.mirna.hospitalmanagementapi.application.usecase.patient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.mirna.hospitalmanagementapi.domain.entities.Patient;
import com.mirna.hospitalmanagementapi.domain.repositories.PatientRepository;
/**
* This class is used to execute the findById method
*
* @author Mirna Gama
* @version 1.0
*/
@Component
public class FindPatientByIdUseCase {
@Autowired
private PatientRepository patientRepository;
/**
* Executes the findById method from Patient repository
*
* @param id A long representing the patient's unique identifier
*
* @return The corresponding patient if successful, or null if it is non-existent
*
*/
public Patient execute(Long id) {
return patientRepository.findById(id).orElse(null);
}
}

View File

@ -0,0 +1,31 @@
package com.mirna.hospitalmanagementapi.application.usecase.patient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.mirna.hospitalmanagementapi.domain.entities.Patient;
import com.mirna.hospitalmanagementapi.domain.repositories.PatientRepository;
/**
* This class is used to execute the save method from patient repository
*
* @author Mirna Gama
* @version 1.0
*/
@Component
public class SavePatientUseCase {
@Autowired
private PatientRepository patientRepository;
/**
* Executes the save method from Patient repository
*
* @param patient The Patient to be saved in the repository
* @return The saved patient if successful, or null if there is an error
*
*/
public Patient execute(Patient patient) {
return this.patientRepository.save(patient);
}
}