""" 用户相关 Pydantic Schemas """ from pydantic import BaseModel, Field from datetime import datetime from typing import Optional class UserCreate(BaseModel): """用户注册请求""" username: str = Field(..., min_length=2, max_length=50, description="用户名") password: str = Field(..., min_length=6, max_length=100, description="密码") nickname: Optional[str] = Field(None, max_length=50, description="昵称") class UserLogin(BaseModel): """用户登录请求""" username: str = Field(..., description="用户名") password: str = Field(..., description="密码") class UserResponse(BaseModel): """用户响应""" id: int username: str nickname: Optional[str] = None phone: Optional[str] = None avatar: Optional[str] = None created_at: datetime class Config: from_attributes = True class Token(BaseModel): """认证令牌响应""" access_token: str token_type: str = "bearer" class UserUpdate(BaseModel): """用户信息更新请求""" nickname: Optional[str] = Field(None, max_length=50, description="昵称") phone: Optional[str] = Field(None, max_length=20, description="手机号") avatar: Optional[str] = Field(None, max_length=255, description="头像URL") class PasswordChange(BaseModel): """修改密码请求""" old_password: str = Field(..., description="旧密码") new_password: str = Field(..., min_length=6, max_length=100, description="新密码")