update to use get-init instead of input parameter

This commit is contained in:
tekh 2025-08-15 15:03:42 +02:00
parent 4bb6a6cf18
commit ad9f7ef7e4
2 changed files with 39 additions and 7 deletions

View File

@ -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; }
}

View File

@ -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
};
}
}
}