refactor(EConnectClient): Vereinfachung der Antwortverarbeitung in EConnectClient durch Verwendung von bedingten Ausdrücken und Entfernen der ungenutzten PostAsync-Überladung
This commit is contained in:
parent
beadc3c4bb
commit
20b5b8124d
@ -9,7 +9,5 @@ public interface IEConnectClient<TError> where TError : class
|
||||
public Task<Response<IAsyncEnumerable<TData?>, TError>> GetListAsAsyncEnumerable<TData>(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
||||
where TData : class;
|
||||
|
||||
public Task<Response<TError>> PostAsync(string? route = null, object? queryParams = null, CancellationToken cancel = default);
|
||||
|
||||
Task<Response<TError>> PostAsync(Stream stream, string fileName, string? route = null, object? queryParams = null, CancellationToken cancel = default);
|
||||
}
|
||||
@ -45,20 +45,16 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
||||
|
||||
var res = await Http.GetAsync(route, cancel);
|
||||
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
return new ()
|
||||
return res.IsSuccessStatusCode
|
||||
? new()
|
||||
{
|
||||
Ok = true,
|
||||
StatusCode = res.StatusCode,
|
||||
Data = (res.Content.Headers.ContentLength > 0)
|
||||
? await res.Content.ReadFromJsonAsync<TData>(_options.JsonSerializerOptions, cancel)
|
||||
Data = (res.Content.Headers.ContentLength > 0)
|
||||
? await res.Content.ReadFromJsonAsync<TData>(_options.JsonSerializerOptions, cancel)
|
||||
: null
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ()
|
||||
}
|
||||
: new()
|
||||
{
|
||||
Ok = false,
|
||||
StatusCode = res.StatusCode,
|
||||
@ -66,7 +62,6 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
||||
? await res.Content.ReadFromJsonAsync<TError>(_options.JsonSerializerOptions, cancel)
|
||||
: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Response<IAsyncEnumerable<TData?>, TError>> GetListAsAsyncEnumerable<TData>(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
||||
@ -76,20 +71,16 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
||||
|
||||
var res = await Http.GetAsync(route, cancel);
|
||||
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
return new ()
|
||||
return res.IsSuccessStatusCode
|
||||
? new()
|
||||
{
|
||||
Ok = true,
|
||||
StatusCode = res.StatusCode,
|
||||
Data = (res.Content.Headers.ContentLength > 0)
|
||||
? res.Content.ReadFromJsonAsAsyncEnumerable<TData>(_options.JsonSerializerOptions, cancel)
|
||||
: null
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new()
|
||||
}
|
||||
: new()
|
||||
{
|
||||
Ok = false,
|
||||
StatusCode = res.StatusCode,
|
||||
@ -97,34 +88,6 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
||||
? await res.Content.ReadFromJsonAsync<TError>(_options.JsonSerializerOptions, cancel)
|
||||
: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Response<TError>> PostAsync(string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
||||
{
|
||||
route = AddQueryString(route, queryParams);
|
||||
|
||||
var res = await Http.PostAsync(route, null, cancel);
|
||||
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Ok = true,
|
||||
StatusCode = res.StatusCode
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Ok = false,
|
||||
StatusCode = res.StatusCode,
|
||||
Error = (res.Content.Headers.ContentLength > 0)
|
||||
? await res.Content.ReadFromJsonAsync<TError>(_options.JsonSerializerOptions, cancel)
|
||||
: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Response<TError>> PostAsync(Stream stream, string fileName, string? route = null, object? queryParams = null, CancellationToken cancel = default)
|
||||
@ -152,14 +115,13 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
||||
|
||||
_logger?.LogCurlAsync(Http, requestMessage: message);
|
||||
|
||||
if (res.IsSuccessStatusCode)
|
||||
return new()
|
||||
return res.IsSuccessStatusCode
|
||||
? new()
|
||||
{
|
||||
Ok = true,
|
||||
StatusCode = res.StatusCode
|
||||
};
|
||||
else
|
||||
return new()
|
||||
}
|
||||
: new()
|
||||
{
|
||||
Ok = false,
|
||||
StatusCode = res.StatusCode,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user