mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-05-16 07:17:54 +02:00
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
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;
|
|
}
|
|
|
|
public record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
|
{
|
|
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
}
|
|
} |