From c729cb33e343e86c1c6013bed67dd011b5e2f180 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 4 Aug 2026 13:55:08 +0200 Subject: [PATCH] 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. --- .../Common/Dto/BatchRecActionViewResponse.cs | 6 ++++++ .../InvokeBatchRecActionViewsCommand.cs | 17 ++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) create mode 100644 src/ReC.Application/Common/Dto/BatchRecActionViewResponse.cs diff --git a/src/ReC.Application/Common/Dto/BatchRecActionViewResponse.cs b/src/ReC.Application/Common/Dto/BatchRecActionViewResponse.cs new file mode 100644 index 0000000..274551f --- /dev/null +++ b/src/ReC.Application/Common/Dto/BatchRecActionViewResponse.cs @@ -0,0 +1,6 @@ +namespace ReC.Application.Common.Dto; + +public record BatchRecActionViewResponse(int TotalActionCount) +{ + public int ActionExceptionCount { get; internal set; } = 0; +} \ No newline at end of file diff --git a/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionViewsCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionViewsCommand.cs index 10ed064..c53c32c 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionViewsCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionViewsCommand.cs @@ -1,5 +1,6 @@ using MediatR; using Microsoft.Extensions.Logging; +using ReC.Application.Common.Dto; using ReC.Application.Common.Exceptions; using ReC.Application.RecActions.Queries; using ReC.Domain.Constants; @@ -12,22 +13,14 @@ public record InvokeBatchRecActionViewsCommand : IRequest SuccessCount + FailureCount; - - public int SuccessCount { get; internal set; } = 0; - - public int FailureCount { get; internal set; } = 0; -} - public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger? logger = null) : IRequestHandler { public async Task Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel) { - var res = new BatchRecActionViewResponse(); var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId }, cancel); + var res = new BatchRecActionViewResponse(TotalActionCount: actions.Count()); + foreach (var action in actions) { try @@ -37,8 +30,6 @@ public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger