from dataclasses import dataclass from anydi import singleton from pydantic import TypeAdapter from dmp.adapters.db import ReportingDB from dmp.artists.dtos import Label LabelValidator = TypeAdapter(list[Label]) @dataclass class GetArtistAccountsAllRequest: global_participant_id: str @singleton class GetArtistAccountsAllHandler: def __init__( self, db: ReportingDB, ) -> None: self.db = db def handle(self, request: GetArtistAccountsAllRequest) -> list[Label]: return self._get_artist_accounts_all(request.global_participant_id) def _get_artist_accounts_all(self, global_participant_id: str) -> list[Label]: query = self.db.query_from_template( "artist/get-accounts-all.sql", context={ "global_participant_id": global_participant_id, }, ) return LabelValidator.validate_python( self.db.session.execute(query).mappings(), )