feat: Implement search and sorting functionality for playlists in API and repository
This commit is contained in:
@@ -8,7 +8,7 @@ from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
from app.core.logging import get_logger
|
||||
from app.models.playlist import Playlist
|
||||
from app.models.sound import Sound
|
||||
from app.repositories.playlist import PlaylistRepository
|
||||
from app.repositories.playlist import PlaylistRepository, PlaylistSortField, SortOrder
|
||||
from app.repositories.sound import SoundRepository
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -212,6 +212,27 @@ class PlaylistService:
|
||||
"""Search all playlists by name."""
|
||||
return await self.playlist_repo.search_by_name(query)
|
||||
|
||||
async def search_and_sort_playlists(
|
||||
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,
|
||||
) -> list[dict]:
|
||||
"""Search and sort playlists with optional statistics."""
|
||||
return await self.playlist_repo.search_and_sort(
|
||||
search_query=search_query,
|
||||
sort_by=sort_by,
|
||||
sort_order=sort_order,
|
||||
user_id=user_id,
|
||||
include_stats=include_stats,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
)
|
||||
|
||||
async def get_playlist_sounds(self, playlist_id: int) -> list[Sound]:
|
||||
"""Get all sounds in a playlist."""
|
||||
await self.get_playlist_by_id(playlist_id) # Verify playlist exists
|
||||
|
||||
Reference in New Issue
Block a user