Record last time an environmental device reported

This commit is contained in:
2024-05-28 13:53:02 -04:00
parent d69d69bf68
commit b1a9230f91
12 changed files with 181 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
using ChrisKaczor.HomeMonitor.Environment.Service.Models;
using ChrisKaczor.HomeMonitor.Environment.Service.Models.Device;
using ChrisKaczor.HomeMonitor.Environment.Service.Models.Indoor;
using Dapper;
using DbUp;
@@ -80,4 +81,31 @@ public class Database(IConfiguration configuration)
return await connection.QueryAsync<ReadingsAggregate>(query, new { Start = start, End = end }).ConfigureAwait(false);
}
public async Task<IEnumerable<Device>> GetDevicesAsync()
{
await using var connection = CreateConnection();
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Environment.Service.Data.Queries.GetDevices.psql");
return await connection.QueryAsync<Device>(query).ConfigureAwait(false);
}
public async Task<Device?> GetDeviceAsync(string deviceName)
{
await using var connection = CreateConnection();
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Environment.Service.Data.Queries.GetDevice.psql");
return await connection.QueryFirstOrDefaultAsync<Device>(query, new { Name = deviceName }).ConfigureAwait(false);
}
public async Task SetDeviceLastUpdatedAsync(string deviceName, DateTimeOffset? lastUpdated)
{
await using var connection = CreateConnection();
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Environment.Service.Data.Queries.SetDeviceLastUpdated.psql");
await connection.ExecuteAsync(query, new { Name = deviceName, LastUpdated = lastUpdated }).ConfigureAwait(false);
}
}