From: 2weiEmu Date: Fri, 1 May 2026 11:45:55 +0000 (+0200) Subject: updated: method of songs get by id X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=9fb8a22649fbb48ad98696d1d2cf5682bf17fd01;p=binbsis50-sm.git updated: method of songs get by id --- diff --git a/pkg/dbhandling/songsapi.go b/pkg/dbhandling/songsapi.go index d1b2aa5..e1d1c5b 100644 --- a/pkg/dbhandling/songsapi.go +++ b/pkg/dbhandling/songsapi.go @@ -77,6 +77,7 @@ func (dbw *DBWrapper) SongsGet(w http.ResponseWriter, r *http.Request) { } w.Write(b) + w.WriteHeader(http.StatusOK) } @@ -165,15 +166,38 @@ func (dbw *DBWrapper) SongsUpdateById(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } -/** TODO TEST - * +/** TEST + * Method to get a specific song by ID **/ func (dbw *DBWrapper) SongsGetById(w http.ResponseWriter, r *http.Request) { + // the ID should be as 'song:XX' in the KEY section of DB song + // then all the non-zero / non-empty fields will be updated on that song + newSong := DBSong{} + err := json.NewDecoder(r.Body).Decode(&newSong) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + } + newSong, err = dbw.getSongByKey(newSong.Key) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + } + + b, err := json.Marshal(newSong) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + } + + w.Write(b) + w.WriteHeader(http.StatusOK) } /** TODO TEST * **/ func (dbw *DBWrapper) SongsDeleteById(w http.ResponseWriter, r *http.Request) { + }