update to use get-init instead of input parameter
This commit is contained in:
parent
4bb6a6cf18
commit
ad9f7ef7e4
@ -1,5 +1,17 @@
|
||||
namespace Leanetec.EConnect.Domain.Entities;
|
||||
using System.Net;
|
||||
|
||||
public record Response<TError>(bool Ok, TError? Error = null) where TError : class;
|
||||
namespace Leanetec.EConnect.Domain.Entities;
|
||||
|
||||
public record Response<TData, TError>(bool Ok, TData? Data = null, TError? Error = null) where TData : class where TError : class;
|
||||
public record Response<TError>() where TError : class
|
||||
{
|
||||
public bool Ok { get; init; }
|
||||
|
||||
public HttpStatusCode? StatusCode { get; init; }
|
||||
|
||||
public TError? Error { get; init; }
|
||||
}
|
||||
|
||||
public record Response<TData, TError> : Response<TError> where TData : class where TError : class
|
||||
{
|
||||
public TData? Data { get; init; }
|
||||
}
|
||||
@ -35,12 +35,22 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await res.Content.ReadFromJsonAsync<TData>(_options.JsonSerializerOptions, cancel);
|
||||
return new Response<TData, TError>(true, Data: data);
|
||||
return new ()
|
||||
{
|
||||
Ok = true,
|
||||
StatusCode = res.StatusCode,
|
||||
Data = data
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = await res.Content.ReadFromJsonAsync<TError>(_options.JsonSerializerOptions, cancel);
|
||||
return new Response<TData, TError>(false, Error: error);
|
||||
return new ()
|
||||
{
|
||||
Ok = false,
|
||||
StatusCode = res.StatusCode,
|
||||
Error = error
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,12 +70,22 @@ public class EConnectClient<TError> : IEConnectClient<TError> where TError : cl
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
var data = res.Content.ReadFromJsonAsAsyncEnumerable<TData>(_options.JsonSerializerOptions, cancel);
|
||||
return new Response<IAsyncEnumerable<TData?>, TError>(true, Data: data);
|
||||
return new ()
|
||||
{
|
||||
Ok = true,
|
||||
StatusCode = res.StatusCode,
|
||||
Data = data
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = await res.Content.ReadFromJsonAsync<TError>(_options.JsonSerializerOptions, cancel);
|
||||
return new Response<IAsyncEnumerable<TData?>, TError>(false, Error: error);
|
||||
return new()
|
||||
{
|
||||
Ok = false,
|
||||
StatusCode = res.StatusCode,
|
||||
Error = error
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user