1a7a624b87
用户/提现/上报/审计日志四个主列表页从「加载更多」改为页码分页: - CursorPage 加 total 字段(可选,不影响其它接口) - queries 新增 offset_paginate(items, next_cursor, total);count 与分页同源, 筛选条件一处构建避免漂移;list_users/withdraw/price_reports 接入返回 total - price_reports / audit_logs 从 id 游标改 offset 分页(cursor 即 offset),支持跳页 - 四个 router 透出 total;withdraw 详情内部调用同步解包 - 反馈页本轮排除(其 router/model 正在 feat/feedback-iteration 迭代,避免纠缠) 测试: test_audit_log_pagination 改为校验 offset+total;admin 套件 47 passed。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""admin 操作审计日志查询(所有 admin 可看:谁在何时对什么做了什么)。"""
|
|
from __future__ import annotations
|
|
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
|
|
from app.admin.deps import AdminDb, get_current_admin
|
|
from app.admin.repositories import audit_log as audit_repo
|
|
from app.admin.schemas.admin import AdminAuditLogOut
|
|
from app.admin.schemas.common import CursorPage
|
|
|
|
router = APIRouter(
|
|
prefix="/admin/api/audit-logs",
|
|
tags=["admin-audit"],
|
|
dependencies=[Depends(get_current_admin)],
|
|
)
|
|
|
|
|
|
@router.get("", response_model=CursorPage[AdminAuditLogOut], summary="审计日志(谁改了什么)")
|
|
def list_audit_logs(
|
|
db: AdminDb,
|
|
action: Annotated[str | None, Query()] = None,
|
|
target_type: Annotated[str | None, Query()] = None,
|
|
admin_id: Annotated[int | None, Query()] = None,
|
|
limit: Annotated[int, Query(ge=1, le=100)] = 50,
|
|
cursor: Annotated[int | None, Query()] = None,
|
|
) -> CursorPage[AdminAuditLogOut]:
|
|
items, next_cursor, total = audit_repo.list_audit_logs(
|
|
db, action=action, target_type=target_type, admin_id=admin_id, limit=limit, cursor=cursor,
|
|
)
|
|
return CursorPage(
|
|
items=[AdminAuditLogOut.model_validate(x) for x in items],
|
|
next_cursor=next_cursor,
|
|
total=total,
|
|
)
|