Files
life-echo/api/routers/user.py
iammm0 3690417fdc feat: 新增后端API路由模块
- 新增faqs.py常见问题路由
- 新增feedback.py反馈路由
- 新增orders.py订单路由
- 新增plans.py套餐路由
- 新增quota.py配额路由
- 新增user.py用户路由
- 更新main.py注册新路由
- 更新requirements.txt添加依赖
2026-01-23 14:02:36 +08:00

43 lines
1.1 KiB
Python

"""
用户相关 API 路由
"""
from fastapi import APIRouter, Depends
from pydantic import BaseModel
from typing import Optional
from middleware.auth import get_current_user
from database.models import User
router = APIRouter(prefix="/api/user", tags=["user"])
class UserProfileResponse(BaseModel):
"""用户资料响应"""
id: str
phone: str
email: Optional[str]
nickname: str
avatar_url: Optional[str]
subscription_type: str
created_at: str
@router.get("/profile", response_model=UserProfileResponse)
async def get_user_profile(
current_user: User = Depends(get_current_user)
):
"""
获取当前用户资料
与 /api/auth/me 功能相同,但路径不同以满足前端需求
"""
return UserProfileResponse(
id=current_user.id,
phone=current_user.phone,
email=current_user.email,
nickname=current_user.nickname,
avatar_url=current_user.avatar_url,
subscription_type=current_user.subscription_type,
created_at=current_user.created_at.isoformat()
)