Decouple InvokeBatchRecActionViewsCommand from ReadRecActionQueryBase, making it a plain IRequest with an explicit ProfileId property. Update the extension and handler to use the new structure, improving clarity and separation of concerns.
37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using MediatR;
|
|
using ReC.Application.RecActionViews.Queries;
|
|
using ReC.Domain.Constants;
|
|
|
|
namespace ReC.Application.RecActionViews.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<InvokeBatchRecActionViewsCommand>
|
|
{
|
|
public async Task Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel)
|
|
{
|
|
var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId, Invoked = false }, cancel);
|
|
|
|
foreach (var action in actions)
|
|
{
|
|
var ok = await sender.Send(action.ToInvokeCommand(), cancel);
|
|
if (!ok)
|
|
switch (action.ErrorAction)
|
|
{
|
|
case ErrorAction.Continue:
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
} |