Prevent rec action invocation if batch has results

Add validation in InvokeRecActionViewsCommandHandler to check
for existing results before invoking rec actions for a batch.
Throw BadRequestException if results are found to avoid
duplicate processing. Add necessary using statements for
exceptions and queries.
This commit is contained in:
2026-04-16 10:22:31 +02:00
parent e45aeea2b9
commit e1c3f74cd4

View File

@@ -1,7 +1,9 @@
using MediatR;
using DigitalData.Core.Exceptions;
using MediatR;
using Microsoft.Extensions.Logging;
using ReC.Application.Common.Exceptions;
using ReC.Application.RecActions.Queries;
using ReC.Application.Results.Queries;
using ReC.Domain.Constants;
namespace ReC.Application.RecActions.Commands;
@@ -16,6 +18,11 @@ public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger<InvokeRe
{
public async Task Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel)
{
var any = await sender.Send(new AnyResultViewQuery(BatchId: request.References.BatchId), cancel);
if(any)
throw new BadRequestException($"Cannot invoke rec actions for batch {request.References.BatchId} because there are already results associated with it. Count: {any}");
var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId }, cancel);
foreach (var action in actions)