You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
936 B
48 lines
936 B
"""
|
|
基础Schema
|
|
"""
|
|
from datetime import datetime
|
|
from typing import Optional, TypeVar, Generic, List
|
|
from pydantic import BaseModel
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
class ResponseModel(BaseModel, Generic[T]):
|
|
"""统一响应模型"""
|
|
code: int = 200
|
|
message: str = "success"
|
|
data: Optional[T] = None
|
|
timestamp: datetime = datetime.utcnow()
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class PaginationParams(BaseModel):
|
|
"""分页参数"""
|
|
page: int = 1
|
|
page_size: int = 20
|
|
|
|
|
|
class PaginatedData(BaseModel, Generic[T]):
|
|
"""分页数据"""
|
|
items: List[T]
|
|
total: int
|
|
page: int
|
|
page_size: int
|
|
total_pages: int
|
|
|
|
|
|
class PaginatedResponse(ResponseModel[PaginatedData[T]], Generic[T]):
|
|
"""分页响应模型"""
|
|
pass
|
|
|
|
|
|
class ErrorResponse(BaseModel):
|
|
"""错误响应"""
|
|
code: int
|
|
message: str
|
|
data: Optional[dict] = None
|
|
timestamp: datetime = datetime.utcnow()
|