2026-06-03 21:40:26 +00:00
|
|
|
"""Common Pydantic schemas: pagination."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-06-10 20:52:56 +00:00
|
|
|
from typing import Generic, TypeVar
|
2026-06-03 21:40:26 +00:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2026-06-10 20:52:56 +00:00
|
|
|
items: list[T] # type: ignore[valid-type]
|
2026-06-03 21:40:26 +00:00
|
|
|
total: int
|
|
|
|
|
skip: int
|
|
|
|
|
limit: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = ["PaginatedResponse", "PaginationParams"]
|