using ChrisKaczor.HomeMonitor.Weather.Models; using ChrisKaczor.HomeMonitor.Weather.Service.Data; using ChrisKaczor.HomeMonitor.Weather.Service.Models; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace ChrisKaczor.HomeMonitor.Weather.Service.Controllers { [Route("[controller]")] [ApiController] public class ReadingsController : ControllerBase { private readonly Database _database; public ReadingsController(Database database) { _database = database; } [HttpGet("recent")] public async Task> GetRecent() { return await _database.GetRecentReading(); } [HttpGet("history")] public async Task>> GetHistory(DateTimeOffset start, DateTimeOffset end) { return (await _database.GetReadingHistory(start, end)).ToList(); } [HttpGet("value-history")] public async Task>> GetValueHistory(WeatherValueType weatherValueType, DateTimeOffset start, DateTimeOffset end) { return (await _database.GetReadingValueHistory(weatherValueType, start, end)).ToList(); } [HttpGet("history-grouped")] public async Task>> GetHistoryGrouped(DateTimeOffset start, DateTimeOffset end, int bucketMinutes = 2) { return (await _database.GetReadingHistoryGrouped(start, end, bucketMinutes)).ToList(); } [HttpGet("wind-speed-history-grouped")] public async Task>> GetWindSpeedHistoryGrouped(DateTimeOffset start, DateTimeOffset end, int bucketMinutes = 2) { return (await _database.GetWindSpeedHistoryGrouped(start, end, bucketMinutes)).ToList(); } [HttpGet("wind-direction-history-grouped")] public async Task>> GetWindDirectionHistoryGrouped(DateTimeOffset start, DateTimeOffset end) { return (await _database.GetWindDirectionHistoryGrouped(start, end)).ToList(); } } }