mirror of
https://github.com/farcasclaudiu/LearnCollectInst.git
synced 2026-06-22 07:01:08 +03:00
42 lines
1.3 KiB
C#
Executable File
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;
|
|
}
|
|
}
|
|
} |