28 lines
1015 B
C#
28 lines
1015 B
C#
// ApiVersioningDemo.Api/Controllers/WeatherForecastController.cs
|
|
using Asp.Versioning;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace ApiVersioningDemo.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[ApiVersion("1.0")] // 1. Le decimos explícitamente que este es el controlador de la v1
|
|
[Route("api/v{version:apiVersion}/[controller]")] // 2. Modificamos la ruta para obligar a usar "api/v1/..."
|
|
public class WeatherForecastController : ControllerBase
|
|
{
|
|
private static readonly string[] Summaries = [
|
|
"Helado", "Frío", "Fresco", "Templado", "Cálido", "Caluroso", "Sofocante", "SuperScorching"
|
|
];
|
|
|
|
[HttpGet(Name = "GetWeatherForecast")]
|
|
public IEnumerable<WeatherForecast> Get()
|
|
{
|
|
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
|
{
|
|
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
|
TemperatureC = Random.Shared.Next(-20, 55),
|
|
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
|
})
|
|
.ToArray();
|
|
}
|
|
}
|