Files
video/schema/face_schema.py

41 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from datetime import datetime
from pydantic import BaseModel, Field
from typing import List, Optional
# ------------------------------
# 请求模型(前端传参校验)- 保留update的eigenvalue如需更新特征值
# ------------------------------
class FaceCreateRequest(BaseModel):
"""创建人脸记录请求模型无需ID、由数据库自增"""
name: Optional[str] = Field(None, max_length=255, description="名称可选、最长255字符")
class FaceUpdateRequest(BaseModel):
"""更新人脸记录请求模型 - 保留eigenvalue如需更新特征值不影响返回"""
name: Optional[str] = Field(None, max_length=255, description="名称(可选)")
eigenvalue: Optional[str] = Field(None, description="特征值(可选,文件处理后可更新)") # 保留更新能力
address: Optional[str] = Field(None, description="图片完整路径(可选,更新图片时使用)")
# ------------------------------
# 响应模型(后端返回数据)- 核心修改删除eigenvalue字段
# ------------------------------
class FaceResponse(BaseModel):
"""人脸记录响应模型仅返回需要的字段移除eigenvalue"""
id: int = Field(..., description="主键ID数据库自增")
name: Optional[str] = Field(None, description="名称")
address: Optional[str] = Field(None, description="人脸图片完整保存路径(数据库新增字段)") # 仅保留address
created_at: datetime = Field(..., description="记录创建时间(数据库自动生成)")
updated_at: datetime = Field(..., description="记录更新时间(数据库自动生成)")
# 关键配置:支持从数据库查询结果(字典)直接转换
model_config = {"from_attributes": True}
class FaceListResponse(BaseModel):
"""人脸列表分页响应模型结构不变内部FaceResponse已移除eigenvalue"""
total: int = Field(..., description="筛选后的总记录数")
faces: List[FaceResponse] = Field(..., description="当前页的人脸记录列表")
model_config = {"from_attributes": True}