create common AddQueryString method
This commit is contained in:
parent
3ca148f341
commit
2877d62f95
@ -19,8 +19,7 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
|||||||
LazyHttp = new Lazy<HttpClient>(httpFactory.CreateEConnectClient);
|
LazyHttp = new Lazy<HttpClient>(httpFactory.CreateEConnectClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Response<TData, TError>> GetAsync<TData>(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
private string? AddQueryString(string? route = null, object? queryParams = null)
|
||||||
where TData : class
|
|
||||||
{
|
{
|
||||||
// add global query strings
|
// add global query strings
|
||||||
if (_options.DefaultQueryStrings is not null)
|
if (_options.DefaultQueryStrings is not null)
|
||||||
@ -30,6 +29,14 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
|||||||
if (queryParams is not null)
|
if (queryParams is not null)
|
||||||
route = route.AddQueryString(queryParams.ToPropertyDictionary());
|
route = route.AddQueryString(queryParams.ToPropertyDictionary());
|
||||||
|
|
||||||
|
return route;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Response<TData, TError>> GetAsync<TData>(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
||||||
|
where TData : class
|
||||||
|
{
|
||||||
|
route = AddQueryString(route, queryParams);
|
||||||
|
|
||||||
var res = await Http.GetAsync(route, cancel);
|
var res = await Http.GetAsync(route, cancel);
|
||||||
|
|
||||||
if (res.IsSuccessStatusCode)
|
if (res.IsSuccessStatusCode)
|
||||||
@ -57,13 +64,7 @@ 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)
|
public async Task<Response<IAsyncEnumerable<TData?>, TError>> GetListAsAsyncEnumerable<TData>(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
||||||
where TData : class
|
where TData : class
|
||||||
{
|
{
|
||||||
// add global query strings
|
route = AddQueryString(route, queryParams);
|
||||||
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.GetAsync(route, cancel);
|
var res = await Http.GetAsync(route, cancel);
|
||||||
|
|
||||||
@ -92,13 +93,7 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
|||||||
public async Task<Response<TData, TError>> PostAsync<TData>(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
public async Task<Response<TData, TError>> PostAsync<TData>(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
||||||
where TData : class
|
where TData : class
|
||||||
{
|
{
|
||||||
// add global query strings
|
route = AddQueryString(route, queryParams);
|
||||||
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);
|
var res = await Http.PostAsync(route, null, cancel);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user