"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
**/
* 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,
**/
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.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)
}