Skip to content

Commit

Permalink
Move to auth_middelware helper and regenerate
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson committed Apr 23, 2024
1 parent 7e92db3 commit 1882563
Show file tree
Hide file tree
Showing 10 changed files with 425 additions and 61 deletions.
12 changes: 6 additions & 6 deletions packages/discovery-provider/src/api/v1/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class GetTransactionHistory(Resource):
params={"id": "A User ID"},
)
@full_user_ns.expect(transaction_history_parser)
@auth_middleware(transaction_history_parser)
@full_user_ns.marshal_with(transaction_history_response)
@auth_middleware()
def get(self, id, authed_user_id=None):
user_id = decode_with_abort(id, full_user_ns)
return self._get(user_id, authed_user_id)
Expand Down Expand Up @@ -103,8 +103,8 @@ class LegacyGetTransactionHistory(GetTransactionHistory):
deprecated=True,
)
@full_ns.expect(transaction_history_parser)
@auth_middleware(transaction_history_parser)
@full_ns.marshal_with(transaction_history_response)
@auth_middleware()
def get(self, authed_user_id=None):
"""Gets the user's $AUDIO transaction history within the App
Expand All @@ -130,8 +130,8 @@ class GetTransactionHistoryCount(Resource):
params={"id": "A User ID"},
)
@full_user_ns.expect(transaction_history_count_parser)
@auth_middleware(transaction_history_count_parser)
@full_user_ns.marshal_with(transaction_history_count_response)
@auth_middleware()
def get(self, id, authed_user_id=None):
user_id = decode_with_abort(id, full_ns)
if authed_user_id is None:
Expand All @@ -150,8 +150,8 @@ class LegacyGetTransactionHistoryCount(Resource):
deprecated=True,
)
@full_ns.expect(transaction_history_count_parser)
@auth_middleware(transaction_history_count_parser)
@full_ns.marshal_with(transaction_history_count_response)
@auth_middleware()
def get(self, authed_user_id=None):
"""Gets the count of the user's $AUDIO transaction history within the App.
Expand Down Expand Up @@ -204,8 +204,8 @@ class GetUSDCTransactionHistory(Resource):
params={"id": "A User ID"},
)
@full_user_ns.expect(usdc_transaction_history_parser)
@auth_middleware(usdc_transaction_history_parser)
@full_user_ns.marshal_with(transaction_history_response)
@auth_middleware()
def get(self, id, authed_user_id=None):
user_id = decode_with_abort(id, full_ns)
if authed_user_id is None:
Expand Down Expand Up @@ -244,8 +244,8 @@ class GetUSDCTransactionHistoryCount(Resource):
params={"id": "A User ID"},
)
@full_user_ns.expect(usdc_transaction_history_count_parser)
@auth_middleware(usdc_transaction_history_count_parser)
@full_user_ns.marshal_with(transaction_history_count_response)
@auth_middleware()
def get(self, id, authed_user_id=None):
user_id = decode_with_abort(id, full_ns)
if authed_user_id is None:
Expand Down
62 changes: 34 additions & 28 deletions packages/discovery-provider/src/api/v1/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ class TrackList(Resource):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@ns.expect(user_tracks_route_parser)
@auth_middleware(user_tracks_route_parser)
@ns.marshal_with(tracks_response)
@auth_middleware()
@cache(ttl_sec=5)
def get(self, id, authed_user_id=None):
decoded_id = decode_with_abort(id, ns)
Expand Down Expand Up @@ -401,8 +401,8 @@ class FullTrackList(Resource):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@full_ns.expect(user_tracks_route_parser)
@auth_middleware(user_tracks_route_parser)
@full_ns.marshal_with(full_tracks_response)
@auth_middleware()
@cache(ttl_sec=5)
def get(self, id, authed_user_id=None):
decoded_id = decode_with_abort(id, ns)
Expand Down Expand Up @@ -481,7 +481,6 @@ def _get(self, handle, authed_user_id=None):
tracks = list(map(extend_track, tracks))
return success_response(tracks)

@auth_middleware()
@full_ns.doc(
id="""Get Tracks by User Handle""",
description="""Gets the tracks created by a user using the user's handle""",
Expand All @@ -491,14 +490,14 @@ def _get(self, handle, authed_user_id=None):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@full_ns.expect(user_tracks_route_parser)
@auth_middleware(user_tracks_route_parser)
@full_ns.marshal_with(full_tracks_response)
def get(self, handle, authed_user_id=None):
return self._get(handle, authed_user_id)


@ns.route(USER_HANDLE_TRACKS, doc=False)
class HandleTrackList(HandleFullTrackList):
@auth_middleware()
@ns.doc(
id="""Get Tracks by User Handle""",
description="""Gets the tracks created by a user using the user's handle""",
Expand All @@ -508,6 +507,7 @@ class HandleTrackList(HandleFullTrackList):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@ns.expect(user_tracks_route_parser)
@auth_middleware(user_tracks_route_parser)
@ns.marshal_with(tracks_response)
def get(self, handle, authed_user_id):
return super()._get(handle, authed_user_id)
Expand Down Expand Up @@ -550,7 +550,6 @@ def _get(self, handle, authed_user_id=None):
tracks = list(map(extend_track, tracks))
return success_response(tracks)

@auth_middleware()
@full_ns.doc(
id="""Get AI Attributed Tracks by User Handle""",
description="""Gets the AI generated tracks attributed to a user using the user's handle""",
Expand All @@ -560,14 +559,14 @@ def _get(self, handle, authed_user_id=None):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@full_ns.expect(user_tracks_route_parser)
@auth_middleware(user_tracks_route_parser)
@full_ns.marshal_with(full_tracks_response)
def get(self, handle, authed_user_id=None):
return self._get(handle, authed_user_id)


@ns.route(USER_AI_ATTRIBUTED_TRACKS)
class HandleAITrackList(HandleFullAITrackList):
@auth_middleware()
@ns.doc(
id="""Get AI Attributed Tracks by User Handle""",
description="""Gets the AI generated tracks attributed to a user using the user's handle""",
Expand All @@ -577,6 +576,7 @@ class HandleAITrackList(HandleFullAITrackList):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@ns.expect(user_tracks_route_parser)
@auth_middleware(user_tracks_route_parser)
@ns.marshal_with(tracks_response)
def get(self, handle, authed_user_id):
return super()._get(handle, authed_user_id)
Expand Down Expand Up @@ -808,8 +808,8 @@ class UserTracksLibraryFull(Resource):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@full_ns.expect(user_tracks_library_parser)
@auth_middleware(user_tracks_library_parser)
@full_ns.marshal_with(track_library_full_response)
@auth_middleware()
@cache(ttl_sec=5)
def get(self, id: str, authed_user_id: Optional[int] = None):
"""Fetch a user's full library tracks."""
Expand Down Expand Up @@ -883,8 +883,8 @@ class UserPlaylistsLibraryFull(Resource):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@full_ns.expect(user_collections_library_parser)
@auth_middleware(user_collections_library_parser)
@full_ns.marshal_with(collection_library_full_response)
@auth_middleware()
@cache(ttl_sec=5)
def get(self, id: str, authed_user_id: Optional[int] = None):
"""Fetch a user's full library playlists."""
Expand All @@ -901,8 +901,8 @@ class UserAlbumsLibraryFull(Resource):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@full_ns.expect(user_collections_library_parser)
@auth_middleware(user_collections_library_parser)
@full_ns.marshal_with(collection_library_full_response)
@auth_middleware()
@cache(ttl_sec=5)
def get(self, id: str, authed_user_id: Optional[int] = None):
"""Fetch a user's full library playlists."""
Expand Down Expand Up @@ -1005,7 +1005,6 @@ def get(self, id):
@full_ns.route(USER_HISTORY_TRACKS_ROUTE)
class TrackHistoryFull(Resource):
@record_metrics
@auth_middleware()
@cache(ttl_sec=5)
def _get(self, id, authed_user_id):
args = track_history_parser.parse_args()
Expand Down Expand Up @@ -1038,6 +1037,7 @@ def _get(self, id, authed_user_id):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@full_ns.expect(track_history_parser)
@auth_middleware(track_history_parser)
@full_ns.marshal_with(history_response_full)
def get(self, id):
return self._get(id)
Expand All @@ -1052,8 +1052,8 @@ class TrackHistory(TrackHistoryFull):
responses={200: "Success", 400: "Bad request", 500: "Server error"},
)
@ns.expect(track_history_parser)
@auth_middleware(track_history_parser)
@ns.marshal_with(history_response)
@auth_middleware()
def get(self, id, authed_user_id):
return super()._get(id, authed_user_id)

Expand Down Expand Up @@ -2122,9 +2122,6 @@ def get(self, id):
)


purchases_and_sales_count_parser = current_user_parser.copy()


purchases_response = make_full_response(
"purchases_response", full_ns, fields.List(fields.Nested(purchase))
)
Expand All @@ -2143,8 +2140,8 @@ class FullPurchases(Resource):
params={"id": "A User ID"},
)
@full_ns.expect(purchases_and_sales_parser)
@auth_middleware(purchases_and_sales_parser)
@full_ns.marshal_with(purchases_response)
@auth_middleware()
def get(self, id, authed_user_id=None):
decoded_id = decode_with_abort(id, full_ns)
if decoded_id != authed_user_id:
Expand All @@ -2165,6 +2162,9 @@ def get(self, id, authed_user_id=None):
return success_response(list(map(extend_purchase, purchases)))


purchases_and_sales_count_parser = current_user_parser.copy()


@full_ns.route("/<string:id>/purchases/count")
class FullPurchasesCount(Resource):
@full_ns.doc(
Expand All @@ -2173,8 +2173,8 @@ class FullPurchasesCount(Resource):
params={"id": "A User ID"},
)
@full_ns.expect(purchases_and_sales_count_parser)
@auth_middleware(purchases_and_sales_count_parser)
@full_ns.marshal_with(purchases_count_response)
@auth_middleware()
def get(self, id, authed_user_id=None):
decoded_id = decode_with_abort(id, full_ns)
if decoded_id != authed_user_id:
Expand All @@ -2195,8 +2195,8 @@ class FullSales(Resource):
params={"id": "A User ID"},
)
@full_ns.expect(purchases_and_sales_parser)
@auth_middleware(purchases_and_sales_parser)
@full_ns.marshal_with(purchases_response)
@auth_middleware()
def get(self, id, authed_user_id=None):
decoded_id = decode_with_abort(id, full_ns)
if decoded_id != authed_user_id:
Expand Down Expand Up @@ -2225,8 +2225,8 @@ class FullSalesCount(Resource):
params={"id": "A User ID"},
)
@full_ns.expect(purchases_and_sales_count_parser)
@auth_middleware(purchases_and_sales_count_parser)
@full_ns.marshal_with(purchases_count_response)
@auth_middleware()
def get(self, id, authed_user_id=None):
decoded_id = decode_with_abort(id, full_ns)
if decoded_id != authed_user_id:
Expand All @@ -2239,19 +2239,19 @@ def get(self, id, authed_user_id=None):
return success_response(count)


csv_download_parser = current_user_parser.copy()
purchases_download_parser = current_user_parser.copy()


@ns.route("/<string:id>/purchases/download")
class FullPurchasesDownload(Resource):
class PurchasesDownload(Resource):
@ns.doc(
id="Download Purchases as CSV",
description="Downloads the purchases the user has made as a CSV file",
params={"id": "A User ID"},
)
@ns.produces(["text/csv"])
@ns.expect(csv_download_parser)
@auth_middleware()
@ns.expect(purchases_download_parser)
@auth_middleware(purchases_download_parser)
def get(self, id, authed_user_id=None):
decoded_id = decode_with_abort(id, ns)
if decoded_id != authed_user_id:
Expand All @@ -2263,16 +2263,19 @@ def get(self, id, authed_user_id=None):
return response


sales_download_parser = current_user_parser.copy()


@ns.route("/<string:id>/sales/download")
class FullSalesDownload(Resource):
class SalesDownload(Resource):
@ns.doc(
id="Download Sales as CSV",
description="Downloads the sales the user has made as a CSV file",
params={"id": "A User ID"},
)
@ns.produces(["text/csv"])
@ns.expect(csv_download_parser)
@auth_middleware()
@ns.expect(sales_download_parser)
@auth_middleware(sales_download_parser)
def get(self, id, authed_user_id=None):
decoded_id = decode_with_abort(id, ns)
if decoded_id != authed_user_id:
Expand All @@ -2284,16 +2287,19 @@ def get(self, id, authed_user_id=None):
return response


withdrawals_download_parser = current_user_parser.copy()


@ns.route("/<string:id>/withdrawals/download")
class FullWithdrawalsDownload(Resource):
class WithdrawalsDownload(Resource):
@ns.doc(
id="""Download USDC Withdrawals as CSV""",
description="""Downloads the USDC withdrawals the user has made as a CSV file""",
params={"id": "A User ID"},
)
@ns.produces(["text/csv"])
@ns.expect(csv_download_parser)
@auth_middleware()
@ns.expect(withdrawals_download_parser)
@auth_middleware(withdrawals_download_parser)
def get(self, id, authed_user_id=None):
decoded_id = decode_with_abort(id, ns)
if decoded_id != authed_user_id:
Expand Down
Loading

0 comments on commit 1882563

Please sign in to comment.