249a1aaed9
- 后端: 添加 POST /api/retries/{id}/retry (手动重试) + DELETE /api/retries/{id}
+ 审计日志分页(offset/limit/count) + PushRetryJobRepo新增get_all/get_by_id/delete
- 前端retries: 手动重试按钮、删除按钮、状态过滤、操作人显示、toast反馈
- 前端audit: 分页控件(上一页/下一页)、每页50条、新增retry_job/delete_retry过滤
- 修复index.html: 适配审计API新返回格式(data.items)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
"""Nexus — AuditLog Repository (Async SQLAlchemy)"""
|
|
|
|
from typing import List, Optional
|
|
from sqlalchemy import select, func
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from server.domain.models import AuditLog
|
|
|
|
|
|
class AuditLogRepositoryImpl:
|
|
def __init__(self, session: AsyncSession):
|
|
self.session = session
|
|
|
|
async def create(self, log: AuditLog) -> AuditLog:
|
|
self.session.add(log)
|
|
await self.session.commit()
|
|
await self.session.refresh(log)
|
|
return log
|
|
|
|
async def count(self, action: Optional[str] = None) -> int:
|
|
q = select(func.count(AuditLog.id))
|
|
if action:
|
|
q = q.where(AuditLog.action == action)
|
|
result = await self.session.execute(q)
|
|
return result.scalar() or 0
|
|
|
|
async def get_recent(self, limit: int = 200, offset: int = 0) -> List[AuditLog]:
|
|
result = await self.session.execute(
|
|
select(AuditLog).order_by(AuditLog.created_at.desc()).offset(offset).limit(limit)
|
|
)
|
|
return list(result.scalars().all())
|
|
|
|
async def get_by_action(self, action: str, limit: int = 50, offset: int = 0) -> List[AuditLog]:
|
|
result = await self.session.execute(
|
|
select(AuditLog)
|
|
.where(AuditLog.action == action)
|
|
.order_by(AuditLog.created_at.desc())
|
|
.offset(offset)
|
|
.limit(limit)
|
|
)
|
|
return list(result.scalars().all()) |