DotBased/TestWebApi/Controllers/WeatherController.cs

30 lines
927 B
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace TestWebApi.Controllers;
[ApiController]
[Route("[controller]")]
[Authorize]
public class WeatherController : ControllerBase
{
private readonly string[] _summaries =
[
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
];
[HttpGet("GetWeatherForecast")]
public async Task<ActionResult<List<WeatherForecast>>> GetForecast()
{
var forecast = 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)]
))
.ToList();
await Task.Delay(TimeSpan.FromSeconds(1));
return forecast;
}
}