41 lines
No EOL
1.1 KiB
Python
41 lines
No EOL
1.1 KiB
Python
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 |