diff --git a/internal/http/dj_handlers.go b/internal/http/dj_handlers.go index a5d4be8..d0d7aaf 100644 --- a/internal/http/dj_handlers.go +++ b/internal/http/dj_handlers.go @@ -110,5 +110,17 @@ func (dj *DJHandlers) Status(w http.ResponseWriter, r *http.Request) { http.Error(w, "status parsing failed", http.StatusInternalServerError) } } + +func (dj *DJHandlers) MostListenedSong(w http.ResponseWriter, r *http.Request) { + w.Header().Add("Content-Type", "application/json") + mls := radio.MostListened() + if mls == nil { + w.WriteHeader(http.StatusNotFound) + return + } + err := json.NewEncoder(w).Encode(mls) + if err != nil { + log.Println("DJHandlers.MostListenedSong:", err) + http.Error(w, "MostListenedSong parsing failed", http.StatusInternalServerError) } }