31 lines
658 B
Python
31 lines
658 B
Python
|
|
"""Common Pydantic schemas: pagination."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Generic, List, Optional, TypeVar
|
||
|
|
|
||
|
|
from pydantic import BaseModel, ConfigDict, Field
|
||
|
|
|
||
|
|
T = TypeVar("T")
|
||
|
|
|
||
|
|
|
||
|
|
class PaginationParams(BaseModel):
|
||
|
|
"""Standard pagination query params."""
|
||
|
|
|
||
|
|
skip: int = Field(default=0, ge=0)
|
||
|
|
limit: int = Field(default=20, ge=1, le=100)
|
||
|
|
|
||
|
|
|
||
|
|
class PaginatedResponse(BaseModel, Generic[T]):
|
||
|
|
"""Generic paginated response."""
|
||
|
|
|
||
|
|
model_config = ConfigDict(from_attributes=True)
|
||
|
|
|
||
|
|
items: List[T] # type: ignore[valid-type]
|
||
|
|
total: int
|
||
|
|
skip: int
|
||
|
|
limit: int
|
||
|
|
|
||
|
|
|
||
|
|
__all__ = ["PaginatedResponse", "PaginationParams"]
|