40 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
		
		
			
		
	
	
			40 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
|  | from datetime import datetime | |||
|  | from pydantic import BaseModel, Field | |||
|  | from typing import List, Optional | |||
|  | 
 | |||
|  | 
 | |||
|  | # ------------------------------ | |||
|  | # 请求模型(前端传参校验) | |||
|  | # ------------------------------ | |||
|  | class UserRegisterRequest(BaseModel): | |||
|  |     """用户注册请求模型""" | |||
|  |     username: str = Field(..., min_length=3, max_length=50, description="用户名(3-50字符)") | |||
|  |     password: str = Field(..., min_length=6, max_length=100, description="密码(6-100字符)") | |||
|  | 
 | |||
|  | 
 | |||
|  | class UserLoginRequest(BaseModel): | |||
|  |     """用户登录请求模型""" | |||
|  |     username: str = Field(..., description="用户名") | |||
|  |     password: str = Field(..., description="密码") | |||
|  | 
 | |||
|  | 
 | |||
|  | # ------------------------------ | |||
|  | # 响应模型(后端返回用户数据) | |||
|  | # ------------------------------ | |||
|  | class UserResponse(BaseModel): | |||
|  |     """用户信息响应模型(隐藏密码等敏感字段)""" | |||
|  |     id: int = Field(..., description="用户ID") | |||
|  |     username: str = Field(..., description="用户名") | |||
|  |     created_at: datetime = Field(..., description="创建时间") | |||
|  |     updated_at: datetime = Field(..., description="更新时间") | |||
|  | 
 | |||
|  |     # Pydantic V2 配置(支持从数据库查询结果转换) | |||
|  |     model_config = {"from_attributes": True} | |||
|  | 
 | |||
|  | 
 | |||
|  | class UserListResponse(BaseModel): | |||
|  |     """用户列表分页响应模型(与设备/人脸列表结构对齐)""" | |||
|  |     total: int = Field(..., description="用户总数") | |||
|  |     users: List[UserResponse] = Field(..., description="当前页用户列表") | |||
|  | 
 | |||
|  |     model_config = {"from_attributes": True} |