Filtere Statusuebersicht nach Diagnosekriterien
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
85949937cc
commit
852bba6264
2 changed files with 49 additions and 1 deletions
|
|
@ -128,12 +128,27 @@ func handleGetLatestPlayerStatus(store playerStatusStore) http.HandlerFunc {
|
||||||
func handleListLatestPlayerStatuses(store playerStatusStore) http.HandlerFunc {
|
func handleListLatestPlayerStatuses(store playerStatusStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
records := store.List()
|
records := store.List()
|
||||||
|
wantConnectivity := strings.TrimSpace(r.URL.Query().Get("server_connectivity"))
|
||||||
|
wantStale := strings.TrimSpace(r.URL.Query().Get("stale"))
|
||||||
|
filtered := make([]playerStatusRecord, 0, len(records))
|
||||||
for i := range records {
|
for i := range records {
|
||||||
records[i].Stale = isStale(records[i], store.Now())
|
records[i].Stale = isStale(records[i], store.Now())
|
||||||
|
if wantConnectivity != "" && records[i].ServerConnectivity != wantConnectivity {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if wantStale != "" {
|
||||||
|
if wantStale == "true" && !records[i].Stale {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if wantStale == "false" && records[i].Stale {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filtered = append(filtered, records[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
writeJSON(w, http.StatusOK, map[string]any{
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
"screens": records,
|
"screens": filtered,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -402,3 +402,36 @@ func TestHandleListLatestPlayerStatuses(t *testing.T) {
|
||||||
t.Fatalf("response.Screens[0].ScreenID = %q, want %q", got, want)
|
t.Fatalf("response.Screens[0].ScreenID = %q, want %q", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHandleListLatestPlayerStatusesFiltersByConnectivityAndStale(t *testing.T) {
|
||||||
|
store := newInMemoryPlayerStatusStore()
|
||||||
|
store.now = func() time.Time {
|
||||||
|
return time.Date(2026, 3, 22, 16, 10, 0, 0, time.UTC)
|
||||||
|
}
|
||||||
|
store.Save(playerStatusRecord{ScreenID: "screen-online", Timestamp: "2026-03-22T16:09:30Z", Status: "running", ServerConnectivity: "online", ReceivedAt: "2026-03-22T16:09:30Z", HeartbeatEverySeconds: 30})
|
||||||
|
store.Save(playerStatusRecord{ScreenID: "screen-offline", Timestamp: "2026-03-22T16:00:00Z", Status: "running", ServerConnectivity: "offline", ReceivedAt: "2026-03-22T16:00:00Z", HeartbeatEverySeconds: 30})
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/api/v1/screens/status?server_connectivity=offline&stale=true", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
|
||||||
|
handleListLatestPlayerStatuses(store)(w, req)
|
||||||
|
|
||||||
|
if got, want := w.Code, http.StatusOK; got != want {
|
||||||
|
t.Fatalf("status = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
var response struct {
|
||||||
|
Screens []playerStatusRecord `json:"screens"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {
|
||||||
|
t.Fatalf("Unmarshal() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := len(response.Screens), 1; got != want {
|
||||||
|
t.Fatalf("len(response.Screens) = %d, want %d", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := response.Screens[0].ScreenID, "screen-offline"; got != want {
|
||||||
|
t.Fatalf("response.Screens[0].ScreenID = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue