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:
parent
cd8f757c43
commit
cb851a4ec6
@ -4,9 +4,7 @@ using ReC.Application.RecActions.Queries;
|
||||
|
||||
namespace ReC.Application.RecActions.Commands;
|
||||
|
||||
public class InvokeRecActionCommand : ReadRecActionQuery, IRequest
|
||||
{
|
||||
}
|
||||
public record InvokeRecActionCommand : ReadRecActionQueryBase, IRequest;
|
||||
|
||||
public static class InvokeRecActionCommandExtensions
|
||||
{
|
||||
@ -18,7 +16,7 @@ public class InvokeRecActionCommandHandler(ISender sender, IHttpClientFactory cl
|
||||
{
|
||||
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();
|
||||
|
||||
|
||||
@ -8,11 +8,15 @@ using ReC.Application.Common.Dto;
|
||||
|
||||
namespace ReC.Application.RecActions.Queries;
|
||||
|
||||
public class ReadRecActionQuery : IRequest<IEnumerable<RecActionDto>>
|
||||
public record ReadRecActionQueryBase
|
||||
{
|
||||
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 async Task<IEnumerable<RecActionDto>> Handle(ReadRecActionQuery request, CancellationToken cancel)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user