from flask import Blueprint from flask_apispec import doc, marshal_with, use_kwargs from http import HTTPStatus import src.schemas.playlists.common as common_serializers from src.db.playlists.apple import get_playlist_streams_weekly_query, get_playlist_top_weekly_query, \ get_top_playlist_history_dates_query from src.utils.query import get_query_asdict blueprint = Blueprint("playlists_apple", __name__) @blueprint.route("/playlists/apple/top/weekly/", methods=["GET"]) @doc("") @use_kwargs(common_serializers.PlaylistsTopWeekly.Request, location="query") @marshal_with( common_serializers.PlaylistsTopWeekly.Response(many=True), code=HTTPStatus.OK, description="Latest top ranked playlists.", ) @marshal_with(None, code=HTTPStatus.UNAUTHORIZED, description="Authentication failed.") def get_playlists_top_weekly(**data): return get_query_asdict(get_playlist_top_weekly_query(**data)) @blueprint.route("/playlists/apple/previous/top/dates/", methods=["POST"]) @doc("") @use_kwargs(common_serializers.PlaylistsPreviousTopDates.RequestPostBody, location="json") @marshal_with(common_serializers.PlaylistsPreviousTopDates.Response(many=True), code=HTTPStatus.OK, description="") @marshal_with(None, code=HTTPStatus.UNAUTHORIZED, description="Authentication failed.") def get_playlists_previous_top_dates(**data): return get_query_asdict(get_top_playlist_history_dates_query(**data)) @blueprint.route("/playlists/apple/streams/weekly/", methods=["GET"]) @doc("") @use_kwargs(common_serializers.PlaylistsStreamsWeekly.Request, location="query") @marshal_with(common_serializers.PlaylistsStreamsWeekly.Response(many=True), code=HTTPStatus.OK, description="") @marshal_with(None, code=HTTPStatus.UNAUTHORIZED, description="Authentication failed.") def get_playlists_streams_weekly(**data): playlist_ids = data["playlist_ids"] market = data["market"] return get_query_asdict(get_playlist_streams_weekly_query(playlist_ids, market))