from collections.abc import Sequence from dataclasses import dataclass from anydi import singleton from fansifter_common.identifiers.types import ProfileToken from preference_center.profile.models import Subscription from preference_center.profile.services import ProfileService @dataclass class GetSubscriptionsRequest: token: ProfileToken @singleton class GetSubscriptionsHandler: def __init__(self, profile_service: ProfileService) -> None: self.profile_service = profile_service def handle(self, request: GetSubscriptionsRequest) -> Sequence[Subscription]: identifier = self.profile_service.decode_profile_identifier(request.token) profile = self.profile_service.get_profile_by_identifier_cached(identifier) return self.profile_service.get_subscriptions_cached(profile.id)