]> git.example.dev Git - binbsis50-sm.git/commitdiff
jank fix for creating new songs
author2weiEmu <saalbach.robert@outlook.de>
Fri, 1 May 2026 11:51:05 +0000 (13:51 +0200)
committer2weiEmu <saalbach.robert@outlook.de>
Fri, 1 May 2026 11:51:05 +0000 (13:51 +0200)
pkg/dbhandling/songsapi.go

index e1d1c5bc4d7a96a94e5757d0ab28b41a6cf0785f..4817c87f87f0fc3a2e034e2c5982b34a0c1c415f 100644 (file)
@@ -6,6 +6,8 @@ import (
        "strconv"
 )
 
+var START_COUNT = 400 // WARNING: jank
+
 /** TEST
  * An internal method to get the total number of songs as that is just something we need sometimes
  **/
@@ -85,14 +87,11 @@ func (dbw *DBWrapper) SongsGet(w http.ResponseWriter, r *http.Request) {
  * Create a new song in the database (only in the main list don't add to anything)
  **/
 func (dbw *DBWrapper) SongsCreate(w http.ResponseWriter, r *http.Request) {
-       count, err := dbw.getSongCount()
-       if err != nil {
-               w.WriteHeader(http.StatusInternalServerError)
-               return
-       }
+       count := START_COUNT // safe high count to create new songs WARNING:, this should only be used once ideally
+       START_COUNT += 1
 
        newSong := DBSong{}
-       err = json.NewDecoder(r.Body).Decode(&newSong)
+       err := json.NewDecoder(r.Body).Decode(&newSong)
 
        cmd := dbw.RedisDb.HSet(dbw.Ctx, "song:" + strconv.Itoa(count + 1),
                "artistName", newSong.ArtistName,
@@ -171,7 +170,6 @@ func (dbw *DBWrapper) SongsUpdateById(w http.ResponseWriter, r *http.Request) {
  **/
 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 {
@@ -195,9 +193,24 @@ func (dbw *DBWrapper) SongsGetById(w http.ResponseWriter, r *http.Request) {
        w.WriteHeader(http.StatusOK)
 }
 
-/** TODO TEST
- * 
+/** TEST
+ * Delete a song by ID from the database
  **/
 func (dbw *DBWrapper) SongsDeleteById(w http.ResponseWriter, r *http.Request) {
+       // the ID should be as 'song:XX' in the KEY section of DB song
+       deleteSong := DBSong{}
+       err := json.NewDecoder(r.Body).Decode(&deleteSong)
+       if err != nil {
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
+       
+       _, err = dbw.RedisDb.HDel(dbw.Ctx, deleteSong.Key, "artistName", "trackName", "trackViewUrl", "previewUrl", "artworkUrl60", "artworkUrl100", "displayArtistNames", "displayTrackName").Result()
+       if err != nil {
+               w.WriteHeader(http.StatusInternalServerError)
+               return
+       }
+
+       w.WriteHeader(http.StatusOK)
 
 }