feat: add vehicle location history query

This commit is contained in:
lingniu
2026-07-02 00:27:20 +08:00
parent cc89e0d537
commit fb9ab8525a
3 changed files with 304 additions and 4 deletions

View File

@@ -92,14 +92,17 @@ func main() {
closeHistory = func() { _ = db.Close() }
database := env("TDENGINE_DATABASE", history.DefaultDatabase)
mux.Handle("/api/history/raw-frames", history.NewRawFrameHandler(history.NewRawFrameRepository(db, database)))
logger.Info("history raw frame query enabled", "driver", driver, "database", database)
mux.Handle("/api/history/locations", history.NewLocationHandler(history.NewLocationRepository(db, database)))
logger.Info("history query enabled", "driver", driver, "database", database)
} else {
mux.HandleFunc("/api/history/raw-frames", func(w http.ResponseWriter, _ *http.Request) {
historyUnavailable := func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusServiceUnavailable)
_ = json.NewEncoder(w).Encode(map[string]any{"error": "TDENGINE_DSN is not configured"})
})
logger.Warn("TDENGINE_DSN is empty; raw frame query api disabled")
}
mux.HandleFunc("/api/history/raw-frames", historyUnavailable)
mux.HandleFunc("/api/history/locations", historyUnavailable)
logger.Warn("TDENGINE_DSN is empty; history query api disabled")
}
defer closeHistory()