]> git.example.dev Git - binbsis50-sm.git/commitdiff
updated: method of songs get by id
author2weiEmu <saalbach.robert@outlook.de>
Fri, 1 May 2026 11:45:55 +0000 (13:45 +0200)
committer2weiEmu <saalbach.robert@outlook.de>
Fri, 1 May 2026 11:45:55 +0000 (13:45 +0200)
pkg/dbhandling/songsapi.go

index d1b2aa510c75f6862e8cd82e74aafb34790bd4aa..e1d1c5bc4d7a96a94e5757d0ab28b41a6cf0785f 100644 (file)
@@ -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) {
+
 }