Coverage for kwai/modules/portal/get_applications.py: 85%
20 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
1"""Module that defines the use case: get all applications for a portal."""
2from dataclasses import dataclass
4from kwai.modules.portal.applications.application_repository import (
5 ApplicationRepository,
6)
9@dataclass(kw_only=True, frozen=True, slots=True)
10class GetApplicationsCommand:
11 """Input for the use case [GetApplications][kwai.modules.portal.get_applications.GetApplications].
13 Attributes:
14 name: Only return the application with the given name
15 news: Only return applications that can contain news
16 events: Only return applications that can contain events
17 pages: Only return applications that can contain pages
18 """
20 name: str = ""
21 news: bool = False
22 events: bool = False
23 pages: bool = False
26class GetApplications:
27 """Implements the use case 'get applications'."""
29 def __init__(self, application_repo: ApplicationRepository):
30 """Initialize the use case.
32 Args:
33 application_repo: A repository for getting applications.
34 """
35 self._application_repo = application_repo
37 async def execute(self, command: GetApplicationsCommand):
38 """Execute the use case.
40 Args:
41 command: The input for this use case.
42 """
43 query = self._application_repo.create_query()
44 if command.events:
45 query.filter_only_events()
46 if command.news:
47 query.filter_only_news()
48 if command.pages:
49 query.filter_only_pages()
51 return await query.count(), self._application_repo.get_all(query)