big update

This commit is contained in:
Daniel Ledda
2021-02-27 13:06:36 +01:00
parent 0dc3fdb9b8
commit eb5c9faa35
13 changed files with 746 additions and 169 deletions

View File

@@ -53,7 +53,7 @@ func sendData(w http.ResponseWriter, r *http.Request) {
}
dateSince = strings.Split(newDateSince.Format(time.RFC3339Nano), "Z")[0]
}
records, err := getSnapshotRecordsFromDb(dateSince)
records, err := fetchDatetimeSnapshotsSince(dateSince)
if internalErrorOnErr(fmt.Errorf("couldn't get snapshots from db: %w", err), w, r) { return }
json, err := createJsonFromSnapshotRecords(records)
if internalErrorOnErr(fmt.Errorf("couldn't create json from snapshots: %w", err), w, r) { return }
@@ -67,8 +67,8 @@ func createAndSendSnapshot(w http.ResponseWriter, r *http.Request) {
if internalErrorOnErr(fmt.Errorf("couldn't create a snapshot: %w", err), w, r) { return }
_, err = writeSnapshotToDb(snapshot)
if internalErrorOnErr(fmt.Errorf("couldn't save snapshot to db: %w", err), w, r) { return }
dbSnapshotRecord, err := getLastSnapshotRecordFromDb()
json, err := createJsonFromSnapshotRecords([]*SnapshotRecord{dbSnapshotRecord})
dbSnapshotRecord, err := fetchLastSnapshotWithDatetime()
json, err := createJsonFromSnapshotRecords([]*DatetimeSnapshotRecord{dbSnapshotRecord})
if internalErrorOnErr(fmt.Errorf("couldn't create json from last snapshots: %w", err), w, r) { return }
w.Header().Set("Content-Type", "application/json")
_, err = fmt.Fprintf(w, string(json))