Refactor BatchRecActionViewResponse to a record type

Refactored `BatchRecActionViewResponse` from a mutable class to an immutable record type with a constructor for `TotalActionCount` and a new `ActionExceptionCount` property. Moved the record to its own file under the `ReC.Application.Common.Dto` namespace.

Updated `InvokeBatchRecActionViewsCommand` and `InvokeRecActionViewsCommandHandler` to use the new record type. Removed `SuccessCount` and `FailureCount` properties, replacing them with `ActionExceptionCount`.

Performed minor cleanup, including removing the old class definition and updating namespaces.
This commit is contained in:
2026-08-04 13:55:08 +02:00
parent cad7ca16cb
commit c729cb33e3
2 changed files with 10 additions and 13 deletions

View File

@@ -0,0 +1,6 @@
namespace ReC.Application.Common.Dto;
public record BatchRecActionViewResponse(int TotalActionCount)
{
public int ActionExceptionCount { get; internal set; } = 0;
}

View File

@@ -1,5 +1,6 @@
using MediatR; using MediatR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using ReC.Application.Common.Dto;
using ReC.Application.Common.Exceptions; using ReC.Application.Common.Exceptions;
using ReC.Application.RecActions.Queries; using ReC.Application.RecActions.Queries;
using ReC.Domain.Constants; using ReC.Domain.Constants;
@@ -12,22 +13,14 @@ public record InvokeBatchRecActionViewsCommand : IRequest<BatchRecActionViewResp
public required InvokeReferences References { get; init; } public required InvokeReferences References { get; init; }
} }
public record BatchRecActionViewResponse
{
public int TotalActionCount => SuccessCount + FailureCount;
public int SuccessCount { get; internal set; } = 0;
public int FailureCount { get; internal set; } = 0;
}
public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger<InvokeRecActionViewsCommandHandler>? logger = null) : IRequestHandler<InvokeBatchRecActionViewsCommand, BatchRecActionViewResponse> public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger<InvokeRecActionViewsCommandHandler>? logger = null) : IRequestHandler<InvokeBatchRecActionViewsCommand, BatchRecActionViewResponse>
{ {
public async Task<BatchRecActionViewResponse> Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel) public async Task<BatchRecActionViewResponse> Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel)
{ {
var res = new BatchRecActionViewResponse();
var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId }, cancel); var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId }, cancel);
var res = new BatchRecActionViewResponse(TotalActionCount: actions.Count());
foreach (var action in actions) foreach (var action in actions)
{ {
try try
@@ -37,8 +30,6 @@ public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger<InvokeRe
Action = action, Action = action,
References = request.References References = request.References
}, cancel); }, cancel);
res.SuccessCount += 1;
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -56,7 +47,7 @@ public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger<InvokeRe
throw; throw;
} }
res.FailureCount += 1; res.ActionExceptionCount += 1;
} }
} }