Add FluentValidation for ReadResultViewQuery filters
Introduced ReadResultViewQueryValidator to enforce that at least one filter (Id, ActionId, ProfileId, or BatchId) is provided. Also validates that numeric IDs are greater than 0 and BatchId is not empty when present.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using FluentValidation;
|
||||
using ReC.Application.Results.Queries;
|
||||
|
||||
namespace ReC.Application.Common.Validations;
|
||||
|
||||
public class ReadResultViewQueryValidator : AbstractValidator<ReadResultViewQuery>
|
||||
{
|
||||
public ReadResultViewQueryValidator()
|
||||
{
|
||||
RuleFor(x => x)
|
||||
.Must(x => x.Id.HasValue || x.ActionId.HasValue || x.ProfileId.HasValue || x.BatchId is not null)
|
||||
.WithMessage("At least one filter (Id, ActionId, ProfileId or BatchId) must be provided.");
|
||||
|
||||
RuleFor(x => x.Id)
|
||||
.GreaterThan(0)
|
||||
.When(x => x.Id.HasValue)
|
||||
.WithMessage("Id must be greater than 0.");
|
||||
|
||||
RuleFor(x => x.ActionId)
|
||||
.GreaterThan(0)
|
||||
.When(x => x.ActionId.HasValue)
|
||||
.WithMessage("ActionId must be greater than 0.");
|
||||
|
||||
RuleFor(x => x.ProfileId)
|
||||
.GreaterThan(0)
|
||||
.When(x => x.ProfileId.HasValue)
|
||||
.WithMessage("ProfileId must be greater than 0.");
|
||||
|
||||
RuleFor(x => x.BatchId)
|
||||
.NotEmpty()
|
||||
.When(x => x.BatchId is not null)
|
||||
.WithMessage("BatchId must not be empty when provided.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user