Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor projects and update JSON handling #12

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions complete/Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>linux-x64</RuntimeIdentifiers>
<EnableSdkContainerDebugging>True</EnableSdkContainerDebugging>
<UserSecretsId>7b8931a0-bda7-4546-b99d-dc41f97af10e</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,11 +12,6 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ContainerEnvironmentVariable Include="ASPNETCORE_HTTPS_PORTS">
<Value>8081</Value>
</ContainerEnvironmentVariable>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ServiceDefaults\ServiceDefaults.csproj" />
Expand Down
10 changes: 0 additions & 10 deletions complete/MyWeatherHub/MyWeatherHub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<OpenApiReference Include="OpenAPIs\swagger.json" CodeGenerator="NSwagCSharp" Options="/UseBaseUrl:false" ClassName="NwsManager">
<SourceUri>https://localhost:7032/swagger/v1/swagger.json</SourceUri>
</OpenApiReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="7.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NSwag.ApiDescription.Client" Version="13.18.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 36 additions & 0 deletions complete/MyWeatherHub/NwsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Text.Json;

namespace MyWeatherHub;

public class NwsManager(HttpClient client)
{
readonly JsonSerializerOptions options = new()
{
PropertyNameCaseInsensitive = true
};

public async Task<Zone[]> GetZonesAsync()
{
var response = await client.GetAsync("zones");
response.EnsureSuccessStatusCode();

var content = await response.Content.ReadAsStringAsync();
var zones = JsonSerializer.Deserialize<Zone[]>(content, options);

return zones ?? [];
}

public async Task<Forecast[]> GetForecastByZoneAsync(string zoneId)
{
var response = await client.GetAsync($"forecast/{zoneId}");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
var forecast = JsonSerializer.Deserialize<Forecast[]>(content, options);

return forecast ?? [];
}
}

public record Zone(string Key, string Name, string State);

public record Forecast(string Name, string DetailedForecast);
9 changes: 0 additions & 9 deletions start-with-api/Api/Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>linux-x64</RuntimeIdentifiers>
<EnableSdkContainerDebugging>True</EnableSdkContainerDebugging>
<UserSecretsId>7b8931a0-bda7-4546-b99d-dc41f97af10e</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ContainerEnvironmentVariable Include="ASPNETCORE_HTTPS_PORTS">
<Value>8081</Value>
</ContainerEnvironmentVariable>
</ItemGroup>

</Project>
Loading