refactor: Improve exception handling and logging in authentication and playlist services; enhance code readability and structure
All checks were successful
Backend CI / lint (push) Successful in 9m21s
Backend CI / test (push) Successful in 4m18s

This commit is contained in:
JSC
2025-08-13 00:04:55 +02:00
parent f094fbf140
commit bee1076239
14 changed files with 144 additions and 66 deletions

View File

@@ -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,