From 9e0ca30d27289cd94ab531fa6853ae9ac9a97974 Mon Sep 17 00:00:00 2001 From: Darren Reid Date: Tue, 3 Oct 2023 11:35:28 +1100 Subject: [PATCH] Fix weather --- .../Data/WeatherForecast.cs | 12 --------- .../Data/WeatherForecastService.cs | 19 ------------- Gallery.Unified.Client/Program.cs | 1 + .../wwwroot/data/weather.json | 27 +++++++++++++++++++ Gallery.Unified/Program.cs | 2 -- 5 files changed, 28 insertions(+), 33 deletions(-) delete mode 100644 Gallery.Unified.Client/Data/WeatherForecast.cs delete mode 100644 Gallery.Unified.Client/Data/WeatherForecastService.cs create mode 100644 Gallery.Unified.Client/wwwroot/data/weather.json diff --git a/Gallery.Unified.Client/Data/WeatherForecast.cs b/Gallery.Unified.Client/Data/WeatherForecast.cs deleted file mode 100644 index d024815..0000000 --- a/Gallery.Unified.Client/Data/WeatherForecast.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace MyApp.Data; - -public class WeatherForecast -{ - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } -} \ No newline at end of file diff --git a/Gallery.Unified.Client/Data/WeatherForecastService.cs b/Gallery.Unified.Client/Data/WeatherForecastService.cs deleted file mode 100644 index 6b872b0..0000000 --- a/Gallery.Unified.Client/Data/WeatherForecastService.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace MyApp.Data; - -public class WeatherForecastService -{ - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - public Task GetForecastAsync(DateTime startDate) - { - return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = startDate.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }).ToArray()); - } -} \ No newline at end of file diff --git a/Gallery.Unified.Client/Program.cs b/Gallery.Unified.Client/Program.cs index 1318ac2..9b44295 100644 --- a/Gallery.Unified.Client/Program.cs +++ b/Gallery.Unified.Client/Program.cs @@ -10,6 +10,7 @@ builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); // builder.Services.AddScoped(s => s.GetRequiredService()); + var apiBaseUrl = builder.Configuration["ApiBaseUrl"] ?? builder.HostEnvironment.BaseAddress; builder.Services.AddBlazorApiClient(apiBaseUrl); diff --git a/Gallery.Unified.Client/wwwroot/data/weather.json b/Gallery.Unified.Client/wwwroot/data/weather.json new file mode 100644 index 0000000..23687ae --- /dev/null +++ b/Gallery.Unified.Client/wwwroot/data/weather.json @@ -0,0 +1,27 @@ +[ + { + "date": "2018-05-06", + "temperatureC": 1, + "summary": "Freezing" + }, + { + "date": "2018-05-07", + "temperatureC": 14, + "summary": "Bracing" + }, + { + "date": "2018-05-08", + "temperatureC": -13, + "summary": "Freezing" + }, + { + "date": "2018-05-09", + "temperatureC": -16, + "summary": "Balmy" + }, + { + "date": "2018-05-10", + "temperatureC": -2, + "summary": "Chilly" + } +] diff --git a/Gallery.Unified/Program.cs b/Gallery.Unified/Program.cs index d2ae69b..946ccb5 100644 --- a/Gallery.Unified/Program.cs +++ b/Gallery.Unified/Program.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Mvc; using MyApp; using MyApp.Client; -using MyApp.Data; var builder = WebApplication.CreateBuilder(args); @@ -28,7 +27,6 @@ builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(baseUrl) }); builder.Services.AddBlazorServerApiClient(baseUrl); -builder.Services.AddSingleton(); builder.Services.AddLocalStorage(); var app = builder.Build();