This commit is contained in:
andrei-mihnea-cerbu
2024-04-08 00:03:24 +03:00
parent 2ccec617a5
commit b48d5ee19e
168 changed files with 2877 additions and 1146 deletions
@@ -3,25 +3,22 @@ using FluentValidation;
namespace Application.Endpoints.MedicalHistories;
public class MedicalHistoryUpdateValidation : AbstractValidator<MedicalHistoryUpdateDTO>
public class MedicalHistoryUpdateValidation : AbstractValidator<MedicalHistoryUpdateDto>
{
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IPacientRepository _pacientRepository;
private readonly IPatientRepository _patientRepository;
public MedicalHistoryUpdateValidation(IMedicalHistoryRepository medicalHistoryRepository, IPacientRepository pacientRepository)
public MedicalHistoryUpdateValidation(IMedicalHistoryRepository medicalHistoryRepository,
IPatientRepository patientRepository)
{
_medicalHistoryRepository = medicalHistoryRepository;
_pacientRepository = pacientRepository;
_patientRepository = patientRepository;
RuleFor(x => x.Id)
.NotEmpty().WithMessage("Id is required")
.MustAsync(BeExistingMedicalHistoryRecord).WithMessage("Medical hostory record does not exist");
.MustAsync(BeExistingMedicalHistoryRecord).WithMessage("Medical history record does not exist");
RuleFor(x => x.UserId)
.NotEmpty().WithMessage("Pacient is required.")
.MustAsync(BeExistingUser).WithMessage("Specified pacient id doesn't exist.");
RuleFor(x => x.Description)
RuleFor(x => x.Content)
.NotEmpty().WithMessage("Description is required.");
}
@@ -30,10 +27,4 @@ public class MedicalHistoryUpdateValidation : AbstractValidator<MedicalHistoryUp
var record = await _medicalHistoryRepository.GetByIdAsync(guid);
return record != null;
}
private async Task<bool> BeExistingUser(Guid userId, CancellationToken cancellationToken)
{
var pacient = await _pacientRepository.GetByIdAsync(userId);
return pacient != null;
}
}
}