using DigitalData.Core.Abstractions.Interfaces; using MediatR; using ReC.Application.RecActions.Queries; using ReC.Domain.Constants; namespace ReC.Application.RecActions.Commands; public record InvokeBatchRecActionViewsCommand : IRequest { public long ProfileId { get; init; } } public static class InvokeBatchRecActionViewsCommandExtensions { public static Task InvokeBatchRecActionView(this ISender sender, long profileId, CancellationToken cancel = default) => sender.Send(new InvokeBatchRecActionViewsCommand { ProfileId = profileId }, cancel); } public class InvokeRecActionViewsCommandHandler(ISender sender) : IRequestHandler { public async Task Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel) { var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId }, cancel); foreach (var action in actions) { try { await sender.Send(new InvokeRecActionViewCommand() { Action = action }, cancel); } catch { switch (action.ErrorAction) { case ErrorAction.Continue: break; default: // Rethrow the exception to stop processing further actions throw; } } } } }