From 9fb8a22649fbb48ad98696d1d2cf5682bf17fd01 Mon Sep 17 00:00:00 2001 From: 2weiEmu Date: Fri, 1 May 2026 13:45:55 +0200 Subject: [PATCH] updated: method of songs get by id --- pkg/dbhandling/songsapi.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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) { + } -- 2.54.0