Files
yaoyaoai/app/api/v1/agent_users.py
fengchuanhn@gmail.com 80958994a2 11
2026-05-22 16:49:02 +08:00

45 lines
1.4 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.
"""代理仅查看名下用户agent_id 匹配)。"""
from fastapi import APIRouter, Query
from app.dependencies import AgentUser, DbSession
from app.schemas.admin_user import AdminUserOut
from app.schemas.common import ApiResponse, PaginatedData
from app.services import agent_user as agent_user_service
router = APIRouter(prefix="/agent/users", tags=["代理-用户"])
@router.get("", response_model=ApiResponse[PaginatedData[AdminUserOut]])
async def list_users(
agent: AgentUser,
db: DbSession,
page: int = Query(1, ge=1, description="页码,从 1 开始"),
page_size: int = Query(
agent_user_service.DEFAULT_PAGE_SIZE,
ge=1,
le=agent_user_service.MAX_PAGE_SIZE,
description="每页条数",
),
username: str | None = Query(None, description="用户名模糊搜索"),
role_id: int | None = Query(None, ge=0, le=3, description="按角色筛选"),
) -> ApiResponse[PaginatedData[AdminUserOut]]:
users, total = await agent_user_service.list_users(
db,
agent_id=agent.id,
page=page,
page_size=page_size,
username=username,
role_id=role_id,
)
return ApiResponse(
ok=True,
message="",
data=PaginatedData.build(
[AdminUserOut.model_validate(u) for u in users],
total=total,
page=page,
page_size=page_size,
),
)