diff --git a/src/ReC.Application/Common/HttpExtensions.cs b/src/ReC.Application/Common/HttpExtensions.cs deleted file mode 100644 index cecc0e7..0000000 --- a/src/ReC.Application/Common/HttpExtensions.cs +++ /dev/null @@ -1,29 +0,0 @@ -using ReC.Domain.Constants; -using System.Diagnostics.CodeAnalysis; - -namespace ReC.Application.Common; - -public static class HttpExtensions -{ - private static readonly Dictionary _methods = new() - { - [RestType.Get] = HttpMethod.Get, - [RestType.Post] = HttpMethod.Post, - [RestType.Put] = HttpMethod.Put, - [RestType.Delete] = HttpMethod.Delete, - [RestType.Patch] = HttpMethod.Patch, - [RestType.Head] = HttpMethod.Head, - [RestType.Options] = HttpMethod.Options, - [RestType.Trace] = HttpMethod.Trace, - [RestType.Connect] = HttpMethod.Connect - }; - - public static HttpMethod ToHttpMethod(this RestType method) => !method.IsValid() - ? throw new ArgumentOutOfRangeException(nameof(method), $"The RestType value '{method}' is not valid.") - : _methods.TryGetValue(method, out var httpMethod) - ? httpMethod - : new HttpMethod(method.ToHttpMethodName()); - - public static HttpRequestMessage ToHttpRequestMessage(this HttpMethod method, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri) - => new(method, requestUri); -} diff --git a/src/ReC.Application/RecActions/Commands/InvokeRecActionViewCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeRecActionViewCommand.cs index 6f35335..eeac815 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeRecActionViewCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeRecActionViewCommand.cs @@ -38,9 +38,7 @@ public class InvokeRecActionViewCommandHandler( $"Id: {action.Id}" ); - using var httpReq = restType - .ToHttpMethod() - .ToHttpRequestMessage(action.EndpointUri); + using var httpReq = CreateHttpRequestMessage(restType, action.EndpointUri); if (action.Body is not null) httpReq.Content = new StringContent(action.Body); @@ -136,4 +134,24 @@ public class InvokeRecActionViewCommandHandler( return response.IsSuccessStatusCode; } + + private static HttpRequestMessage CreateHttpRequestMessage(RestType restType, string? endpointUri) + { + var method = restType switch + { + RestType.Get => HttpMethod.Get, + RestType.Post => HttpMethod.Post, + RestType.Put => HttpMethod.Put, + RestType.Delete => HttpMethod.Delete, + RestType.Patch => HttpMethod.Patch, + RestType.Head => HttpMethod.Head, + RestType.Options => HttpMethod.Options, + RestType.Trace => HttpMethod.Trace, + RestType.Connect => HttpMethod.Connect, + RestType.None => throw new ArgumentOutOfRangeException(nameof(restType), $"The RestType value '{restType}' is not valid."), + _ => new HttpMethod(restType.ToString().ToUpperInvariant()) + }; + + return new HttpRequestMessage(method, endpointUri); + } } \ No newline at end of file