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,26 @@ using FluentValidation;
namespace Application.Endpoints.MedicalHistories;
public class MedicalHistoryCreateValidation : AbstractValidator<MedicalHistoryDTO>
public class MedicalHistoryCreateValidation : AbstractValidator<MedicalHistoryCreateDto>
{
private readonly IPacientRepository _pacientRepository;
private readonly IPatientRepository _patientRepository;
public MedicalHistoryCreateValidation(IPacientRepository pacientRepository)
public MedicalHistoryCreateValidation(IPatientRepository patientRepository)
{
_pacientRepository = pacientRepository;
_patientRepository = patientRepository;
RuleFor(x => x.UserId)
.NotEmpty().WithMessage("Pacient is required.")
.MustAsync(BeExistingUser).WithMessage("Specified pacient id doesn't exist.");
.NotEmpty().WithMessage("Patient is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
.MustAsync(BeExistingUser).WithMessage("Specified patient doesn't exist.")
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
RuleFor(x => x.Description)
.NotEmpty().WithMessage("Description is required.");
RuleFor(x => x.Content)
.NotEmpty().WithMessage("Description is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
}
private async Task<bool> BeExistingUser(Guid userId, CancellationToken cancellationToken)
{
var pacient = await _pacientRepository.GetByIdAsync(userId);
return pacient != null;
var patient = await _patientRepository.GetByIdAsync(userId);
return patient != null;
}
}
}