from aiohttp import web from aiohttp_apispec import docs, querystring_schema from apollo_utils.core.constants.market import Market from server.client import services from server.constants import BASE_API_PREFIX, DSP from server.scenarios.playlists.amazon.streams_graph import get_amazon_streams_graph_with_worldwide from server.schemas.playlists.streams_graph import PlaylistStreamsGraph from server.utils.response import dump_response_schema router = web.RouteTableDef() @router.get(BASE_API_PREFIX + "/v1/playlists/streams/graph/") @docs(tags=["amazon", "markets"], summary="Get Playlist streams graph by playlist_id for provided period") @querystring_schema(PlaylistStreamsGraph.Request) @dump_response_schema(PlaylistStreamsGraph.Response(many=True), apply=False) async def get(request: web.Request): params = request["querystring"] if DSP.AMAZON.value == params["vendor"] and Market.WORLDWIDE in params["markets"]: return await get_amazon_streams_graph_with_worldwide(**params) return await services.dsp.get_v1_playlists_streams_graph(**params)