WeatherForecastController.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using TEAMModelOS.Filter;
  8. namespace TEAMModelAPI.Controllers
  9. {
  10. [ApiController]
  11. [Route("[controller]")]
  12. public class WeatherForecastController : ControllerBase
  13. {
  14. private static readonly string[] Summaries = new[]
  15. {
  16. "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
  17. };
  18. private readonly ILogger<WeatherForecastController> _logger;
  19. public WeatherForecastController(ILogger<WeatherForecastController> logger)
  20. {
  21. _logger = logger;
  22. }
  23. [HttpGet]
  24. [ApiToken]
  25. public IEnumerable<WeatherForecast> Get()
  26. {
  27. var rng = new Random();
  28. return Enumerable.Range(1, 5).Select(index => new WeatherForecast
  29. {
  30. Date = DateTime.Now.AddDays(index),
  31. TemperatureC = rng.Next(-20, 55),
  32. Summary = Summaries[rng.Next(Summaries.Length)]
  33. })
  34. .ToArray();
  35. }
  36. }
  37. }