From 4088a52196f2f1c42d3576dd888f8a3b012d3ae6 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 16 Apr 2026 14:48:09 +0200 Subject: [PATCH] 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. --- .../ReadResultViewQueryValidator.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/ReC.Application/Common/Validations/ReadResultViewQueryValidator.cs diff --git a/src/ReC.Application/Common/Validations/ReadResultViewQueryValidator.cs b/src/ReC.Application/Common/Validations/ReadResultViewQueryValidator.cs new file mode 100644 index 0000000..1faef60 --- /dev/null +++ b/src/ReC.Application/Common/Validations/ReadResultViewQueryValidator.cs @@ -0,0 +1,34 @@ +using FluentValidation; +using ReC.Application.Results.Queries; + +namespace ReC.Application.Common.Validations; + +public class ReadResultViewQueryValidator : AbstractValidator +{ + 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."); + } +}