Coverage for src/kwai/modules/portal/repositories/author_repository.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2024-01-01 00:00 +0000

1"""Module that defines an interface for an Author repository.""" 

2 

3from abc import ABC, abstractmethod 

4from typing import AsyncGenerator 

5 

6from kwai.core.domain.value_objects.unique_id import UniqueId 

7from kwai.modules.portal.domain.author import AuthorEntity, AuthorIdentifier 

8from kwai.modules.portal.repositories.author_query import AuthorQuery 

9 

10 

11class AuthorNotFoundException(Exception): 

12 """Raised when an author cannot be found.""" 

13 

14 

15class AuthorRepository(ABC): 

16 """An interface for an author repository.""" 

17 

18 @abstractmethod 

19 def create_query(self) -> AuthorQuery: 

20 """Create a query for quering authors.""" 

21 raise NotImplementedError 

22 

23 @abstractmethod 

24 async def get(self, id: AuthorIdentifier) -> AuthorEntity: 

25 """Get the author with the given user identifier.""" 

26 raise NotImplementedError 

27 

28 @abstractmethod 

29 async def get_by_uuid(self, uuid: UniqueId) -> AuthorEntity: 

30 """Get the author that is linked to the user with the given uuid.""" 

31 raise NotImplementedError 

32 

33 @abstractmethod 

34 def get_all( 

35 self, query: AuthorQuery | None = None, limit: int = 0, offset: int = 0 

36 ) -> AsyncGenerator[AuthorEntity, None]: 

37 """Yield all authors of a given query. 

38 

39 Args: 

40 query: The query to use for selecting the authors. 

41 limit: The maximum number of entities to return. 

42 offset: Skip the offset rows before beginning to return entities. 

43 """ 

44 raise NotImplementedError 

45 

46 @abstractmethod 

47 async def create(self, author: AuthorEntity) -> AuthorEntity: 

48 """Save an author entity to the database.""" 

49 raise NotImplementedError 

50 

51 @abstractmethod 

52 async def delete(self, author: AuthorEntity) -> None: 

53 """Delete an author entity from the dabase.""" 

54 raise NotImplementedError