using Application.Services.Database.PostgreSQL; using FluentValidation; namespace Application.Endpoints.MedicalHistories.FileManagement; public class MedicalHistoryUpdateValidation : AbstractValidator { private readonly IMedicalHistoryRepository _medicalHistoryRepository; private readonly IPatientRepository _patientRepository; public MedicalHistoryUpdateValidation(IMedicalHistoryRepository medicalHistoryRepository, IPatientRepository patientRepository) { _medicalHistoryRepository = medicalHistoryRepository; _patientRepository = patientRepository; RuleFor(x => x.Id) .NotEmpty().WithMessage("Id is required") .MustAsync(BeExistingMedicalHistoryRecord).WithMessage("Medical history record does not exist"); RuleFor(x => x.Content) .NotEmpty().WithMessage("Description is required."); } private async Task BeExistingMedicalHistoryRecord(Guid guid, CancellationToken token) { var record = await _medicalHistoryRepository.GetByIdAsync(guid); return record != null; } }