Refactor Rec Actions handling with MediatR support
Refactored the handling of "Rec Actions" by introducing the `InvokeRecActionCommandHandler` class and leveraging the MediatR library for command handling. Simplified the logic in `InvokeBatchRecActionsCommand.cs` by delegating HTTP request handling to the `sender.Send` method, which now uses `InvokeRecActionCommand`. Updated `InvokeRecActionCommand` to implement the `IRequest` interface, enabling MediatR pipeline compatibility. Added `InvokeRecActionCommandExtensions` for converting `RecActionDto` to `InvokeRecActionCommand`, improving readability. Centralized HTTP request logic in the new `InvokeRecActionCommandHandler`, which validates `RestType`, sends HTTP requests, and logs warnings for invalid actions. Removed unused `using` directives and added necessary ones for MediatR and logging. This refactoring improves modularity, testability, and maintainability by separating concerns and streamlining the code structure.
This commit is contained in:
@@ -27,22 +27,7 @@ public class InvokeRecActionsCommandHandler(ISender sender, IHttpClientFactory c
|
||||
await semaphore.WaitAsync(cancel);
|
||||
try
|
||||
{
|
||||
if (action.RestType is null)
|
||||
{
|
||||
logger?.LogWarning(
|
||||
"Rec action could not be invoked because the RestType value is null. ProfileId: {ProfileId}, ActionId: {ActionId}",
|
||||
action.ProfileId,
|
||||
action.ActionId
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
var method = new HttpMethod(action.RestType.ToUpper());
|
||||
var msg = new HttpRequestMessage(method, action.EndpointUri);
|
||||
|
||||
var response = await http.SendAsync(msg, cancel);
|
||||
var body = await response.Content.ReadAsStringAsync(cancel);
|
||||
var headers = response.Headers.ToDictionary();
|
||||
await sender.Send(action.ToInvokeCommand(), cancel);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user