feat(ClientOptions): add QueryStrings-property.

- add logic to handle global query strings on EConnectClient
This commit is contained in:
tekh 2025-08-15 10:20:33 +02:00
parent a7cbced3e6
commit dd60555ed3
3 changed files with 13 additions and 0 deletions

View File

@ -7,4 +7,6 @@ public class ClientOptions
public string? ApiKey { get; set; }
public TimeSpan? Timeout { get; set; }
public Dictionary<string, string?>? QueryStrings { get; set; }
}

View File

@ -23,6 +23,11 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
public async Task<Response<TData, TError>> GetAsync<TData>(string? route = null, object? queryParams = null, CancellationToken cancel = default)
where TData : class
{
// add global query strings
if (_options.QueryStrings is not null)
route = route.AddQueryString(_options.QueryStrings);
// add query strings
if (queryParams is not null)
route = route.AddQueryString(queryParams.ToPropertyDictionary());
@ -43,6 +48,11 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
public async Task<Response<IAsyncEnumerable<TData?>, TError>> GetListAsAsyncEnumerable<TData>(string? route = null, object? queryParams = null, CancellationToken cancel = default)
where TData : class
{
// add global query strings
if (_options.QueryStrings is not null)
route = route.AddQueryString(_options.QueryStrings);
// add query strings
if (queryParams is not null)
route = route.AddQueryString(queryParams.ToPropertyDictionary());

View File

@ -15,6 +15,7 @@ public static class ObjectExtensions
prop => prop.GetValue(obj).ToSafeString()
);
}
public static Dictionary<string, string?> ToPropertyDictionary(this Dictionary<string, object?> obj)
{
return obj