initial working state
This commit is contained in:
parent
816fb34f75
commit
bb9a24c1ed
15 changed files with 688 additions and 0 deletions
41
src/synclean/models/pagination.py
Normal file
41
src/synclean/models/pagination.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import Optional, Dict, Any, TypeVar, Generic
|
||||
from synclean.models.enums import RoomOrderBy, Direction, UserOrderBy
|
||||
|
||||
OrderByType = TypeVar("OrderByType")
|
||||
|
||||
|
||||
@dataclass
|
||||
class PaginationParams(Generic[OrderByType]):
|
||||
"""Parameters for pagination."""
|
||||
limit: int = 100
|
||||
offset: int = 0
|
||||
order_by: OrderByType = None
|
||||
direction: Direction = Direction.FORWARD
|
||||
search_term: Optional[str] = None
|
||||
|
||||
def to_query_params(self) -> Dict[str, Any]:
|
||||
"""Convert to query parameters for API request."""
|
||||
params = {
|
||||
'limit': self.limit,
|
||||
'from': self.offset,
|
||||
'order_by': self.order_by.value,
|
||||
'dir': self.direction.value
|
||||
}
|
||||
|
||||
if self.search_term:
|
||||
params['search_term'] = self.search_term
|
||||
|
||||
return params
|
||||
|
||||
|
||||
@dataclass
|
||||
class RoomPaginationParams(PaginationParams[RoomOrderBy]):
|
||||
"""Pagination parameters for rooms."""
|
||||
order_by = RoomOrderBy = RoomOrderBy.NAME
|
||||
|
||||
|
||||
@dataclass
|
||||
class UserPaginationParams(PaginationParams[UserOrderBy]):
|
||||
"""Pagination parameters for users."""
|
||||
order_by = UserOrderBy = UserOrderBy.MEDIA_LENGTH
|
Loading…
Add table
Add a link
Reference in a new issue