mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-14 01:25:38 -05:00
Add initial history API
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using ChrisKaczor.HomeMonitor.Weather.Models;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -85,5 +87,14 @@ namespace ChrisKaczor.HomeMonitor.Weather.Service.Data
|
||||
|
||||
return await connection.QueryFirstOrDefaultAsync<WeatherReading>(query);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WeatherReading>> GetReadingHistory(DateTimeOffset start, DateTimeOffset end)
|
||||
{
|
||||
await using var connection = CreateConnection();
|
||||
|
||||
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Weather.Service.Data.Resources.GetReadingHistory.sql");
|
||||
|
||||
return await connection.QueryAsync<WeatherReading>(query, new { Start = start, End = end });
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Weather/Service/Data/Resources/GetReadingHistory.sql
Normal file
18
Weather/Service/Data/Resources/GetReadingHistory.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
SELECT Timestamp,
|
||||
WindDirection,
|
||||
WindSpeed,
|
||||
Humidity,
|
||||
HumidityTemperature,
|
||||
Rain,
|
||||
Pressure,
|
||||
PressureTemperature,
|
||||
BatteryLevel,
|
||||
LightLevel,
|
||||
Latitude,
|
||||
Longitude,
|
||||
Altitude,
|
||||
SatelliteCount,
|
||||
GpsTimestamp
|
||||
FROM Reading
|
||||
WHERE Timestamp BETWEEN @Start AND @End
|
||||
ORDER BY Timestamp ASC
|
||||
Reference in New Issue
Block a user