Coverage for src/kwai/modules/portal/applications/application_repository.py: 100%
6 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module that defines an interface for an application repository."""
3from abc import ABC, abstractmethod
4from typing import AsyncIterator
6from kwai.modules.portal.applications.application import (
7 ApplicationEntity,
8 ApplicationIdentifier,
9)
10from kwai.modules.portal.applications.application_query import ApplicationQuery
13class ApplicationNotFoundException(Exception):
14 """Raised when the application can not be found."""
17class ApplicationRepository(ABC):
18 """An application repository interface."""
20 @abstractmethod
21 def create_query(self) -> ApplicationQuery:
22 """Create a query for querying applications."""
23 raise NotImplementedError
25 @abstractmethod
26 async def get_by_id(self, id_: ApplicationIdentifier) -> ApplicationEntity:
27 """Get the application with the given id.
29 Args:
30 id_: The id of the application.
32 Returns:
33 An application entity.
35 Raises:
36 ApplicationNotFoundException: when the application does not exist.
37 """
38 raise NotImplementedError
40 @abstractmethod
41 async def get_by_name(self, name: str) -> ApplicationEntity:
42 """Get the application with the given name.
44 Args:
45 name: The name of the application.
47 Returns:
48 An application entity.
50 Raises:
51 ApplicationNotFoundException: when the application with the given name
52 does not exist.
53 """
54 raise NotImplementedError
56 @abstractmethod
57 async def get_all(
58 self,
59 query: ApplicationQuery | None = None,
60 limit: int | None = None,
61 offset: int | None = None,
62 ) -> AsyncIterator[ApplicationEntity]:
63 """Return all applications of a given query.
65 Args:
66 query: The query to use for selecting the rows.
67 limit: The maximum number of entities to return.
68 offset: Skip the offset rows before beginning to return entities.
70 Yields:
71 A list of applications.
72 """
73 raise NotImplementedError
75 @abstractmethod
76 async def create(self, application: ApplicationEntity) -> ApplicationEntity:
77 """Create a new application entity.
79 Args:
80 application: The application to create.
81 """
82 raise NotImplementedError
84 @abstractmethod
85 async def update(self, application: ApplicationEntity):
86 """Update an application entity.
88 Args:
89 application: The application to update.
90 """
91 raise NotImplementedError
93 @abstractmethod
94 async def delete(self, application: ApplicationEntity):
95 """Delete an application entity.
97 Args:
98 application: The application to delete.
99 """
100 raise NotImplementedError