using ChrisKaczor.HomeMonitor.Environment.Service.Data; using ChrisKaczor.HomeMonitor.Environment.Service.Models; using Microsoft.AspNetCore.Mvc; namespace ChrisKaczor.HomeMonitor.Environment.Service.Controllers; [Route("[controller]")] [ApiController] public class ReadingsController(Database database) : ControllerBase { [HttpGet("recent")] public async Task>> GetRecent([FromQuery] string? tz) { var recentReadings = await database.GetRecentReadings(); if (string.IsNullOrWhiteSpace(tz)) return Ok(recentReadings); try { var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(tz); foreach (var recentReading in recentReadings) { recentReading.Time = recentReading.Time.ToOffset(timeZoneInfo.GetUtcOffset(recentReading.Time)); } } catch (Exception e) { return BadRequest(e.Message); } return Ok(recentReadings); } }