Coverage for src/kwai/modules/portal/pages/page_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 a page repository."""
3from abc import ABC, abstractmethod
4from typing import AsyncIterator
6from kwai.modules.portal.pages.page import PageEntity, PageIdentifier
7from kwai.modules.portal.pages.page_query import PageQuery
10class PageNotFoundException(Exception):
11 """Raised when a page can not be found."""
14class PageRepository(ABC):
15 """Interface for a page repository."""
17 @abstractmethod
18 async def create(self, page: PageEntity) -> PageEntity:
19 """Create a new page entity.
21 Args:
22 page: The page to create.
24 Returns:
25 The page entity with an identifier.
26 """
27 raise NotImplementedError
29 @abstractmethod
30 async def update(self, page: PageEntity):
31 """Update a page entity.
33 Args:
34 page: The page to update.
35 """
36 raise NotImplementedError
38 @abstractmethod
39 async def delete(self, page: PageEntity):
40 """Delete a page.
42 Args:
43 page: The page to delete.
44 """
45 raise NotImplementedError
47 @abstractmethod
48 def create_query(self) -> PageQuery:
49 """Create a query for querying pages."""
50 raise NotImplementedError
52 @abstractmethod
53 async def get_by_id(self, id_: PageIdentifier) -> PageEntity:
54 """Get the page with the given id.
56 Args:
57 id_: The id of the page.
59 Returns:
60 A page entity.
61 """
62 raise NotImplementedError
64 @abstractmethod
65 async def get_all(
66 self,
67 query: PageQuery | None = None,
68 limit: int | None = None,
69 offset: int | None = None,
70 ) -> AsyncIterator[PageEntity]:
71 """Return all pages of a given query.
73 Args:
74 query: The query to use for selecting the rows.
75 limit: The maximum number of entities to return.
76 offset: Skip the offset rows before beginning to return entities.
78 Yields:
79 A list of pages.
80 """
81 raise NotImplementedError