Compare commits
10 Commits
10e751b9a1
...
682fb772f7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
682fb772f7 | ||
|
|
9d5bf509d5 | ||
|
|
757ba77179 | ||
|
|
11ab4388d0 | ||
|
|
d904fded39 | ||
|
|
e6a8c81a0b | ||
|
|
4256a79122 | ||
|
|
c3c6ffdf99 | ||
|
|
8b248db4e2 | ||
|
|
c5787c8736 |
@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{AC628874-E
|
|||||||
docs\econnect-api_swagger.pdf = docs\econnect-api_swagger.pdf
|
docs\econnect-api_swagger.pdf = docs\econnect-api_swagger.pdf
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Leanetec.EConnect.Infrastructure", "src\Leanetec.EConnect.Infrastructure\Leanetec.EConnect.Infrastructure.csproj", "{88A1AA25-45F3-4082-8B5A-F95FC8A21057}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -29,6 +31,10 @@ Global
|
|||||||
{9242EEA9-447B-44A6-A66D-D671DD16D0BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{9242EEA9-447B-44A6-A66D-D671DD16D0BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{9242EEA9-447B-44A6-A66D-D671DD16D0BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{9242EEA9-447B-44A6-A66D-D671DD16D0BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{9242EEA9-447B-44A6-A66D-D671DD16D0BB}.Release|Any CPU.Build.0 = Release|Any CPU
|
{9242EEA9-447B-44A6-A66D-D671DD16D0BB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{88A1AA25-45F3-4082-8B5A-F95FC8A21057}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{88A1AA25-45F3-4082-8B5A-F95FC8A21057}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{88A1AA25-45F3-4082-8B5A-F95FC8A21057}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{88A1AA25-45F3-4082-8B5A-F95FC8A21057}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -36,6 +42,7 @@ Global
|
|||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{34DC964A-1905-7DFC-0125-D551D3EEFCDD} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
{34DC964A-1905-7DFC-0125-D551D3EEFCDD} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||||
{9242EEA9-447B-44A6-A66D-D671DD16D0BB} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
{9242EEA9-447B-44A6-A66D-D671DD16D0BB} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||||
|
{88A1AA25-45F3-4082-8B5A-F95FC8A21057} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {8C81AD6F-B903-4C78-873C-38EE216EFAD5}
|
SolutionGuid = {8C81AD6F-B903-4C78-873C-38EE216EFAD5}
|
||||||
|
|||||||
11
src/Leanetec.EConnect.Client/Interface/IEConnectClient.cs
Normal file
11
src/Leanetec.EConnect.Client/Interface/IEConnectClient.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using Leanetec.EConnect.Domain.Entities;
|
||||||
|
|
||||||
|
namespace Leanetec.EConnect.Client.Interface;
|
||||||
|
|
||||||
|
public interface IEConnectClient<TError> where TError : class
|
||||||
|
{
|
||||||
|
public Task<Response<TData, TError>> GetAsync<TData>(string? route = null, CancellationToken cancel = default) where TData : class;
|
||||||
|
|
||||||
|
public Task<Response<IAsyncEnumerable<TData?>, TError>> GetListAsAsyncEnumerable<TData>(string? route = null, CancellationToken cancel = default)
|
||||||
|
where TData : class;
|
||||||
|
}
|
||||||
39
src/Leanetec.EConnect.Domain/Entities/OrderDocument.cs
Normal file
39
src/Leanetec.EConnect.Domain/Entities/OrderDocument.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
namespace Leanetec.EConnect.Domain.Entities;
|
||||||
|
|
||||||
|
public class OrderDocument
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The unique internal id of the file
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name of the file
|
||||||
|
/// </summary>
|
||||||
|
public string? FileName { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The size of the file in bytes
|
||||||
|
/// </summary>
|
||||||
|
public int FileSizeInBytes { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The internal unique id of the folder containing this file
|
||||||
|
/// </summary>
|
||||||
|
public int ParentFolderId { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The string representation of the timstamp when this file has been created (uploaded)
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? CreatedOn { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The string representation of the timstamp when this file has been updated
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? LastUpdateOn { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The MIME type of the file
|
||||||
|
/// </summary>
|
||||||
|
public string? FileMimeType { get; init; }
|
||||||
|
}
|
||||||
10
src/Leanetec.EConnect.Domain/Entities/ProblemDetail.cs
Normal file
10
src/Leanetec.EConnect.Domain/Entities/ProblemDetail.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace Leanetec.EConnect.Domain.Entities;
|
||||||
|
|
||||||
|
public class ProblemDetail
|
||||||
|
{
|
||||||
|
public string? Type { get; init; }
|
||||||
|
public string? Title { get; init; }
|
||||||
|
public int? Status { get; init; }
|
||||||
|
public string? Detail { get; init; }
|
||||||
|
public string? Instance { get; init; }
|
||||||
|
}
|
||||||
5
src/Leanetec.EConnect.Domain/Entities/Response.cs
Normal file
5
src/Leanetec.EConnect.Domain/Entities/Response.cs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
namespace Leanetec.EConnect.Domain.Entities;
|
||||||
|
|
||||||
|
public record Response<TData, TError>(bool Ok, TData? Data = null, TError? Error = null)
|
||||||
|
where TData : class
|
||||||
|
where TError : class;
|
||||||
6
src/Leanetec.EConnect.Infrastructure/ClientExtensions.cs
Normal file
6
src/Leanetec.EConnect.Infrastructure/ClientExtensions.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace Leanetec.EConnect.Infrastructure;
|
||||||
|
|
||||||
|
public static class ClientExtensions
|
||||||
|
{
|
||||||
|
public static HttpClient CreateEConnectClient(this IHttpClientFactory factory) => factory.CreateClient(DependencyInjection.EConnectClientName);
|
||||||
|
}
|
||||||
36
src/Leanetec.EConnect.Infrastructure/DependencyInjection.cs
Normal file
36
src/Leanetec.EConnect.Infrastructure/DependencyInjection.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using Leanetec.EConnect.Client.Interface;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace Leanetec.EConnect.Infrastructure;
|
||||||
|
|
||||||
|
public static class DependencyInjection
|
||||||
|
{
|
||||||
|
internal static readonly string EConnectClientName = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
|
internal static IServiceCollection ConfigureEConnectClient(this IServiceCollection services, Action<HttpClient> configureClient)
|
||||||
|
{
|
||||||
|
services.AddHttpClient(EConnectClientName, configureClient);
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, Action<Config> options)
|
||||||
|
{
|
||||||
|
Config config = new(services);
|
||||||
|
options.Invoke(config);
|
||||||
|
services.ConfigureEConnectClient(config.EConnectClient);
|
||||||
|
services.AddScoped(typeof(IEConnectClient<>), typeof(EConnectClient<>));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class Config
|
||||||
|
{
|
||||||
|
private readonly IServiceCollection _services;
|
||||||
|
|
||||||
|
internal Config(IServiceCollection services)
|
||||||
|
{
|
||||||
|
_services = services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action<HttpClient> EConnectClient { get; set; } = _ => { };
|
||||||
|
}
|
||||||
|
}
|
||||||
49
src/Leanetec.EConnect.Infrastructure/EConnectClient.cs
Normal file
49
src/Leanetec.EConnect.Infrastructure/EConnectClient.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using Leanetec.EConnect.Client.Interface;
|
||||||
|
using Leanetec.EConnect.Domain.Entities;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
|
namespace Leanetec.EConnect.Infrastructure;
|
||||||
|
|
||||||
|
public class EConnectClient<TError> : IEConnectClient<TError> where TError : class
|
||||||
|
{
|
||||||
|
private readonly HttpClient _http;
|
||||||
|
|
||||||
|
public EConnectClient(IHttpClientFactory factory)
|
||||||
|
{
|
||||||
|
_http = factory.CreateEConnectClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Response<TData, TError>> GetAsync<TData>(string? route = null, CancellationToken cancel = default)
|
||||||
|
where TData : class
|
||||||
|
{
|
||||||
|
var res = await _http.GetAsync(route, cancel);
|
||||||
|
|
||||||
|
if (res.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var data = await res.Content.ReadFromJsonAsync<TData>(cancel);
|
||||||
|
return new Response<TData, TError>(true, Data: data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var error = await res.Content.ReadFromJsonAsync<TError>(cancel);
|
||||||
|
return new Response<TData, TError>(false, Error: error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Response<IAsyncEnumerable<TData?>, TError>> GetListAsAsyncEnumerable<TData>(string? route = null, CancellationToken cancel = default)
|
||||||
|
where TData : class
|
||||||
|
{
|
||||||
|
var res = await _http.GetAsync(route, cancel);
|
||||||
|
|
||||||
|
if (res.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var data = res.Content.ReadFromJsonAsAsyncEnumerable<TData>(cancel);
|
||||||
|
return new Response<IAsyncEnumerable<TData?>, TError>(true, Data: data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var error = await res.Content.ReadFromJsonAsync<TError>(cancellationToken: cancel);
|
||||||
|
return new Response<IAsyncEnumerable<TData?>, TError>(false, Error: error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Leanetec.EConnect.Client\Leanetec.EConnect.Client.csproj" />
|
||||||
|
<ProjectReference Include="..\Leanetec.EConnect.Domain\Leanetec.EConnect.Domain.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Loading…
x
Reference in New Issue
Block a user