from aiohttp import web from aiohttp_apispec import docs, querystring_schema from server.constants import BASE_API_PREFIX, DSP from server.constants.playlists.meta import PlaylistMetaApolloInclude from server.scenarios.playlists.get_playlist_meta.common import get_meta_playlists_info from server.schemas.playlists.apple.get_meta import V1PlaylistApple, V1PlaylistsAppleInfo from server.utils.response import dump_response_schema router = web.RouteTableDef() @router.get(BASE_API_PREFIX + "/v1/playlists/apple/info/") @docs( tags=["playlists", "apple"], summary="Get general Apple playlist's info.", ) @querystring_schema(V1PlaylistsAppleInfo.Request) @dump_response_schema(V1PlaylistsAppleInfo.Response(many=True), apply=False) async def get(request: web.Request) -> web.Response: params = request["querystring"] playlist_ids, country_code, image_size = params["playlist_ids"], params["country_code"], params["image_size"] meta = await get_meta_playlists_info( playlist_ids, dsp=DSP.APPLE, country_code=country_code, apollo_include=[PlaylistMetaApolloInclude.PLAYLIST_DATES_FULL.value], ) return V1PlaylistsAppleInfo.Response(many=True, context={"image_size": image_size}).dump(meta) @router.get(BASE_API_PREFIX + "/v1/playlists/apple/") @docs( tags=["playlist", "apple"], summary="Get apple playlists by ids.", ) @querystring_schema(V1PlaylistApple.Request) @dump_response_schema(V1PlaylistApple.Response) async def get(request: web.Request) -> web.Response: params = request["querystring"] playlist_ids, country_code = params["playlist_id"], params["country"] meta = await get_meta_playlists_info( playlist_ids, dsp=DSP.APPLE, country_code=country_code, apollo_include=[PlaylistMetaApolloInclude.PLAYLIST_DATES_FULL.value], ) return meta[0] if meta else {}