refactor: Improve exception handling and logging in authentication and playlist services; enhance code readability and structure
This commit is contained in:
@@ -212,12 +212,13 @@ class PlaylistService:
|
||||
"""Search all playlists by name."""
|
||||
return await self.playlist_repo.search_by_name(query)
|
||||
|
||||
async def search_and_sort_playlists(
|
||||
async def search_and_sort_playlists( # noqa: PLR0913
|
||||
self,
|
||||
search_query: str | None = None,
|
||||
sort_by: PlaylistSortField | None = None,
|
||||
sort_order: SortOrder = SortOrder.ASC,
|
||||
user_id: int | None = None,
|
||||
*,
|
||||
include_stats: bool = False,
|
||||
limit: int | None = None,
|
||||
offset: int = 0,
|
||||
@@ -269,7 +270,7 @@ class PlaylistService:
|
||||
current_sounds = await self.playlist_repo.get_playlist_sounds(playlist_id)
|
||||
position = len(current_sounds)
|
||||
else:
|
||||
# Ensure position doesn't create gaps - if position is too high, place at end
|
||||
# Ensure position doesn't create gaps - if too high, place at end
|
||||
current_sounds = await self.playlist_repo.get_playlist_sounds(playlist_id)
|
||||
max_position = len(current_sounds)
|
||||
position = min(position, max_position)
|
||||
@@ -329,7 +330,11 @@ class PlaylistService:
|
||||
# Create sequential positions: 0, 1, 2, 3...
|
||||
sound_positions = [(sound.id, index) for index, sound in enumerate(sounds)]
|
||||
await self.playlist_repo.reorder_playlist_sounds(playlist_id, sound_positions)
|
||||
logger.debug("Reordered %s sounds in playlist %s to eliminate gaps", len(sounds), playlist_id)
|
||||
logger.debug(
|
||||
"Reordered %s sounds in playlist %s to eliminate gaps",
|
||||
len(sounds),
|
||||
playlist_id,
|
||||
)
|
||||
|
||||
async def reorder_playlist_sounds(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user