Files
StoreWeb/StoreHub/Controllers/v2/WeatherForecastController.cs
T
2026-08-14 18:00:58 +08:00

33 lines
930 B
C#

using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using StoreHub.Framework.Commons;
namespace StoreHub.Controllers.v2
{
[ApiController]
[ApiVersion("2.0")]
[Route("api/v{version:apiVersion}/[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries =
[
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
];
[HttpGet(Name = "GetWeatherForecastV2")]
public ApiResult<IEnumerable<WeatherForecastV2>> Get()
{
IEnumerable<WeatherForecastV2> data = Enumerable.Range(1, 10).Select(index => new WeatherForecastV2
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
FeelsLikeC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
return ApiResult.Success(data);
}
}
}