Files
FACULTATE-HEALTHCARE_MANAGER/backend/Application/Endpoints/Patients/QuerriesPatients/QuerriesPatientsHandle.cs
T
2024-05-21 12:10:53 +03:00

36 lines
1.1 KiB
C#

using Application.Services.Database.PostgreSQL;
namespace Application.Endpoints.Patients.QuerriesPatients;
public class QuerriesPatientsHandle(IPatientRepository patientRepository)
{
public async Task<BaseResponse> HandleGet(Guid id, CancellationToken token)
{
var patient = await patientRepository.GetByIdAsync(id, token);
if (patient != null)
return new BaseResponse
{
StatusCode = HttpStatusCodes.OK,
Message = $"Retrieved patient with id: {id}",
Data = patient
};
return new BaseResponse
{
StatusCode = HttpStatusCodes.NotFound,
Message = $"Patient with id: {id} not found",
Data = null
};
}
public async Task<BaseResponse> HandleGetAll(CancellationToken token)
{
var patients = await patientRepository.GetAllAsync(token);
return new BaseResponse
{
StatusCode = HttpStatusCodes.OK,
Message = "Retrieved patients",
Data = patients.ToList()
};
}
}