schemas.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """请求 / 响应 Pydantic 模型。
  2. 注意:所有响应都使用 app/response.py 中的 ApiResponse 信封包裹,
  3. 本文件仅定义 data 字段内的业务数据结构。
  4. """
  5. from typing import Any
  6. from pydantic import BaseModel, Field
  7. class SearchRequest(BaseModel):
  8. """搜索请求体(POST 用)。"""
  9. query: str = Field(..., min_length=1, description="搜索关键词")
  10. locale: str | None = Field(default="en-us", description="语言代码,留空使用默认")
  11. page: int = Field(default=1, ge=1)
  12. per_page: int = Field(default=25, ge=1, le=100)
  13. class SearchData(BaseModel):
  14. """搜索响应数据(放入 ApiResponse.data 字段)。"""
  15. count: int
  16. page: int
  17. per_page: int
  18. is_next_page: bool
  19. results: list[dict[str, Any]]
  20. class CacheStatus(BaseModel):
  21. """缓存状态(放入 ApiResponse.data 字段)。"""
  22. sec_ids_count: int
  23. last_updated_at: str | None
  24. next_refresh_at: str | None
  25. class CacheRefreshResult(BaseModel):
  26. """手动刷新缓存的返回数据。"""
  27. sec_ids_count: int
  28. last_updated_at: str | None