diff --git a/src/main/java/com/mirna/hospitalmanagementapi/application/usecase/patient/FindPatientByIdUseCase.java b/src/main/java/com/mirna/hospitalmanagementapi/application/usecase/patient/FindPatientByIdUseCase.java new file mode 100644 index 0000000..aa8aedc --- /dev/null +++ b/src/main/java/com/mirna/hospitalmanagementapi/application/usecase/patient/FindPatientByIdUseCase.java @@ -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); + } +} diff --git a/src/main/java/com/mirna/hospitalmanagementapi/application/usecase/patient/SavePatientUseCase.java b/src/main/java/com/mirna/hospitalmanagementapi/application/usecase/patient/SavePatientUseCase.java new file mode 100644 index 0000000..65394bf --- /dev/null +++ b/src/main/java/com/mirna/hospitalmanagementapi/application/usecase/patient/SavePatientUseCase.java @@ -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); + } +}