more_agent/app/models.py

106 lines
2.8 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.

"""用户管理服务 - 数据模型定义模块。
定义系统中使用的 Pydantic 模型,包括请求体和响应体的数据结构。
"""
from datetime import datetime
from typing import Optional
from pydantic import BaseModel, EmailStr, Field
class UserCreate(BaseModel):
"""用户创建请求模型。
Attributes:
username: 用户名3-50个字符
email: 邮箱地址
password: 密码6-100个字符
"""
username: str = Field(..., min_length=3, max_length=50, description="用户名")
email: str = Field(..., description="邮箱地址")
password: str = Field(..., min_length=6, max_length=100, description="密码")
class UserUpdate(BaseModel):
"""用户更新请求模型。
Attributes:
username: 可选,用户名
email: 可选,邮箱地址
"""
username: Optional[str] = Field(None, min_length=3, max_length=50, description="用户名")
email: Optional[str] = Field(None, description="邮箱地址")
class UserLogin(BaseModel):
"""用户登录请求模型。
Attributes:
username: 用户名
password: 密码
"""
username: str = Field(..., description="用户名")
password: str = Field(..., description="密码")
class UserResponse(BaseModel):
"""用户信息响应模型。
Attributes:
id: 用户唯一标识
username: 用户名
email: 邮箱地址
created_at: 创建时间
is_active: 是否激活
"""
id: str = Field(..., description="用户ID")
username: str = Field(..., description="用户名")
email: str = Field(..., description="邮箱地址")
created_at: str = Field(..., description="创建时间")
is_active: bool = Field(default=True, description="是否激活")
class UserInDB(BaseModel):
"""数据库中的用户模型(包含密码哈希)。
Attributes:
id: 用户唯一标识
username: 用户名
email: 邮箱地址
hashed_password: 密码哈希值
created_at: 创建时间
is_active: 是否激活
"""
id: str = Field(..., description="用户ID")
username: str = Field(..., description="用户名")
email: str = Field(..., description="邮箱地址")
hashed_password: str = Field(..., description="密码哈希值")
created_at: str = Field(..., description="创建时间")
is_active: bool = Field(default=True, description="是否激活")
class ErrorResponse(BaseModel):
"""错误响应模型。
Attributes:
detail: 错误详情描述
"""
detail: str = Field(..., description="错误描述")
class SuccessResponse(BaseModel):
"""成功响应模型。
Attributes:
message: 成功消息
"""
message: str = Field(..., description="成功消息")