using MediatR; using Microsoft.Extensions.Logging; using ReC.Application.Common; using ReC.Application.Common.Dto; namespace ReC.Application.RecActions.Commands; public record InvokeRecActionCommand : RecActionDto, IRequest { public InvokeRecActionCommand(RecActionDto root) : base(root) { } public InvokeRecActionCommand() { } } public static class InvokeRecActionCommandExtensions { public static InvokeRecActionCommand ToInvokeCommand(this RecActionDto dto) => new(dto); } public class InvokeRecActionCommandHandler( IHttpClientFactory clientFactory, ILogger? logger = null ) : IRequestHandler { public async Task Handle(InvokeRecActionCommand request, CancellationToken cancel) { using var http = clientFactory.CreateClient(); if (request.RestType is null) { logger?.LogWarning( "Rec action could not be invoked because the RestType value is null. ProfileId: {ProfileId}, ActionId: {ActionId}", request.ProfileId, request.ActionId ); return; } using var httpReq = request.RestType .ToHttpMethod() .ToHttpRequestMessage(request.EndpointUri); using var response = await http.SendAsync(httpReq, cancel); var body = await response.Content.ReadAsStringAsync(cancel); var headers = response.Headers.ToDictionary(); } }