namespace UnoMediaCollection.Server.Apis { internal static class WeatherForecastApi { private const string Tag = "Weather"; private static readonly string[] Summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; internal static WebApplication MapWeatherApi(this WebApplication app) { app.MapGet("/api/weatherforecast", GetForecast) .WithTags(Tag) .WithName(nameof(GetForecast)); return app; } /// /// Creates a make believe weather forecast for the next 5 days. /// /// /// A fake 5 day forecast /// A 5 Day Forecast /// Weather Forecast returned [Produces("application/json")] [ProducesResponseType(typeof(IEnumerable), 200)] private static IEnumerable GetForecast(ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger(nameof(WeatherForecastApi)); logger.LogDebug("Getting Weather Forecast."); return Enumerable.Range(1, 5).Select(index => new WeatherForecast( DateOnly.FromDateTime(DateTime.Now.AddDays(index)), Random.Shared.Next(-20, 55), Summaries[Random.Shared.Next(Summaries.Length)] ) ) .Select(x => { logger.LogInformation("Weather forecast for {Date} is a {Summary} {TemperatureC}°C", x.Date, x.Summary, x.TemperatureC); return x; }) .ToArray(); } } }