from dataclasses import dataclass from anydi import singleton from fansifter_common.auth.requests import AuthRequest from fansifter_common.auth.services import AuthService from fansifter_common.auth.types import Permission from dmp.shopify.dtos import ShopifyStoreArtist from dmp.shopify.repositories import StoreArtistRepository from dmp.shopify.services import StoreAssociationService @dataclass class GetStoreArtistsRequest(AuthRequest): association_id: str @singleton class GetStoreArtistsHandler: permission = Permission("fan_data_channel", "view") def __init__( self, auth_service: AuthService, store_association_service: StoreAssociationService, store_artist_repository: StoreArtistRepository, ) -> None: self.auth_service = auth_service self.store_association_service = store_association_service self.store_artist_repository = store_artist_repository def handle(self, request: GetStoreArtistsRequest) -> list[ShopifyStoreArtist]: store = self.store_association_service.get_store(request.association_id) self.auth_service.check_account_resource( request.identity_id, account=store.account, permission=self.permission, resource_id=store.id, ) if store.is_single_artist_store and store.global_participant_id: return [ ShopifyStoreArtist( global_participant_id=store.global_participant_id, collections_count=store.collections_count or 0, products_count=store.products_count or 0, ) ] return self.store_artist_repository.count_per_artist_by_association_id( association_id=request.association_id )