Changed endpoints and db queries, chart now shows suggested mins and maxes

This commit is contained in:
Daniel Ledda
2020-11-07 15:08:48 +01:00
parent 85bef1d4a3
commit 7eb97118b2
2 changed files with 3 additions and 2 deletions

View File

@@ -71,7 +71,7 @@ func getSnapshotRecordsFromDb(minuteAgo int) ([]*SnapshotRecord, error) {
query := "SELECT `%s`, `%s`, `%s`, `%s`, `%s` FROM `snapshots` WHERE `%s` > date_sub(now(), interval %v minute) ORDER BY `id` DESC;" 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)) rows, err := ClimateDb.Query(fmt.Sprintf(query, "id", "temp", "humidity", "co2", "time", "time", minuteAgo))
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("couldn't execute select query: %w", err)
} }
for rows.Next() { for rows.Next() {
var snapshotRecord SnapshotRecord var snapshotRecord SnapshotRecord

View File

@@ -1,6 +1,7 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@@ -91,7 +92,7 @@ func saveSnapshot(w http.ResponseWriter, r *http.Request) {
} }
func internalErrorOnErr(err error, w http.ResponseWriter, r *http.Request) bool { func internalErrorOnErr(err error, w http.ResponseWriter, r *http.Request) bool {
if err != nil { if errors.Unwrap(err) != nil {
errorMessage := "Internal Server Error!" errorMessage := "Internal Server Error!"
if DEBUG { if DEBUG {
errorMessage += fmt.Sprintf(" Happened during %s request for pattern '%s': %s", errorMessage += fmt.Sprintf(" Happened during %s request for pattern '%s': %s",