fix: Songs API filtering and default vertical
Some checks failed
Deploy Fediversion / deploy (push) Failing after 1s
Some checks failed
Deploy Fediversion / deploy (push) Failing after 1s
- Added vertical query param to GET /songs for correct filtering - Changed default vertical to Phish (was Goose) to avoid empty data for new users
This commit is contained in:
parent
f966ef7c2e
commit
5b8cfffcf9
2 changed files with 18 additions and 3 deletions
|
|
@ -19,8 +19,23 @@ def create_song(song: SongCreate, session: Session = Depends(get_session), curre
|
|||
return db_song
|
||||
|
||||
@router.get("/", response_model=List[SongRead])
|
||||
def read_songs(offset: int = 0, limit: int = Query(default=100, le=1000), session: Session = Depends(get_session)):
|
||||
songs = session.exec(select(Song).offset(offset).limit(limit)).all()
|
||||
def read_songs(
|
||||
offset: int = 0,
|
||||
limit: int = Query(default=100, le=1000),
|
||||
vertical: str = Query(default=None, description="Filter by vertical slug"),
|
||||
session: Session = Depends(get_session)
|
||||
):
|
||||
query = select(Song)
|
||||
|
||||
if vertical:
|
||||
from models import Vertical
|
||||
vertical_entity = session.exec(select(Vertical).where(Vertical.slug == vertical)).first()
|
||||
if vertical_entity:
|
||||
query = query.where(Song.vertical_id == vertical_entity.id)
|
||||
else:
|
||||
return []
|
||||
|
||||
songs = session.exec(query.offset(offset).limit(limit)).all()
|
||||
return songs
|
||||
|
||||
@router.get("/{slug}", response_model=SongReadWithStats)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
export const VERTICALS = [
|
||||
{ slug: "goose", name: "Goose" },
|
||||
{ slug: "phish", name: "Phish" },
|
||||
{ slug: "goose", name: "Goose" },
|
||||
{ slug: "grateful-dead", name: "Grateful Dead" },
|
||||
{ slug: "dead-and-company", name: "Dead & Company" },
|
||||
{ slug: "billy-strings", name: "Billy Strings" },
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue