Skip to content

Commit 21f9c52

Browse files
committed
no passing solid wall thing block
1 parent e2b07e5 commit 21f9c52

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

MyMusicBoxApi/database/playlisttable.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewPlaylistTableInstance() IPlaylistTable {
2424
}
2525

2626
func (table *PlaylistTable) FetchPlaylists(ctx context.Context, lastKnowPlaylistId int) (playlists []models.Playlist, error error) {
27-
query := "SELECT Id, Name, ThumbnailPath, Description, CreationDate FROM Playlist WHERE Id > $1 ORDER BY Id" // order by?
27+
query := "SELECT Id, Name, ThumbnailPath, Description, CreationDate, IsPublic FROM Playlist WHERE Id > $1 ORDER BY Id" // order by?
2828

2929
rows, err := table.QueryRowsContex(ctx, query, lastKnowPlaylistId)
3030

@@ -41,7 +41,7 @@ func (table *PlaylistTable) FetchPlaylists(ctx context.Context, lastKnowPlaylist
4141
playlists = make([]models.Playlist, 0)
4242

4343
for rows.Next() {
44-
scanError := rows.Scan(&playlist.Id, &playlist.Name, &playlist.ThumbnailPath, &playlist.Description, &playlist.CreationDate)
44+
scanError := rows.Scan(&playlist.Id, &playlist.Name, &playlist.ThumbnailPath, &playlist.Description, &playlist.CreationDate, &playlist.IsPublic)
4545

4646
if scanError != nil {
4747
logging.Error(fmt.Sprintf("Scan error: %s", scanError.Error()))
@@ -68,9 +68,9 @@ func (table *PlaylistTable) InsertPlaylist(playlist models.Playlist) (lastInsert
6868
}
6969

7070
func (table *PlaylistTable) DeletePlaylist(playlistId int) (error error) {
71-
query := `DELETE FROM Playlist WHERE Id = $1`
71+
query := `DELETE FROM Playlist WHERE Id = $1 AND IsPublic = $2` // Prevemts private playlists (like the default one) from being deleted for real
7272

73-
err := table.NonScalarQuery(query, playlistId)
73+
err := table.NonScalarQuery(query, playlistId, true)
7474

7575
if err != nil {
7676
logging.Error(fmt.Sprintf("Failed to delete playlist: %s", err.Error()))

MyMusicBoxApi/http/playlist.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ func (handler *PlaylistHandler) DeletePlaylist(ctx *gin.Context) {
110110
return
111111
}
112112

113+
if DefaultPlaylistId == id {
114+
ctx.JSON(http.StatusInternalServerError, models.ErrorResponse("Funky music... "))
115+
return
116+
}
117+
113118
err = handler.PlaylistTable.DeletePlaylist(id)
114119

115120
// TODO delete background image if its not the default image for it

0 commit comments

Comments
 (0)