Coverage for kwai/modules/portal/applications/application_repository.py: 100%
6 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 an interface for an application repository."""
2from abc import ABC, abstractmethod
3from typing import AsyncIterator
5from kwai.modules.portal.applications.application import (
6 ApplicationEntity,
7 ApplicationIdentifier,
8)
9from kwai.modules.portal.applications.application_query import ApplicationQuery
12class ApplicationNotFoundException(Exception):
13 """Raised when the application can not be found."""
16class ApplicationRepository(ABC):
17 """An application repository interface."""
19 @abstractmethod
20 def create_query(self) -> ApplicationQuery:
21 """Create a query for querying applications."""
22 raise NotImplementedError
24 @abstractmethod
25 async def get_by_id(self, id_: ApplicationIdentifier) -> ApplicationEntity:
26 """Get the application with the given id.
28 Args:
29 id_: The id of the application.
31 Returns:
32 An application entity.
34 Raises:
35 ApplicationNotFoundException: when the application does not exist.
36 """
37 raise NotImplementedError
39 @abstractmethod
40 async def get_by_name(self, name: str) -> ApplicationEntity:
41 """Get the application with the given name.
43 Args:
44 name: The name of the application.
46 Returns:
47 An application entity.
49 Raises:
50 ApplicationNotFoundException: when the application with the given name
51 does not exist.
52 """
53 raise NotImplementedError
55 @abstractmethod
56 async def get_all(
57 self,
58 query: ApplicationQuery | None = None,
59 limit: int | None = None,
60 offset: int | None = None,
61 ) -> AsyncIterator[ApplicationEntity]:
62 """Return all applications of a given query.
64 Args:
65 query: The query to use for selecting the rows.
66 limit: The maximum number of entities to return.
67 offset: Skip the offset rows before beginning to return entities.
69 Yields:
70 A list of applications.
71 """
72 raise NotImplementedError
74 @abstractmethod
75 async def create(self, application: ApplicationEntity) -> ApplicationEntity:
76 """Create a new application entity.
78 Args:
79 application: The application to create.
80 """
81 raise NotImplementedError
83 @abstractmethod
84 async def update(self, application: ApplicationEntity):
85 """Update an application entity.
87 Args:
88 application: The application to update.
89 """
90 raise NotImplementedError
92 @abstractmethod
93 async def delete(self, application: ApplicationEntity):
94 """Delete an application entity.
96 Args:
97 application: The application to delete.
98 """
99 raise NotImplementedError