From c9cd92a55acfff657336ff29e3da5527788dbe1f Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 16 Apr 2026 14:13:06 +0200 Subject: [PATCH] Add validator for InvokeBatchRecActionViewsCommand Introduced InvokeBatchRecActionViewsCommandValidator using FluentValidation. This validator ensures BatchId is provided and checks asynchronously via MediatR that no results exist for the given BatchId before allowing the command to proceed. Provides a clear validation message if results are already present. --- ...vokeBatchRecActionViewsCommandValidator.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/ReC.Application/Common/Validations/InvokeBatchRecActionViewsCommandValidator.cs diff --git a/src/ReC.Application/Common/Validations/InvokeBatchRecActionViewsCommandValidator.cs b/src/ReC.Application/Common/Validations/InvokeBatchRecActionViewsCommandValidator.cs new file mode 100644 index 0000000..53783c1 --- /dev/null +++ b/src/ReC.Application/Common/Validations/InvokeBatchRecActionViewsCommandValidator.cs @@ -0,0 +1,22 @@ +using FluentValidation; +using MediatR; +using ReC.Application.RecActions.Commands; +using ReC.Application.Results.Queries; + +namespace ReC.Application.Common.Validations; + +public class InvokeBatchRecActionViewsCommandValidator : AbstractValidator +{ + public InvokeBatchRecActionViewsCommandValidator(ISender sender) + { + RuleFor(x => x.References.BatchId) + .NotEmpty() + .WithMessage("BatchId is required.") + .MustAsync(async (batchId, cancel) => + { + var any = await sender.Send(new AnyResultViewQuery(BatchId: batchId), cancel); + return !any; + }) + .WithMessage(x => $"Cannot invoke rec actions for batch '{x.References.BatchId}' because there are already results associated with it."); + } +}