baoxiang/backend/app/schemas/user.py
2025-12-16 18:06:50 +08:00

94 lines
2.2 KiB
Python
Raw Permalink 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.

"""
用户相关Schema
"""
from pydantic import BaseModel, EmailStr, Field
from typing import Optional, List
from datetime import datetime
class UserBase(BaseModel):
username: str = Field(..., min_length=3, max_length=50)
email: EmailStr
class UserCreate(UserBase):
password: str = Field(..., min_length=6, max_length=72)
class UserLogin(BaseModel):
username: str
password: str
class UserResponse(UserBase):
id: int
role: str
nickname: Optional[str] = None
avatar_url: Optional[str] = None
phone: Optional[str] = None
status: str
balance: int
login_count: int
last_login_at: Optional[datetime] = None
is_active: bool
created_at: datetime
class Config:
from_attributes = True
class UserUpdate(BaseModel):
nickname: Optional[str] = None
email: Optional[EmailStr] = None
phone: Optional[str] = None
role: Optional[str] = None
status: Optional[str] = None
is_active: Optional[bool] = None
class UserBalanceAdjust(BaseModel):
amount: int = Field(..., description="调整金额(正数增加,负数减少)")
description: str = Field(..., min_length=1, max_length=200, description="调整原因")
class UserBatchAction(BaseModel):
action: str = Field(..., description="操作类型ENABLE/DISABLE/BAN")
user_ids: List[int] = Field(..., min_items=1, description="用户ID列表")
reason: Optional[str] = Field(None, description="操作原因")
class UserStatistics(BaseModel):
total_bets: int
total_winnings: int
win_rate: float
class TransactionCreate(BaseModel):
type: str
amount: int
related_id: Optional[int] = None
description: Optional[str] = None
class TransactionResponse(BaseModel):
id: int
type: str
amount: int
balance_after: int
related_id: Optional[int]
description: Optional[str]
created_at: datetime
class Config:
from_attributes = True
class AllowanceClaim(BaseModel):
"""低保领取"""
pass
class ChangePasswordRequest(BaseModel):
"""修改密码请求"""
current_password: str = Field(..., min_length=6, max_length=72, description="当前密码")
new_password: str = Field(..., min_length=6, max_length=72, description="新密码")