✅ validation question
Should I be checking if a entity for a given id exists in my validator or should this be done in the requesthandler of mediator?
I'm using fluent validation
ex:
I'm using fluent validation
ex:
public CreateReviewCommandValidator()
{
RuleFor(x => x.CenterId)
.NotEmpty().WithMessage("{PropertyName} must be provided.")
.MustAsync(CenterExist).WithMessage("Center with that id doesn't exist.");
}
private async Task<bool> CenterExist(int centerId, CancellationToken cancellationToken)
{
return await _dbContext.Centers
.AnyAsync(x => x.Id == centerId, cancellationToken: cancellationToken);
}