Files
Claudiu Farcas bd1826f144 init commit
2022-10-05 09:07:14 +03:00

42 lines
1.3 KiB
C#
Executable File

using LearnCollectInst.Api.Model;
using Microsoft.AspNetCore.Mvc;
namespace LearnCollectInst.Api.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
_logger.LogInformation("Weather forecast list started");
var result = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
// PLAYGROUND:
//throw new ArgumentException("some induced error");
_logger.LogWarning("Weather forecast list was generated", result.Length);
return result;
}
}
}