33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from datetime import datetime
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
# ------------------------------
|
||
# 请求模型(前端传参校验)
|
||
# ------------------------------
|
||
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}
|