Coverage for fss\common\service\service.py: 70%
50 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-11 19:09 +0800
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-11 19:09 +0800
1"""Abstract Service used in the project"""
3from abc import ABC, abstractmethod
4from typing import Any, List, TypeVar, Generic
6T = TypeVar("T", bound=Any)
7DEFAULT_BATCH_SIZE: int = 1000
10class Service(Generic[T], ABC):
11 @abstractmethod
12 async def save(self, *, data: T) -> bool:
13 raise NotImplementedError
15 @abstractmethod
16 async def save_or_update(self, *, data: T) -> bool:
17 raise NotImplementedError
19 @abstractmethod
20 async def save_batch(self, *, data_list: List[T]) -> bool:
21 raise NotImplementedError
23 @abstractmethod
24 async def save_or_update_batch(self, *, data_list: List[T]) -> bool:
25 raise NotImplementedError
27 @abstractmethod
28 async def get_by_id(self, *, id: T) -> T:
29 raise NotImplementedError
31 @abstractmethod
32 async def get_by_ids(self, *, ids: List[T], batch_size: int) -> List[Any]:
33 raise NotImplementedError
35 @abstractmethod
36 async def count(
37 self,
38 ) -> int:
39 raise NotImplementedError
41 @abstractmethod
42 async def list(self, *, page: int, size: int, query: T) -> List[T]:
43 raise NotImplementedError
45 @abstractmethod
46 async def list_ordered(
47 self, *, page: int, size: int, query: T, order_by: T, sort_order: T
48 ) -> List[T]:
49 raise NotImplementedError
51 @abstractmethod
52 async def list_page(self, *, params: T, query: T) -> List[T]:
53 raise NotImplementedError
55 @abstractmethod
56 async def list_page_ordered(self, *, params: T, query: T, sort_order: T) -> List[T]:
57 raise NotImplementedError
59 @abstractmethod
60 async def update_by_id(self, *, data: T) -> bool:
61 raise NotImplementedError
63 @abstractmethod
64 async def update_batch_by_ids(self, *, data_list: List[T]) -> bool:
65 raise NotImplementedError
67 @abstractmethod
68 async def remove_by_id(self, *, id: T) -> bool:
69 raise NotImplementedError
71 @abstractmethod
72 async def remove_batch_by_ids(self, *, ids: List[Any]) -> bool:
73 raise NotImplementedError