File tree Expand file tree Collapse file tree 4 files changed +36
-28
lines changed Expand file tree Collapse file tree 4 files changed +36
-28
lines changed Original file line number Diff line number Diff line change 4
4
<TargetFramework >net8.0</TargetFramework >
5
5
<Nullable >enable</Nullable >
6
6
<ImplicitUsings >enable</ImplicitUsings >
7
- <RuntimeIdentifiers >linux-x64</RuntimeIdentifiers >
8
- <EnableSdkContainerDebugging >True</EnableSdkContainerDebugging >
9
- <UserSecretsId >7b8931a0-bda7-4546-b99d-dc41f97af10e</UserSecretsId >
10
- <DockerDefaultTargetOS >Linux</DockerDefaultTargetOS >
11
7
</PropertyGroup >
12
8
13
9
<ItemGroup >
16
12
<PackageReference Include =" Swashbuckle.AspNetCore" Version =" 6.4.0" />
17
13
</ItemGroup >
18
14
19
- <ItemGroup >
20
- <ContainerEnvironmentVariable Include =" ASPNETCORE_HTTPS_PORTS" >
21
- <Value >8081</Value >
22
- </ContainerEnvironmentVariable >
23
- </ItemGroup >
24
15
25
16
<ItemGroup >
26
17
<ProjectReference Include =" ..\ServiceDefaults\ServiceDefaults.csproj" />
Original file line number Diff line number Diff line change 6
6
<ImplicitUsings >enable</ImplicitUsings >
7
7
</PropertyGroup >
8
8
9
- <ItemGroup >
10
- <OpenApiReference Include =" OpenAPIs\swagger.json" CodeGenerator =" NSwagCSharp" Options =" /UseBaseUrl:false" ClassName =" NwsManager" >
11
- <SourceUri >https://localhost:7032/swagger/v1/swagger.json</SourceUri >
12
- </OpenApiReference >
13
- </ItemGroup >
14
9
15
10
<ItemGroup >
16
11
<PackageReference Include =" Microsoft.AspNetCore.Components.QuickGrid" Version =" 8.0.6" />
17
12
<PackageReference Include =" Microsoft.Extensions.ApiDescription.Client" Version =" 7.0.2" >
18
13
<PrivateAssets >all</PrivateAssets >
19
14
<IncludeAssets >runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets >
20
15
</PackageReference >
21
- <PackageReference Include =" Newtonsoft.Json" Version =" 13.0.1" />
22
- <PackageReference Include =" NSwag.ApiDescription.Client" Version =" 13.18.2" >
23
- <PrivateAssets >all</PrivateAssets >
24
- <IncludeAssets >runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets >
25
- </PackageReference >
26
16
</ItemGroup >
27
17
28
18
<ItemGroup >
Original file line number Diff line number Diff line change
1
+ using System . Text . Json ;
2
+
3
+ namespace MyWeatherHub ;
4
+
5
+ public class NwsManager ( HttpClient client )
6
+ {
7
+ readonly JsonSerializerOptions options = new ( )
8
+ {
9
+ PropertyNameCaseInsensitive = true
10
+ } ;
11
+
12
+ public async Task < Zone [ ] > GetZonesAsync ( )
13
+ {
14
+ var response = await client . GetAsync ( "zones" ) ;
15
+ response . EnsureSuccessStatusCode ( ) ;
16
+
17
+ var content = await response . Content . ReadAsStringAsync ( ) ;
18
+ var zones = JsonSerializer . Deserialize < Zone [ ] > ( content , options ) ;
19
+
20
+ return zones ?? [ ] ;
21
+ }
22
+
23
+ public async Task < Forecast [ ] > GetForecastByZoneAsync ( string zoneId )
24
+ {
25
+ var response = await client . GetAsync ( $ "forecast/{ zoneId } ") ;
26
+ response . EnsureSuccessStatusCode ( ) ;
27
+ var content = await response . Content . ReadAsStringAsync ( ) ;
28
+ var forecast = JsonSerializer . Deserialize < Forecast [ ] > ( content , options ) ;
29
+
30
+ return forecast ?? [ ] ;
31
+ }
32
+ }
33
+
34
+ public record Zone ( string Key , string Name , string State ) ;
35
+
36
+ public record Forecast ( string Name , string DetailedForecast ) ;
Original file line number Diff line number Diff line change 4
4
<TargetFramework >net8.0</TargetFramework >
5
5
<Nullable >enable</Nullable >
6
6
<ImplicitUsings >enable</ImplicitUsings >
7
- <RuntimeIdentifiers >linux-x64</RuntimeIdentifiers >
8
- <EnableSdkContainerDebugging >True</EnableSdkContainerDebugging >
9
- <UserSecretsId >7b8931a0-bda7-4546-b99d-dc41f97af10e</UserSecretsId >
10
- <DockerDefaultTargetOS >Linux</DockerDefaultTargetOS >
11
7
</PropertyGroup >
12
8
13
9
<ItemGroup >
14
10
<PackageReference Include =" Microsoft.AspNetCore.OpenApi" Version =" 8.0.6" />
15
11
<PackageReference Include =" Swashbuckle.AspNetCore" Version =" 6.4.0" />
16
12
</ItemGroup >
17
13
18
- <ItemGroup >
19
- <ContainerEnvironmentVariable Include =" ASPNETCORE_HTTPS_PORTS" >
20
- <Value >8081</Value >
21
- </ContainerEnvironmentVariable >
22
- </ItemGroup >
23
14
24
15
</Project >
You can’t perform that action at this time.
0 commit comments