From ac4168adb162d5c0a6f8be65b8a8a228a4732d75 Mon Sep 17 00:00:00 2001 From: Georg Krause <mail@georg-krause.net> Date: Tue, 27 Sep 2022 13:39:00 +0200 Subject: [PATCH] Fix all subscriptions --- .../subscriptions_all_retrieve.py | 24 +++--- funkwhale_api_client/models/__init__.py | 2 + .../models/all_subscriptions.py | 76 +++++++++++++++++++ .../models/inline_subscription.py | 64 ++++++++++++++++ tests/unit/test_model_subscription.py | 5 +- 5 files changed, 157 insertions(+), 14 deletions(-) create mode 100644 funkwhale_api_client/models/all_subscriptions.py create mode 100644 funkwhale_api_client/models/inline_subscription.py diff --git a/funkwhale_api_client/api/subscriptions/subscriptions_all_retrieve.py b/funkwhale_api_client/api/subscriptions/subscriptions_all_retrieve.py index 3651d25..286ff73 100644 --- a/funkwhale_api_client/api/subscriptions/subscriptions_all_retrieve.py +++ b/funkwhale_api_client/api/subscriptions/subscriptions_all_retrieve.py @@ -3,7 +3,7 @@ from typing import Any, Dict, Optional import httpx from ...client import AuthenticatedClient -from ...models.subscription import Subscription +from ...models.all_subscriptions import AllSubscriptions from ...types import Response @@ -25,15 +25,15 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Subscription]: +def _parse_response(*, response: httpx.Response) -> Optional[AllSubscriptions]: if response.status_code == 200: - response_200 = Subscription.from_dict(response.json()) + response_200 = AllSubscriptions.from_dict(response.json()) return response_200 return None -def _build_response(*, response: httpx.Response) -> Response[Subscription]: +def _build_response(*, response: httpx.Response) -> Response[AllSubscriptions]: return Response( status_code=response.status_code, content=response.content, @@ -45,13 +45,13 @@ def _build_response(*, response: httpx.Response) -> Response[Subscription]: def sync_detailed( *, client: AuthenticatedClient, -) -> Response[Subscription]: +) -> Response[AllSubscriptions]: """Return all the subscriptions of the current user, with only limited data to have a performant endpoint and avoid lots of queries just to display subscription status in the UI Returns: - Response[Subscription] + Response[AllSubscriptions] """ kwargs = _get_kwargs( @@ -69,13 +69,13 @@ def sync_detailed( def sync( *, client: AuthenticatedClient, -) -> Optional[Subscription]: +) -> Optional[AllSubscriptions]: """Return all the subscriptions of the current user, with only limited data to have a performant endpoint and avoid lots of queries just to display subscription status in the UI Returns: - Response[Subscription] + Response[AllSubscriptions] """ return sync_detailed( @@ -86,13 +86,13 @@ def sync( async def asyncio_detailed( *, client: AuthenticatedClient, -) -> Response[Subscription]: +) -> Response[AllSubscriptions]: """Return all the subscriptions of the current user, with only limited data to have a performant endpoint and avoid lots of queries just to display subscription status in the UI Returns: - Response[Subscription] + Response[AllSubscriptions] """ kwargs = _get_kwargs( @@ -108,13 +108,13 @@ async def asyncio_detailed( async def asyncio( *, client: AuthenticatedClient, -) -> Optional[Subscription]: +) -> Optional[AllSubscriptions]: """Return all the subscriptions of the current user, with only limited data to have a performant endpoint and avoid lots of queries just to display subscription status in the UI Returns: - Response[Subscription] + Response[AllSubscriptions] """ return ( diff --git a/funkwhale_api_client/models/__init__.py b/funkwhale_api_client/models/__init__.py index 50a944d..11420e6 100644 --- a/funkwhale_api_client/models/__init__.py +++ b/funkwhale_api_client/models/__init__.py @@ -13,6 +13,7 @@ from .album_create_request import AlbumCreateRequest from .album_request import AlbumRequest from .albums_list_ordering_item import AlbumsListOrderingItem from .all_favorite import AllFavorite +from .all_subscriptions import AllSubscriptions from .allow_list_stat import AllowListStat from .api_actor import APIActor from .api_actor_request import APIActorRequest @@ -65,6 +66,7 @@ from .inbox_item_request import InboxItemRequest from .inbox_item_type_enum import InboxItemTypeEnum from .inline_actor import InlineActor from .inline_actor_request import InlineActorRequest +from .inline_subscription import InlineSubscription from .libraries_list_privacy_level import LibrariesListPrivacyLevel from .library import Library from .library_follow import LibraryFollow diff --git a/funkwhale_api_client/models/all_subscriptions.py b/funkwhale_api_client/models/all_subscriptions.py new file mode 100644 index 0000000..f47f3fc --- /dev/null +++ b/funkwhale_api_client/models/all_subscriptions.py @@ -0,0 +1,76 @@ +from typing import Any, Dict, List, Type, TypeVar + +import attr + +from ..models.inline_subscription import InlineSubscription + +T = TypeVar("T", bound="AllSubscriptions") + + +@attr.s(auto_attribs=True) +class AllSubscriptions: + """ + Attributes: + results (List[InlineSubscription]): + count (int): + """ + + results: List[InlineSubscription] + count: int + additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + results = [] + for results_item_data in self.results: + results_item = results_item_data.to_dict() + + results.append(results_item) + + count = self.count + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "results": results, + "count": count, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + results = [] + _results = d.pop("results") + for results_item_data in _results: + results_item = InlineSubscription.from_dict(results_item_data) + + results.append(results_item) + + count = d.pop("count") + + all_subscriptions = cls( + results=results, + count=count, + ) + + all_subscriptions.additional_properties = d + return all_subscriptions + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/funkwhale_api_client/models/inline_subscription.py b/funkwhale_api_client/models/inline_subscription.py new file mode 100644 index 0000000..61a14c9 --- /dev/null +++ b/funkwhale_api_client/models/inline_subscription.py @@ -0,0 +1,64 @@ +from typing import Any, Dict, List, Type, TypeVar + +import attr + +T = TypeVar("T", bound="InlineSubscription") + + +@attr.s(auto_attribs=True) +class InlineSubscription: + """ + Attributes: + uuid (str): + channel (str): + """ + + uuid: str + channel: str + additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + uuid = self.uuid + channel = self.channel + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "uuid": uuid, + "channel": channel, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + uuid = d.pop("uuid") + + channel = d.pop("channel") + + inline_subscription = cls( + uuid=uuid, + channel=channel, + ) + + inline_subscription.additional_properties = d + return inline_subscription + + @property + def additional_keys(self) -> List[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/tests/unit/test_model_subscription.py b/tests/unit/test_model_subscription.py index be2dbf3..ab017ac 100644 --- a/tests/unit/test_model_subscription.py +++ b/tests/unit/test_model_subscription.py @@ -1,4 +1,5 @@ from funkwhale_api_client.models.subscription import Subscription +from funkwhale_api_client.models.all_subscriptions import AllSubscriptions def test_Subscription(load_data): @@ -10,6 +11,6 @@ def test_Subscription(load_data): def test_SubscriptionAll(load_data): response = load_data("subscription_all") - subscription_all: Subscription = Subscription.from_dict(response) + subscription_all: AllSubscriptions = AllSubscriptions.from_dict(response) - assert isinstance(subscription_all, Subscription) + assert isinstance(subscription_all, AllSubscriptions) -- GitLab