ChouBox/ChouBox.WebApi/Controllers/WeatherForecastController.cs
2025-04-23 19:20:23 +08:00

47 lines
1.5 KiB
C#

using ChouBox.Code.AppExtend;
using ChouBox.Model.Entities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
namespace ChouBox.WebApi.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;
private readonly YoudaContext _dbContext;
private readonly ChouBoxCodeBase _chouBoxCodeBase;
public WeatherForecastController(ILogger<WeatherForecastController> logger, YoudaContext dbContext, ChouBoxCodeBase chouBoxCodeBase)
{
_logger = logger;
_dbContext = dbContext;
_chouBoxCodeBase = chouBoxCodeBase;
}
[HttpGet(Name = "GetWeatherForecast")]
public async Task<IEnumerable<WeatherForecast>> Get()
{
var list = await _dbContext.Config.ToListAsync();
var c = await _chouBoxCodeBase.RedisCache.StringGetAsync("aaa");
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();
}
}
}