diff --git a/backend/routers/songs.py b/backend/routers/songs.py index 5535da3..979be79 100644 --- a/backend/routers/songs.py +++ b/backend/routers/songs.py @@ -23,6 +23,7 @@ def read_songs( offset: int = 0, limit: int = Query(default=100, le=1000), vertical: str = Query(default=None, description="Filter by vertical slug"), + sort: str = Query(default=None, regex="^(times_played)$"), session: Session = Depends(get_session) ): query = select(Song) @@ -34,6 +35,9 @@ def read_songs( query = query.where(Song.vertical_id == vertical_entity.id) else: return [] + + if sort == "times_played": + query = query.outerjoin(Performance).group_by(Song.id).order_by(func.count(Performance.id).desc()) songs = session.exec(query.offset(offset).limit(limit)).all() return songs diff --git a/frontend/app/[vertical]/page.tsx b/frontend/app/[vertical]/page.tsx index ae5fdb4..36a5775 100644 --- a/frontend/app/[vertical]/page.tsx +++ b/frontend/app/[vertical]/page.tsx @@ -139,13 +139,13 @@ export default async function VerticalPage({ params }: Props) { )} - {/* Top Songs */} + {/* Most Played Songs */} {topSongs.length > 0 && (
-

Top Songs

+

Most Played Songs

- All songs + View all songs