From: 2weiEmu Date: Fri, 1 May 2026 11:51:05 +0000 (+0200) Subject: jank fix for creating new songs X-Git-Url: https://git.saalbach.dev/?a=commitdiff_plain;h=88771922355386069928227b5c985636d8aa3660;p=binbsis50-sm.git jank fix for creating new songs --- diff --git a/pkg/dbhandling/songsapi.go b/pkg/dbhandling/songsapi.go index e1d1c5b..4817c87 100644 --- a/pkg/dbhandling/songsapi.go +++ b/pkg/dbhandling/songsapi.go @@ -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) }