44 lines
901 B
Python
44 lines
901 B
Python
"""Common shared schemas."""
|
|||
|
|
from typing import Optional, Any, List, Generic, TypeVar
|
||
|
|
from pydantic import BaseModel
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
T = TypeVar("T")
|
||
|
|
|
||
|
|
|
||
|
|
class PaginatedResponse(BaseModel, Generic[T]):
|
||
|
|
"""Generic paginated response wrapper."""
|
||
|
|
items: List[T]
|
||
|
|
total: int
|
||
|
|
page: int = 1
|
||
|
|
page_size: int = 20
|
||
|
|
|
||
|
|
|
||
|
|
class SuccessResponse(BaseModel):
|
||
|
|
"""Simple success response."""
|
||
|
|
success: bool = True
|
||
|
|
message: str = ""
|
||
|
|
data: Optional[Any] = None
|
||
|
|
|
||
|
|
|
||
|
|
class TokenResponse(BaseModel):
|
||
|
|
"""JWT token response."""
|
||
|
|
access_token: str
|
||
|
|
token_type: str = "bearer"
|
||
|
|
user: "UserBrief"
|
||
|
|
|
||
|
|
|
||
|
|
class UserBrief(BaseModel):
|
||
|
|
"""Brief user info embedded in responses."""
|
||
|
|
id: int
|
||
|
|
username: str
|
||
|
|
email: str
|
||
|
|
role: str
|
||
|
|
user_type: str
|
||
|
|
tenant_id: int
|
||
|
|
|
||
|
|
model_config = {"from_attributes": True}
|
||
|
|
|
||
|
|
|
||
|
|
# Update forward refs
|
||
|
|
TokenResponse.model_rebuild()
|