api v2.0
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user