from typing import Annotated, Any from anydi.ext.fastapi import Inject from fastapi import APIRouter, Query from dmp.api.auth import IdentityId from dmp.api.rosters.schemas import ( FanDataList, FanDataListDetail, GetCustomListsInput, GetLocalRepCountriesInput, GetRostersInput, SearchRostersInput, SearchRostersOutput, ) from dmp.api.schemas import LimitOffsetPage from dmp.rosters.handlers import ( GetCustomListsHandler, GetCustomListsRequest, GetLocalRepCountriesHandler, GetLocalRepCountriesRequest, GetRostersHandler, GetRostersRequest, SearchRostersHandler, SearchRostersRequest, ) router = APIRouter(tags=["Rosters"]) @router.get( "/rosters", operation_id="getRosters", response_model=LimitOffsetPage[FanDataListDetail], response_model_by_alias=True, ) def get_rosters( identity_id: IdentityId, params: Annotated[GetRostersInput, Query()], handler: Annotated[GetRostersHandler, Inject()], ) -> Any: limit = params.limit or GetRostersRequest.DEFAULT_LIMIT offset = params.offset or GetRostersRequest.DEFAULT_OFFSET order_by = params.order_by or GetRostersRequest.DEFAULT_ORDER_BY response = handler.handle( GetRostersRequest( identity_id=identity_id, vendor_id=params.vendor_id, subaccount_id=params.subaccount_id, countries=params.countries, search=params.search, exclude_local_reps=params.exclude_local_reps, order_by=order_by, limit=limit, offset=offset, ) ) return LimitOffsetPage( items=response.items, total=response.total, limit=limit, offset=offset, ) @router.get( "/rosters/search", operation_id="searchRosters", response_model=SearchRostersOutput, response_model_by_alias=True, ) def search_rosters( identity_id: IdentityId, params: Annotated[SearchRostersInput, Query()], handler: Annotated[SearchRostersHandler, Inject()], ) -> Any: return handler.handle( SearchRostersRequest( identity_id=identity_id, vendor_id=params.vendor_id, subaccount_id=params.subaccount_id, search=params.search, exclude_local_reps=params.exclude_local_reps, limit=params.limit or SearchRostersRequest.DEFAULT_LIMIT, ) ) @router.get( "/rosters/custom-lists", operation_id="getCustomLists", response_model=list[FanDataList], response_model_by_alias=True, ) def get_custom_lists( identity_id: IdentityId, params: Annotated[GetCustomListsInput, Query()], handler: Annotated[GetCustomListsHandler, Inject()], ) -> Any: return handler.handle( GetCustomListsRequest( identity_id=identity_id, custom_list_ids=params.custom_list_ids, ) ) @router.get( "/rosters/local-rep-countries", operation_id="getLocalRepCountries", response_model=list[str], ) def get_local_rep_countries( identity_id: IdentityId, params: Annotated[GetLocalRepCountriesInput, Query()], handler: Annotated[GetLocalRepCountriesHandler, Inject()], ) -> Any: return handler.handle( GetLocalRepCountriesRequest( identity_id=identity_id, vendor_id=params.vendor_id, subaccount_id=params.subaccount_id, global_participant_ids=params.global_participant_ids, ) )