Refactor RecAction commands and queries to use records

Refactored `InvokeRecActionCommand` and `ReadRecActionQuery`
to leverage C# `record` types for immutability and improved
data structure clarity. Introduced `ReadRecActionQueryBase`
as a shared base record to separate common properties and
logic. Updated `InvokeRecActionCommandHandler` to use the
new `ToReadQuery` method for compatibility. These changes
enhance code maintainability, reusability, and separation
of concerns while preserving existing functionality.
This commit is contained in:
tekh 2025-11-27 10:56:21 +01:00
parent cd8f757c43
commit cb851a4ec6
2 changed files with 7 additions and 5 deletions

View File

@ -4,9 +4,7 @@ using ReC.Application.RecActions.Queries;
namespace ReC.Application.RecActions.Commands; namespace ReC.Application.RecActions.Commands;
public class InvokeRecActionCommand : ReadRecActionQuery, IRequest public record InvokeRecActionCommand : ReadRecActionQueryBase, IRequest;
{
}
public static class InvokeRecActionCommandExtensions public static class InvokeRecActionCommandExtensions
{ {
@ -18,7 +16,7 @@ public class InvokeRecActionCommandHandler(ISender sender, IHttpClientFactory cl
{ {
public async Task Handle(InvokeRecActionCommand request, CancellationToken cancel) public async Task Handle(InvokeRecActionCommand request, CancellationToken cancel)
{ {
var actions = await sender.Send(request as ReadRecActionQuery, cancel); var actions = await sender.Send(request.ToReadQuery(), cancel);
var http = clientFactory.CreateClient(); var http = clientFactory.CreateClient();

View File

@ -8,11 +8,15 @@ using ReC.Application.Common.Dto;
namespace ReC.Application.RecActions.Queries; namespace ReC.Application.RecActions.Queries;
public class ReadRecActionQuery : IRequest<IEnumerable<RecActionDto>> public record ReadRecActionQueryBase
{ {
public int ProfileId { get; init; } public int ProfileId { get; init; }
public ReadRecActionQuery ToReadQuery() => new(this);
} }
public record ReadRecActionQuery(ReadRecActionQueryBase Root) : ReadRecActionQueryBase(Root), IRequest<IEnumerable<RecActionDto>>;
public class ReadRecActionQueryHandler(IRepository<RecAction> repo, IMapper mapper) : IRequestHandler<ReadRecActionQuery, IEnumerable<RecActionDto>> public class ReadRecActionQueryHandler(IRepository<RecAction> repo, IMapper mapper) : IRequestHandler<ReadRecActionQuery, IEnumerable<RecActionDto>>
{ {
public async Task<IEnumerable<RecActionDto>> Handle(ReadRecActionQuery request, CancellationToken cancel) public async Task<IEnumerable<RecActionDto>> Handle(ReadRecActionQuery request, CancellationToken cancel)