From 7f9c0ac12dd119f1ecdf82cbc6d69292225d8836 Mon Sep 17 00:00:00 2001 From: yupix Date: Sat, 3 Feb 2024 01:26:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20get=5Finvite=5Flist=20=E3=82=92=20all?= =?UTF-8?q?=E7=89=88=E3=81=A8=E3=81=A7=E5=88=86=E3=81=91=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mipac/actions/admins/invite.py | 42 +++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/mipac/actions/admins/invite.py b/mipac/actions/admins/invite.py index 2aab0ab..3236d4d 100644 --- a/mipac/actions/admins/invite.py +++ b/mipac/actions/admins/invite.py @@ -34,20 +34,46 @@ class AdminInviteActions(AbstractAction): offset: int = 0, type: Literal["unused", "used", "expired", "all"] = "all", sort: Literal["+createdAt", "-createdAt", "+usedAt", "-usedAt"] = "+createdAt", - *, - get_all: bool = False, - ) -> AsyncGenerator[InviteCode, None]: + ) -> list[InviteCode]: + body = remove_dict_empty( + { + "limit": limit, + "offset": offset, + "type": type, + "sort": sort, + } + ) + + res: list[IInviteCode] = await self._session.request( + Route("POST", "/api/admin/invite/list"), json=body, auth=True + ) + + return [InviteCode(raw_invite_code, client=self.__client) for raw_invite_code in res] + + async def get_all_invite_list( + self, + limit: int = 30, + offset: int = 0, + type: Literal["unused", "used", "expired", "all"] = "all", + sort: Literal["+createdAt", "-createdAt", "+usedAt", "-usedAt"] = "+createdAt", + ): + body = remove_dict_empty( + { + "limit": limit, + "offset": offset, + "type": type, + "sort": sort, + } + ) + pagination = Pagination[IInviteCode]( http_client=self.__session, route=Route("POST", "/api/admin/invite/list"), - json=remove_dict_empty({"limit": limit, "offset": offset, "type": type, "sort": sort}), + json=body, pagination_type="count", auth=True, ) - while True: + while pagination.is_final is False: raw_invite_codes = await pagination.next() for raw_invite_code in raw_invite_codes: yield InviteCode(raw_invite_code, client=self.__client) - - if pagination.is_final or get_all is False: - break