feat(tracks): filter track list by ingest source
Add an optional `source` filter to `GET /api/v1/tracks` (and the `TrackRepository.list`/`count` port + SQLAlchemy adapter). Lets clients query, e.g., only uploaded tracks (`?source=upload`) newest-first — the backing for the webui's persistent "Recently uploaded" view. - test: upload then list with `?source=upload` (hit) / `?source=youtube` (miss) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -170,6 +170,7 @@ class SqlAlchemyTrackRepository:
|
||||
artist_id: uuid.UUID | None,
|
||||
album_id: uuid.UUID | None,
|
||||
q: str | None,
|
||||
source: str | None = None,
|
||||
sort_by: str = "created_at",
|
||||
order: str = "desc",
|
||||
limit: int = 50,
|
||||
@@ -180,6 +181,8 @@ class SqlAlchemyTrackRepository:
|
||||
stmt = stmt.where(TrackModel.artist_id == artist_id)
|
||||
if album_id is not None:
|
||||
stmt = stmt.where(TrackModel.album_id == album_id)
|
||||
if source is not None:
|
||||
stmt = stmt.where(TrackModel.source == source)
|
||||
if q:
|
||||
stmt = stmt.where(TrackModel.title.ilike(f"%{q}%"))
|
||||
|
||||
@@ -204,12 +207,15 @@ class SqlAlchemyTrackRepository:
|
||||
artist_id: uuid.UUID | None,
|
||||
album_id: uuid.UUID | None,
|
||||
q: str | None,
|
||||
source: str | None = None,
|
||||
) -> int:
|
||||
stmt = select(func.count()).select_from(TrackModel)
|
||||
if artist_id is not None:
|
||||
stmt = stmt.where(TrackModel.artist_id == artist_id)
|
||||
if album_id is not None:
|
||||
stmt = stmt.where(TrackModel.album_id == album_id)
|
||||
if source is not None:
|
||||
stmt = stmt.where(TrackModel.source == source)
|
||||
if q:
|
||||
stmt = stmt.where(TrackModel.title.ilike(f"%{q}%"))
|
||||
return (await self._session.execute(stmt)).scalar_one()
|
||||
|
||||
Reference in New Issue
Block a user