diff --git a/cmd/dwelling-radiodj/main.go b/cmd/dwelling-radiodj/main.go index 65c7a1c..d754e8c 100644 --- a/cmd/dwelling-radiodj/main.go +++ b/cmd/dwelling-radiodj/main.go @@ -62,6 +62,8 @@ func main() { r.Handler(http.MethodGet, "/song", djh.Song) r.Handler(http.MethodGet, "/songs", djh.Songs) + r.Handler(http.MethodGet, "/status", djh.Status) + srv := ihttp.NewHttpServer(r) if err := srv.Start(*listenAddress); err != nil { diff --git a/internal/http/dj_handlers.go b/internal/http/dj_handlers.go index 13fdf5f..1a191dc 100644 --- a/internal/http/dj_handlers.go +++ b/internal/http/dj_handlers.go @@ -96,8 +96,19 @@ func (dj *DJHandlers) Songs(w http.ResponseWriter, r *http.Request) { } } +func (dj *DJHandlers) Status(w http.ResponseWriter, r *http.Request) { + withList := r.URL.Query().Has("with-list") + if withList { + err := json.NewEncoder(w).Encode(&struct { + Current *radio.Song_ `json:"current_song,omitempty"` + Listeners *radio.ListenerCounter `json:"listeners"` + List []radio.Song_ `json:"last_songs,omitempty"` + }{ + Current: songList.Current(), + Listeners: dj.listeners, + List: songList.List()}) if err != nil { - log.Println("DJHandlers.Song current:", err) + log.Println("DJHandlers.Status-withList:", err) } } }