Files
life-echo/api/routers/user.py

43 lines
1.1 KiB
Python
Raw Normal View History

"""
用户相关 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()
)