TourIAm/TIAMWebApp/Server/Controllers/WeatherForecastAPIControlle...

37 lines
1.2 KiB
C#

using Microsoft.AspNetCore.Mvc;
using TIAMWebApp.Shared.Application.Models;
namespace TIAMWebApp.Server.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastAPIController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Kurvahideg", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastAPIController> _logger;
//Constructor for the WeatherForecastAPIController
public WeatherForecastAPIController(ILogger<WeatherForecastAPIController> logger)
{
_logger = logger;
}
// GET: WeatherForecastAPIController Calls the API and returns the weather forecast
[HttpGet]
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();
}
}
}