|
| 1 | +using System.Text.Json; |
| 2 | +using System.Text.Json.Serialization; |
1 | 3 | using EDILibrary;
|
2 | 4 | using TransformerBeeClient;
|
3 | 5 |
|
4 | 6 | var builder = WebApplication.CreateBuilder(args);
|
5 | 7 | builder.Services.AddHttpClient();
|
6 | 8 |
|
7 | 9 | builder.Services.AddTransient<ITransformerBeeAuthenticator, NoAuthenticator>(); // Or you could use ClientIdClientSecretAuthenticator
|
8 |
| -builder.Services.AddHttpClient("TransformerBee", client => |
9 |
| -{ |
10 |
| - client.BaseAddress = new Uri("http://localhost:5021/"); // or https://transformerstage.utilibee.io |
11 |
| -}); |
| 10 | +builder.Services.AddHttpClient( |
| 11 | + "TransformerBee", |
| 12 | + client => |
| 13 | + { |
| 14 | + client.BaseAddress = new Uri("http://localhost:5021/"); // or https://transformerstage.utilibee.io |
| 15 | + } |
| 16 | +); |
12 | 17 | builder.Services.AddTransient<ICanConvertToBo4e, TransformerBeeRestClient>();
|
13 | 18 | builder.Services.AddTransient<ICanConvertToEdifact, TransformerBeeRestClient>();
|
14 | 19 |
|
15 | 20 | var app = builder.Build();
|
16 | 21 |
|
17 | 22 | app.MapGet("/", () => "I ❤ BO4E");
|
18 |
| -app.MapGet("/talkToTransformerBee", async (ICanConvertToBo4e transformerBeeRestClient) => |
19 |
| -{ |
20 |
| - var bo4e = await transformerBeeRestClient.ConvertToBo4e( |
21 |
| - "UNA:+,? 'UNB+UNOC:3+9912345789012:500+9909876543210:500+230703:1059+ASDFHGJ'UNH+11223344556678+UTILMD:D:11A:UN:S1.1'BGM+E01+918273746512345678901'DTM+137:202306300558?+00:303'NAD+MS+9912345789012::293'NAD+MR+9909876543210::293'IDE+24+918273746512345678901'IMD++Z36+Z13'DTM+92:202212312300?+00:303'STS+7++E01'LOC+Z16+78889918283'LOC+Z17+DE0000111122223333444455556667778'RFF+Z13:55001'SEQ+Z01'CCI+Z30++Z07'CCI+Z19++11X0-0000-0116-J'CCI+++Z15'CCI+++Z88'CAV+Z74:::Z09'CAV+Z73:::Z11'SEQ+Z12'QTY+Z16:0:P1'SEQ+Z03'CCI+++E13'CAV+Z30:::788811123'SEQ+Z75'CCI+Z61++ZG1'NAD+Z09+++Schaefer:Ulrike:::Frau:Z01'NAD+Z04+++Schaefer:Ulrike:::Frau:Z01+Flughafenstrasse::64+Vilseck++92247+DE'NAD+DP++++Flughafenstrasse::64+Vilseck++92247+DE'NAD+Z05+++Schaefer:Ulrike:::Frau:Z01+Flughafenstrasse::64+Vilseck++92247+DE'UNT+31+11223344556678'UNZ+1+ASDFHGJ'", |
22 |
| - EdifactFormatVersion.FV2310); |
23 |
| - return bo4e.Single().Transaktionen.Single(); |
24 |
| -}); |
| 23 | +app.MapGet( |
| 24 | + "/talkToTransformerBee", |
| 25 | + async (HttpContext context, ICanConvertToBo4e transformerBeeRestClient) => |
| 26 | + { |
| 27 | + var bo4e = await transformerBeeRestClient.ConvertToBo4e( |
| 28 | + "UNA:+,? 'UNB+UNOC:3+9912345789012:500+9909876543210:500+230703:1059+ASDFHGJ'UNH+11223344556678+UTILMD:D:11A:UN:S1.1'BGM+E01+918273746512345678901'DTM+137:202306300558?+00:303'NAD+MS+9912345789012::293'NAD+MR+9909876543210::293'IDE+24+918273746512345678901'IMD++Z36+Z13'DTM+92:202212312300?+00:303'STS+7++E01'LOC+Z16+78889918283'LOC+Z17+DE0000111122223333444455556667778'RFF+Z13:55001'SEQ+Z01'CCI+Z30++Z07'CCI+Z19++11X0-0000-0116-J'CCI+++Z15'CCI+++Z88'CAV+Z74:::Z09'CAV+Z73:::Z11'SEQ+Z12'QTY+Z16:0:P1'SEQ+Z03'CCI+++E13'CAV+Z30:::788811123'SEQ+Z75'CCI+Z61++ZG1'NAD+Z09+++Schaefer:Ulrike:::Frau:Z01'NAD+Z04+++Schaefer:Ulrike:::Frau:Z01+Flughafenstrasse::64+Vilseck++92247+DE'NAD+DP++++Flughafenstrasse::64+Vilseck++92247+DE'NAD+Z05+++Schaefer:Ulrike:::Frau:Z01+Flughafenstrasse::64+Vilseck++92247+DE'UNT+31+11223344556678'UNZ+1+ASDFHGJ'", |
| 29 | + EdifactFormatVersion.FV2310 |
| 30 | + ); |
| 31 | + context.Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Json; |
| 32 | + var result = bo4e.Single().Transaktionen.Single(); |
| 33 | + var json = JsonSerializer.Serialize( |
| 34 | + result, |
| 35 | + new JsonSerializerOptions() { Converters = { new JsonStringEnumConverter() } } |
| 36 | + ); |
| 37 | + await context.Response.WriteAsync(json); |
| 38 | + } |
| 39 | +); |
25 | 40 | app.Run();
|
26 | 41 |
|
27 |
| -public partial class Program |
28 |
| -{ |
29 |
| -} // required for integration testing; If you miss this the test will complain, that it cannot find a 'testhost.deps.json' |
| 42 | +public partial class Program { } // required for integration testing; If you miss this the test will complain, that it cannot find a 'testhost.deps.json' |
0 commit comments