refactor: 优化API路由和响应模型 feat(admin): 添加App用户管理接口 feat(sms): 实现阿里云短信服务集成 feat(email): 添加SMTP邮件发送功能 feat(upload): 支持文件上传接口 feat(rate-limiter): 实现手机号限流器 fix: 修复计算步骤入库问题 docs: 更新API文档和测试计划 chore: 更新依赖和配置
115 lines
3.4 KiB
Python
115 lines
3.4 KiB
Python
from pydantic import BaseModel, Field, validator
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
import re
|
|
|
|
|
|
class AppUserRegisterSchema(BaseModel):
|
|
"""AppUser注册Schema - 只需要手机号"""
|
|
phone: str = Field(..., description="手机号")
|
|
|
|
@validator('phone')
|
|
def validate_phone(cls, v):
|
|
if not re.match(r'^1[3-9]\d{9}$', v):
|
|
raise ValueError('手机号格式不正确')
|
|
return v
|
|
|
|
|
|
class AppUserLoginSchema(BaseModel):
|
|
"""AppUser登录Schema"""
|
|
phone: str = Field(..., description="手机号")
|
|
password: str = Field(..., description="密码")
|
|
|
|
|
|
class AppUserJWTPayload(BaseModel):
|
|
"""AppUser JWT载荷"""
|
|
user_id: int
|
|
phone: str
|
|
exp: datetime
|
|
|
|
|
|
class AppUserJWTOut(BaseModel):
|
|
"""AppUser JWT输出"""
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
expires_in: int
|
|
|
|
|
|
class AppUserInfoOut(BaseModel):
|
|
"""AppUser信息输出"""
|
|
id: int
|
|
phone: str
|
|
nickname: Optional[str] = None
|
|
avatar: Optional[str] = None
|
|
company_name: Optional[str] = None
|
|
company_address: Optional[str] = None
|
|
company_contact: Optional[str] = None
|
|
company_phone: Optional[str] = None
|
|
company_email: Optional[str] = None
|
|
is_active: bool
|
|
last_login: Optional[datetime] = None
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
remaining_quota: int
|
|
|
|
|
|
class AppUserUpdateSchema(BaseModel):
|
|
"""AppUser更新Schema"""
|
|
nickname: Optional[str] = Field(None, description="昵称")
|
|
avatar: Optional[str] = Field(None, description="头像")
|
|
company_name: Optional[str] = Field(None, description="公司名称")
|
|
company_address: Optional[str] = Field(None, description="公司地址")
|
|
company_contact: Optional[str] = Field(None, description="公司联系人")
|
|
company_phone: Optional[str] = Field(None, description="公司电话")
|
|
company_email: Optional[str] = Field(None, description="公司邮箱")
|
|
|
|
|
|
class AppUserChangePasswordSchema(BaseModel):
|
|
"""AppUser修改密码Schema"""
|
|
old_password: str = Field(..., description="原密码")
|
|
new_password: str = Field(..., description="新密码")
|
|
|
|
|
|
class AppUserDashboardOut(BaseModel):
|
|
"""AppUser首页摘要输出"""
|
|
remaining_quota: int
|
|
latest_valuation: Optional[dict] = None
|
|
pending_invoices: int
|
|
|
|
|
|
class AppUserQuotaOut(BaseModel):
|
|
"""AppUser剩余估值次数输出"""
|
|
remaining_count: int
|
|
user_type: Optional[str] = None
|
|
|
|
|
|
class AppUserQuotaUpdateSchema(BaseModel):
|
|
user_id: int = Field(..., description="用户ID")
|
|
target_count: Optional[int] = Field(None, description="目标次数")
|
|
delta: Optional[int] = Field(None, description="增减次数")
|
|
op_type: str = Field(..., description="操作类型")
|
|
remark: Optional[str] = Field(None, description="备注")
|
|
|
|
|
|
class AppUserQuotaLogOut(BaseModel):
|
|
id: int
|
|
app_user_id: int
|
|
operator_id: int
|
|
operator_name: str
|
|
before_count: int
|
|
after_count: int
|
|
op_type: str
|
|
remark: Optional[str] = None
|
|
|
|
|
|
class AppUserRegisterOut(BaseModel):
|
|
"""App 用户注册结果"""
|
|
user_id: int = Field(..., description="用户ID")
|
|
phone: str = Field(..., description="手机号")
|
|
default_password: str = Field(..., description="默认密码(手机号后六位)")
|
|
|
|
|
|
class TokenValidateOut(BaseModel):
|
|
"""Token 校验结果"""
|
|
user_id: int = Field(..., description="用户ID")
|
|
phone: str = Field(..., description="手机号") |