""" 用户管理API路由 """ from typing import Any, List from fastapi import APIRouter, Depends, HTTPException, Query from fastapi.security import OAuth2PasswordBearer from app.config import settings router = APIRouter() # 临时模拟用户 oauth2_scheme = OAuth2PasswordBearer( tokenUrl=f"{settings.API_V1_STR}/auth/login" ) async def get_current_user(): """ 临时获取当前用户(无数据库依赖) """ # 返回模拟用户数据 return { "id": 1, "username": "admin", "email": "admin@example.com", "nickname": "管理员", "status": True, } @router.get("/me") async def get_current_user_info(current_user: dict = Depends(get_current_user)): """ 获取当前用户信息 """ return current_user @router.get("/") async def list_users( skip: int = Query(0, ge=0, description="跳过的记录数"), limit: int = Query(10, ge=1, le=100, description="返回的记录数"), ): """ 获取用户列表(模拟数据) """ return { "items": [ { "id": 1, "username": "admin", "email": "admin@example.com", "status": True, }, { "id": 2, "username": "user1", "email": "user1@example.com", "status": True, }, ], "total": 2, "page": 1, "size": 10, "pages": 1, } @router.get("/{user_id}") async def get_user(user_id: int): """ 获取用户详情(模拟数据) """ if user_id == 1: return { "id": 1, "username": "admin", "email": "admin@example.com", "status": True, "created_at": "2024-01-01T00:00:00", } else: raise HTTPException(status_code=404, detail="User not found")