1
0

/song endpoint was broken into two, the second one is /songs that returns a list of prev played songs, and /song just a current one.

This commit is contained in:
Alexander Andreev 2023-10-01 22:05:39 +04:00
parent 381da691a4
commit 96baa42fe0
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 18 additions and 10 deletions

View File

@ -59,8 +59,8 @@ func main() {
s = r.Sub("/playlist")
s.Handler(http.MethodGet, "/", djh.PlaylistNext)
s = r.Sub("/song")
s.Handler(http.MethodGet, "/", djh.Song)
r.Handler(http.MethodGet, "/song", djh.Song)
r.Handler(http.MethodGet, "/songs", djh.Songs)
srv := ihttp.NewHttpServer(r)

View File

@ -79,15 +79,23 @@ func (dj *DJHandlers) PlaylistNext(w http.ResponseWriter, _ *http.Request) {
}
func (dj *DJHandlers) Song(w http.ResponseWriter, r *http.Request) {
isList := r.URL.Query().Has("list")
w.Header().Add("Content-Type", "application/json")
if isList {
err := json.NewEncoder(w).Encode(songList.Current())
if err != nil {
log.Println("DJHandlers.Song:", err)
http.Error(w, "cannot obtain current song", http.StatusInternalServerError)
}
}
func (dj *DJHandlers) Songs(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(songList.List())
if err != nil {
log.Println("DJHandlers.Song list:", err)
log.Println("DJHandlers.Songs:", err)
http.Error(w, "cannot obtain list of last songs", http.StatusInternalServerError)
}
} else {
err := json.NewEncoder(w).Encode(songList.Current())
}
if err != nil {
log.Println("DJHandlers.Song current:", err)
}