Skip to content

Commit

Permalink
Fix top playlists with user_id (#4701)
Browse files Browse the repository at this point in the history
  • Loading branch information
jowlee committed Feb 2, 2023
1 parent 48b2b74 commit ec80d1c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
6 changes: 4 additions & 2 deletions discovery-provider/src/api/v1/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
get_default_max,
make_full_response,
make_response,
pagination_parser,
pagination_with_current_user_parser,
search_parser,
success_response,
Expand Down Expand Up @@ -276,7 +275,7 @@ def get(self):
return success_response(response["playlists"])


top_parser = pagination_parser.copy()
top_parser = pagination_with_current_user_parser.copy()
top_parser.add_argument(
"type",
required=True,
Expand Down Expand Up @@ -311,6 +310,9 @@ def get(self):
args["offset"] = 0
if args.get("type") not in ["album", "playlist"]:
abort_bad_request_param("type", ns)
current_user_id = get_current_user_id(args)
if current_user_id:
args["current_user_id"] = current_user_id

args["with_users"] = True

Expand Down
10 changes: 8 additions & 2 deletions discovery-provider/src/queries/get_top_playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


class GetTopPlaylistsArgs(TypedDict):
current_user_id: Optional[int]
limit: Optional[int]
mood: Optional[str]
filter: Optional[str]
Expand All @@ -33,7 +34,12 @@ class TopPlaylistKind(str, enum.Enum):


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

# NOTE: This is a temporary fix while migrating clients to pass
# along an encoded user id via url param
if current_user_id is None:
current_user_id = get_current_user_id(required=False)

# Argument parsing and checking
if kind not in ("playlist", "album"):
Expand All @@ -44,7 +50,7 @@ def get_top_playlists(kind: TopPlaylistKind, args: GetTopPlaylistsArgs):
limit = args.get("limit", 16)
mood = args.get("mood", None)

if "filter" in args:
if args.get("filter") is not None:
query_filter = args.get("filter")
if query_filter != "followees":
raise exceptions.ArgumentError(
Expand Down
4 changes: 4 additions & 0 deletions discovery-provider/src/queries/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ def get_top_playlists_route(type):
args["mood"] = None
if "with_users" in request.args:
args["with_users"] = parse_bool_param(request.args.get("with_users"))

current_user_id = get_current_user_id(required=False)
args["current_user_id"] = current_user_id

try:
playlists = get_top_playlists(type, args)
return api_helpers.success_response(playlists)
Expand Down
2 changes: 2 additions & 0 deletions libs/src/services/discoveryProvider/DiscoveryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,15 @@ export class DiscoveryProvider {
limit,
mood,
filter,
encodedUserId,
withUsers = false
}: Requests.GetTopFullPlaylistsParams) {
const req = Requests.getTopFullPlaylists({
type,
limit,
mood,
filter,
encodedUserId,
withUsers
})
return await this._makeRequest(req)
Expand Down
5 changes: 4 additions & 1 deletion libs/src/services/discoveryProvider/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,15 @@ export type GetTopFullPlaylistsParams = {
mood?: string
filter?: string
withUsers?: boolean
encodedUserId?: string
}

export const getTopFullPlaylists = ({
type,
limit,
mood,
filter,
encodedUserId,
withUsers = false
}: GetTopFullPlaylistsParams) => {
return {
Expand All @@ -521,7 +523,8 @@ export const getTopFullPlaylists = ({
limit,
mood,
filter,
with_users: withUsers
with_users: withUsers,
user_id: encodedUserId
}
}
}
Expand Down

0 comments on commit ec80d1c

Please sign in to comment.