From 3ca148f34135bce3748d829b92f62e84b810eb08 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 15 Aug 2025 15:06:38 +0200 Subject: [PATCH] feat(EConnectClient): add PostAsync method without body --- .../EConnectClient.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Leanetec.EConnect.Infrastructure/EConnectClient.cs b/src/Leanetec.EConnect.Infrastructure/EConnectClient.cs index fb1d4c4..1e88a81 100644 --- a/src/Leanetec.EConnect.Infrastructure/EConnectClient.cs +++ b/src/Leanetec.EConnect.Infrastructure/EConnectClient.cs @@ -88,4 +88,37 @@ public class EConnectClient : IEConnectClient where TError : cl }; } } + + public async Task> PostAsync(string? route = null, object? queryParams = null, CancellationToken cancel = default) + where TData : class + { + // add global query strings + if (_options.DefaultQueryStrings is not null) + route = route.AddQueryString(_options.DefaultQueryStrings); + + // add query strings + if (queryParams is not null) + route = route.AddQueryString(queryParams.ToPropertyDictionary()); + + var res = await Http.PostAsync(route, null, cancel); + + if (res.IsSuccessStatusCode) + { + return new() + { + Ok = true, + StatusCode = res.StatusCode + }; + } + else + { + var error = await res.Content.ReadFromJsonAsync(_options.JsonSerializerOptions, cancel); + return new() + { + Ok = false, + StatusCode = res.StatusCode, + Error = error + }; + } + } } \ No newline at end of file