Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsolo committed Jul 5, 2022
1 parent 1f3bf42 commit e5105e4
Showing 1 changed file with 34 additions and 50 deletions.
84 changes: 34 additions & 50 deletions discovery-provider/src/api/v1/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,11 @@ def get(self, handle, authed_user_id=None):
class HandleTrackList(HandleFullTrackList):
@auth_middleware()
@ns.doc(
id="""Get User by Handle""",
description="Gets a single user by their handle",
params={"handle": "A User handle"},
id="""Get Tracks by User Handle""",
description="""Gets the tracks created by a user using the user's handle""",
params={
"handle": "A User handle",
},
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@ns.expect(user_tracks_route_parser)
Expand Down Expand Up @@ -499,6 +501,30 @@ class HandleRepostList(HandleFullRepostList):
def get(self, handle):
return super()._get(handle)

tags_route_parser = pagination_with_current_user_parser.copy()
tags_route_parser.remove_argument("offset")
tags_response = make_response("tags_response", ns, fields.List(fields.String))

@ns.route("/<string:id>/tags")
class MostUsedTags(Resource):
@record_metrics
@ns.doc(
id="""Get Top Track Tags""",
description="""Gets the most used track tags by a user.""",
params={"id": "A User ID"},
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@full_ns.expect(tags_route_parser)
@ns.marshal_with(tags_response)
@cache(ttl_sec=60 * 5)
def get(self, id):
"""Fetch most used tags in a user's tracks."""
decoded_id = decode_with_abort(id, ns)
args = tags_route_parser.parse_args()
limit = format_limit(args)
tags = get_top_user_track_tags({"user_id": decoded_id, "limit": limit})
return success_response(tags)


favorites_response = make_response(
"favorites_response", ns, fields.List(fields.Nested(activity_model))
Expand All @@ -508,6 +534,7 @@ def get(self, handle):
)


# different route from /<string:id>/favorites/tracks
@ns.route("/<string:id>/favorites")
class FavoritedTracks(Resource):
@record_metrics
Expand All @@ -526,31 +553,6 @@ def get(self, id):
return success_response(favorites)


tags_route_parser = pagination_with_current_user_parser.copy()
tags_route_parser.remove_argument("offset")
tags_response = make_response("tags_response", ns, fields.List(fields.String))


@ns.route("/<string:id>/tags")
class MostUsedTags(Resource):
@record_metrics
@ns.doc(
id="""Get Top Track Tags""",
description="""Gets the most used track tags by a user.""",
params={"id": "A User ID"},
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@full_ns.expect(tags_route_parser)
@ns.marshal_with(tags_response)
@cache(ttl_sec=60 * 5)
def get(self, id):
"""Fetch most used tags in a user's tracks."""
decoded_id = decode_with_abort(id, ns)
args = tags_route_parser.parse_args()
limit = format_limit(args)
tags = get_top_user_track_tags({"user_id": decoded_id, "limit": limit})
return success_response(tags)


USER_FAVORITED_TRACKS_ROUTE = "/<string:id>/favorites/tracks"

Expand Down Expand Up @@ -591,20 +593,6 @@ def get(self, id):
return self._get(id)


@ns.route(USER_FAVORITED_TRACKS_ROUTE)
class UserFavoritedTracks(UserFavoritedTracksFull):
@ns.doc(
id="""Get Favorites""",
description="""Gets a user's favorite tracks""",
params={"id": "A User ID"},
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@ns.expect(pagination_with_current_user_parser)
@ns.marshal_with(favorites_response)
def get(self, id):
return super()._get(id)


history_response = make_full_response(
"history_response", ns, fields.List(fields.Nested(activity_model))
)
Expand All @@ -622,7 +610,7 @@ class TrackHistoryFull(Resource):
def _get(self, id):
args = pagination_with_current_user_parser.parse_args()
decoded_id = decode_with_abort(id, ns)
current_user_id = get_current_user_id(args) # non optional?
current_user_id = get_current_user_id(args)
offset = format_offset(args)
limit = format_limit(args)
get_tracks_args = GetUserListeningHistoryArgs(
Expand Down Expand Up @@ -863,7 +851,7 @@ def get(self, id):
"genre", required=False, action="append", description="List of Genres"
)
top_genre_users_response = make_response(
"top_genre_users_response+", ns, fields.List(fields.Nested(user_model))
"top_genre_users_response", ns, fields.List(fields.Nested(user_model))
)
top_genre_users_response_full = make_full_response(
"top_genre_users_response_full",
Expand Down Expand Up @@ -1074,9 +1062,7 @@ def get(self, id):
)


@full_ns.route(
"/content_node/<string:replica_type>", doc=False
) # no non-full for this?
@full_ns.route("/content_node/<string:replica_type>", doc=False)
class UsersByContentNode(Resource):
@ns.doc(
id="""Get Users By Replica Type for Content Node""",
Expand Down Expand Up @@ -1319,9 +1305,7 @@ def get(self, id: str):
)


@full_ns.route(
"/<string:id>/supporting/<string:supported_user_id>"
) # non full not necessary here either?
@full_ns.route("/<string:id>/supporting/<string:supported_user_id>")
class FullGetSupporting(Resource):
@record_metrics
@full_ns.doc(
Expand Down

0 comments on commit e5105e4

Please sign in to comment.