Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

top playlists endpoint #3353

Merged
merged 2 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions discovery-provider/src/api/v1/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@
"full_playlist_response", full_ns, fields.List(fields.Nested(full_playlist_model))
)

playlists_with_score = ns.clone(
"playlist_full",
full_playlist_model,
{"score": fields.Float},
)

full_playlists_with_score_response = make_full_response(
"full_playlist_with_score_response",
full_ns,
fields.List(fields.Nested(playlists_with_score)),
)


def get_playlist(playlist_id, current_user_id):
"""Returns a single playlist, or None"""
Expand Down Expand Up @@ -195,13 +207,18 @@ def get(self):
choices=("album", "playlist"),
description="The collection type",
)
top_parser.add_argument(
"mood",
required=False,
description="Filer to a mood",
)


@ns.route("/top", doc=False)
@full_ns.route("/top", doc=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it weird that playlists endpoint can return both albums and playlists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean? There's no separate /album endpoints
For this, the type is specified to be album or playlist

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

top lives in v1/playlists, that's all. this is probably fine. maybe we should think about calling this stuff collection 🤷

class Top(Resource):
@record_metrics
@ns.doc(id="""Top Playlists""", description="""Gets top playlists.""")
@ns.marshal_with(playlists_response)
@ns.marshal_with(full_playlists_with_score_response)
@cache(ttl_sec=30 * 60)
def get(self):
args = top_parser.parse_args()
Expand Down
17 changes: 16 additions & 1 deletion discovery-provider/src/queries/get_top_playlists.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import enum
from typing import Optional, TypedDict

from sqlalchemy import desc
from src import exceptions
from src.models.playlists.aggregate_playlist import AggregatePlaylist
Expand All @@ -17,7 +20,19 @@
from src.utils.db_session import get_db_read_replica


def get_top_playlists(kind, args):
class GetTopPlaylistsArgs(TypedDict):
limit: Optional[int]
mood: Optional[str]
filter: Optional[str]
with_users: Optional[bool]


class TopPlaylistKind(str, enum.Enum):
playlist = "playlist"
album = "album"


def get_top_playlists(kind: TopPlaylistKind, args: GetTopPlaylistsArgs):
current_user_id = get_current_user_id(required=False)

# Argument parsing and checking
Expand Down