Changed endpoints and db queries, chart now shows suggested mins and maxes
This commit is contained in:
@@ -39,6 +39,7 @@ func startServer() {
|
||||
r.HandleFunc("/since/{mins}", showCharts).Methods("GET")
|
||||
r.HandleFunc("/data/", sendData).Methods("GET")
|
||||
r.HandleFunc("/data/since/{mins}", sendData).Methods("GET")
|
||||
r.HandleFunc("/data/last/", sendLastSnapshot).Methods("GET")
|
||||
r.HandleFunc("/", saveSnapshot).Methods("POST")
|
||||
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||
http.Handle("/", r)
|
||||
@@ -84,6 +85,25 @@ func sendData(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func sendLastSnapshot(w http.ResponseWriter, r *http.Request) {
|
||||
record, err := getLastSnapshotRecordFromDb()
|
||||
if err != nil {
|
||||
sendInternalError(fmt.Errorf("couldn't read last snapshot from the database: %w", err), w, r)
|
||||
return
|
||||
}
|
||||
json, err := createJsonFromSnapshotRecords(record)
|
||||
if err != nil {
|
||||
sendInternalError(fmt.Errorf("couldn't create a json from the last record: %w", err), w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, err = fmt.Fprintf(w, string(json))
|
||||
if err != nil {
|
||||
sendInternalError(err, w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func saveSnapshot(w http.ResponseWriter, r *http.Request) {
|
||||
snapshotSub, err := createSnapshotSubFromJsonBodyStream(r.Body)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user