Files
video/schema/user_schema.py
2025-09-02 18:51:50 +08:00

33 lines
1.2 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
# ------------------------------
# 请求模型(前端传参校验)
# ------------------------------
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}