mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-14 01:25:38 -05:00
Start adding API endpoints
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Dapper;
|
||||
using ChrisKaczor.HomeMonitor.Environment.Service.Models;
|
||||
using Dapper;
|
||||
using DbUp;
|
||||
using Npgsql;
|
||||
using System.Reflection;
|
||||
using ChrisKaczor.HomeMonitor.Environment.Service.Models.Indoor;
|
||||
|
||||
namespace ChrisKaczor.HomeMonitor.Environment.Service.Data;
|
||||
|
||||
@@ -41,7 +43,7 @@ public class Database(IConfiguration configuration)
|
||||
return connection;
|
||||
}
|
||||
|
||||
public async Task StoreMessageAsync(Message message)
|
||||
public async Task StoreMessageAsync(DeviceMessage message)
|
||||
{
|
||||
await using var connection = CreateConnection();
|
||||
|
||||
@@ -49,4 +51,13 @@ public class Database(IConfiguration configuration)
|
||||
|
||||
await connection.QueryAsync(query, message);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Readings>> GetRecentReadings()
|
||||
{
|
||||
await using var connection = CreateConnection();
|
||||
|
||||
var query = ResourceReader.GetString("ChrisKaczor.HomeMonitor.Environment.Service.Data.Queries.GetRecentReadings.sql");
|
||||
|
||||
return await connection.QueryAsync<Readings>(query).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
16
Environment/Service/Data/Queries/GetRecentReadings.sql
Normal file
16
Environment/Service/Data/Queries/GetRecentReadings.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
SELECT DISTINCT ON (name)
|
||||
time,
|
||||
name,
|
||||
model,
|
||||
temperature,
|
||||
pressure,
|
||||
humidity,
|
||||
luminance,
|
||||
gas_resistance AS gasResistance,
|
||||
color_temperature AS colorTemperature,
|
||||
air_quality_index AS airQualityIndex
|
||||
FROM
|
||||
reading
|
||||
ORDER BY
|
||||
name,
|
||||
time DESC
|
||||
Reference in New Issue
Block a user