refactor: Update playlist service and endpoints for global current playlist management

This commit is contained in:
JSC
2025-08-01 16:58:25 +02:00
parent 3132175354
commit c0f51b2e23
4 changed files with 63 additions and 30 deletions

View File

@@ -54,9 +54,9 @@ class PlaylistService:
return main_playlist
async def get_current_playlist(self, user_id: int) -> Playlist:
"""Get the user's current playlist, fallback to main playlist."""
current_playlist = await self.playlist_repo.get_current_playlist(user_id)
async def get_current_playlist(self) -> Playlist:
"""Get the global current playlist, fallback to main playlist."""
current_playlist = await self.playlist_repo.get_global_current_playlist()
if current_playlist:
return current_playlist
@@ -317,6 +317,30 @@ class PlaylistService:
user_id,
)
# Global current playlist methods
async def set_current_playlist_global(self, playlist_id: int) -> Playlist:
"""Set a playlist as the global current playlist (app-wide)."""
playlist = await self.get_playlist_by_id(playlist_id)
# Unset any existing current playlist globally
await self._unset_global_current_playlist()
# Set new current playlist
playlist = await self.playlist_repo.update(playlist, {"is_current": True})
logger.info("Set playlist %s as global current playlist", playlist_id)
return playlist
async def unset_current_playlist_global(self) -> None:
"""Unset the global current playlist (main playlist becomes fallback)."""
await self._unset_global_current_playlist()
logger.info("Unset global current playlist, main playlist is now fallback")
async def _unset_global_current_playlist(self) -> None:
"""Unset any current playlist globally."""
current_playlist = await self.playlist_repo.get_global_current_playlist()
if current_playlist:
await self.playlist_repo.update(current_playlist, {"is_current": False})
async def _unset_current_playlist(self, user_id: int) -> None:
"""Unset the current playlist for a user."""
current_playlist = await self.playlist_repo.get_current_playlist(user_id)