diff --git a/core/playlists.go b/core/playlists.go index bfec3b5e9..83f8605f2 100644 --- a/core/playlists.go +++ b/core/playlists.go @@ -227,6 +227,12 @@ func (s *playlists) Update(ctx context.Context, playlistId string, if public != nil { pls.Public = *public } + // Special case: The playlist is now empty + if len(idxToRemove) > 0 && len(pls.Tracks) == 0 { + if err = repo.Tracks(playlistId).DeleteAll(); err != nil { + return err + } + } return repo.Put(pls) }) } diff --git a/model/playlist.go b/model/playlist.go index 262d724d9..a5c17a619 100644 --- a/model/playlist.go +++ b/model/playlist.go @@ -120,5 +120,6 @@ type PlaylistTrackRepository interface { AddArtists(artistIds []string) (int, error) AddDiscs(discs []DiscID) (int, error) Delete(id ...string) error + DeleteAll() error Reorder(pos int, newPos int) error } diff --git a/persistence/playlist_repository.go b/persistence/playlist_repository.go index 514063b81..d1c7258e2 100644 --- a/persistence/playlist_repository.go +++ b/persistence/playlist_repository.go @@ -110,10 +110,10 @@ func (r *playlistRepository) Put(p *model.Playlist) error { return nil } // Only update tracks if they were specified - if len(pls.Tracks) == 0 { - return nil + if len(pls.Tracks) > 0 { + return r.updateTracks(id, p.MediaFiles()) } - return r.updateTracks(id, p.MediaFiles()) + return r.RefreshStatus(id) } func (r *playlistRepository) Get(id string) (*model.Playlist, error) { diff --git a/persistence/playlist_track_repository.go b/persistence/playlist_track_repository.go index 0d4abe155..a4c6f014a 100644 --- a/persistence/playlist_track_repository.go +++ b/persistence/playlist_track_repository.go @@ -164,6 +164,18 @@ func (r *playlistTrackRepository) Delete(ids ...string) error { return r.playlistRepo.renumber(r.playlistId) } +func (r *playlistTrackRepository) DeleteAll() error { + if !r.isTracksEditable() { + return rest.ErrPermissionDenied + } + err := r.delete(Eq{"playlist_id": r.playlistId}) + if err != nil { + return err + } + + return r.playlistRepo.renumber(r.playlistId) +} + func (r *playlistTrackRepository) Reorder(pos int, newPos int) error { if !r.isTracksEditable() { return rest.ErrPermissionDenied