finalizare 1.0
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using Application.Endpoints.MedicalHistories;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
|
||||
namespace Application.Endpoints.Patients.DeletePatient;
|
||||
|
||||
public class DeletePatientHandler(
|
||||
IPatientRepository patientRepository,
|
||||
IMedicalHistoryRepository medicalHistoryRepository,
|
||||
IMedicalHistoryMongoDbService medicalHistoryMongoDbService)
|
||||
{
|
||||
public async Task<BaseResponse> Handle(Guid patientId, CancellationToken token)
|
||||
{
|
||||
var patient = await patientRepository.GetByIdAsync(patientId, token);
|
||||
if (patient == null)
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NotFound,
|
||||
Message = "Patient not found.",
|
||||
Data = null
|
||||
};
|
||||
|
||||
await patientRepository.DeleteAsync(patient, token);
|
||||
|
||||
var medicalHistoryList = await medicalHistoryRepository.GetAllAsync(token);
|
||||
foreach (var med in medicalHistoryList)
|
||||
if (med.UserId == patientId)
|
||||
{
|
||||
await medicalHistoryRepository.DeleteAsync(med, token);
|
||||
await medicalHistoryMongoDbService.DeleteByIdAsync<MedicalHistoryAuthorisationModel>(med.Id.ToString(), token);
|
||||
}
|
||||
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NoContent,
|
||||
Message = null,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user