refactor: Rename global current playlist methods for clarity and consistency
This commit is contained in:
@@ -56,7 +56,7 @@ class PlaylistService:
|
||||
|
||||
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()
|
||||
current_playlist = await self.playlist_repo.get_current_playlist()
|
||||
if current_playlist:
|
||||
return current_playlist
|
||||
|
||||
@@ -85,7 +85,7 @@ class PlaylistService:
|
||||
|
||||
# If this is set as current, unset the previous current playlist
|
||||
if is_current:
|
||||
await self._unset_current_playlist(user_id)
|
||||
await self._unset_current_playlist()
|
||||
|
||||
playlist_data = {
|
||||
"user_id": user_id,
|
||||
@@ -138,7 +138,7 @@ class PlaylistService:
|
||||
|
||||
if is_current is not None:
|
||||
if is_current:
|
||||
await self._unset_current_playlist(user_id)
|
||||
await self._unset_current_playlist()
|
||||
update_data["is_current"] = is_current
|
||||
|
||||
if update_data:
|
||||
@@ -157,15 +157,11 @@ class PlaylistService:
|
||||
detail="This playlist cannot be deleted",
|
||||
)
|
||||
|
||||
# Check if this is the current playlist
|
||||
was_current = playlist.is_current
|
||||
|
||||
await self.playlist_repo.delete(playlist)
|
||||
logger.info("Deleted playlist %s for user %s", playlist_id, user_id)
|
||||
|
||||
# If the deleted playlist was current, set main playlist as current
|
||||
if was_current:
|
||||
await self._set_main_as_current(user_id)
|
||||
# Note: If the deleted playlist was current, main playlist becomes fallback
|
||||
# No action needed as get_current_playlist() handles the fallback automatically
|
||||
|
||||
async def search_playlists(self, query: str, user_id: int) -> list[Playlist]:
|
||||
"""Search user's playlists by name."""
|
||||
@@ -260,26 +256,6 @@ class PlaylistService:
|
||||
await self.playlist_repo.reorder_playlist_sounds(playlist_id, sound_positions)
|
||||
logger.info("Reordered sounds in playlist %s for user %s", playlist_id, user_id)
|
||||
|
||||
async def set_current_playlist(self, playlist_id: int, user_id: int) -> Playlist:
|
||||
"""Set a playlist as the current playlist."""
|
||||
playlist = await self.get_playlist_by_id(playlist_id)
|
||||
|
||||
# Unset previous current playlist
|
||||
await self._unset_current_playlist(user_id)
|
||||
|
||||
# Set new current playlist
|
||||
playlist = await self.playlist_repo.update(playlist, {"is_current": True})
|
||||
logger.info("Set playlist %s as current for user %s", playlist_id, user_id)
|
||||
return playlist
|
||||
|
||||
async def unset_current_playlist(self, user_id: int) -> None:
|
||||
"""Unset the current playlist and set main playlist as current."""
|
||||
await self._unset_current_playlist(user_id)
|
||||
await self._set_main_as_current(user_id)
|
||||
logger.info(
|
||||
"Unset current playlist and set main as current for user %s",
|
||||
user_id,
|
||||
)
|
||||
|
||||
async def get_playlist_stats(self, playlist_id: int) -> dict[str, Any]:
|
||||
"""Get statistics for a playlist."""
|
||||
@@ -317,42 +293,27 @@ 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)."""
|
||||
# Current playlist methods (global by default)
|
||||
async def set_current_playlist(self, playlist_id: int) -> Playlist:
|
||||
"""Set a playlist as the 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()
|
||||
await self._unset_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)
|
||||
logger.info("Set playlist %s as 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_current_playlist(self) -> None:
|
||||
"""Unset the current playlist (main playlist becomes fallback)."""
|
||||
await self._unset_current_playlist()
|
||||
logger.info("Unset current playlist, main playlist is now fallback")
|
||||
|
||||
async def _unset_global_current_playlist(self) -> None:
|
||||
async def _unset_current_playlist(self) -> None:
|
||||
"""Unset any current playlist globally."""
|
||||
current_playlist = await self.playlist_repo.get_global_current_playlist()
|
||||
current_playlist = await self.playlist_repo.get_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)
|
||||
if current_playlist:
|
||||
await self.playlist_repo.update(current_playlist, {"is_current": False})
|
||||
|
||||
async def _set_main_as_current(self, user_id: int) -> None:
|
||||
"""Unset current playlist so main playlist becomes the fallback current."""
|
||||
# Just ensure no user playlist is marked as current
|
||||
# The get_current_playlist method will fallback to main playlist
|
||||
await self._unset_current_playlist(user_id)
|
||||
logger.info(
|
||||
"Unset current playlist for user %s, main playlist is now fallback",
|
||||
user_id,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user