32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from fastapi import APIRouter, Depends
|
|
|
|
from app.core.config import settings
|
|
from app.repositories.audit import list_audit_events
|
|
from app.repositories.schemes import get_scheme_record_by_scheme_id
|
|
from app.schemas.audit import AuditEventItem, SchemeAuditResponse
|
|
from app.security.auth import require_api_key
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get(f"{settings.api_v1_prefix}/schemes/{{scheme_id}}/audit", response_model=SchemeAuditResponse)
|
|
async def get_scheme_audit(scheme_id: str, role: str = Depends(require_api_key)):
|
|
await get_scheme_record_by_scheme_id(scheme_id)
|
|
rows = await list_audit_events(scheme_id)
|
|
|
|
return SchemeAuditResponse(
|
|
items=[
|
|
AuditEventItem(
|
|
audit_event_id=row.audit_event_id,
|
|
scheme_id=row.scheme_id,
|
|
event_type=row.event_type,
|
|
object_type=row.object_type,
|
|
object_ref=row.object_ref,
|
|
details_json=row.details_json,
|
|
created_at=row.created_at.isoformat(),
|
|
)
|
|
for row in rows
|
|
],
|
|
total=len(rows),
|
|
)
|