Moved the webapp to a webpack with some typescript, updated server wtih new endpoints

This commit is contained in:
Daniel Ledda
2020-11-14 01:06:29 +01:00
parent 6dba158ff0
commit 4e57a8eb47
21 changed files with 11118 additions and 20964 deletions

View File

@@ -4,6 +4,7 @@ import (
"database/sql"
_ "github.com/Freeaqingme/golang-sql-driver-mysql"
"fmt"
"time"
)
var ClimateDb *sql.DB
@@ -66,10 +67,10 @@ func getLastSnapshotRecordFromDb() (*SnapshotRecord, error) {
return &snapshotRecord, nil
}
func getSnapshotRecordsFromDb(minuteAgo int) ([]*SnapshotRecord, error) {
func getSnapshotRecordsFromDb(dateSince time.Time) ([]*SnapshotRecord, error) {
snapshots := make([]*SnapshotRecord, 0)
query := "SELECT `%s`, `%s`, `%s`, `%s`, `%s` FROM `snapshots` WHERE `%s` > date_sub(now(), interval %v minute) ORDER BY `id` DESC;"
rows, err := ClimateDb.Query(fmt.Sprintf(query, "id", "temp", "humidity", "co2", "time", "time", minuteAgo))
query := "SELECT `%s`, `%s`, `%s`, `%s`, `%s` FROM `snapshots` WHERE `%s` > %s ORDER BY `id` DESC;"
rows, err := ClimateDb.Query(fmt.Sprintf(query, "id", "temp", "humidity", "co2", "time", "time", dateSince.String()))
if err != nil {
return nil, fmt.Errorf("couldn't execute select query: %w", err)
}