Initial project commit

This commit is contained in:
2026-05-09 16:40:29 +08:00
commit 02b0259a9e
267 changed files with 54891 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import json
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.audit_log import AuditLog
async def log_action(
db: AsyncSession,
operator_id: int,
action: str,
target_type: str,
target_id: int | None = None,
detail: dict | str | None = None,
) -> AuditLog:
detail_str = None
if detail is not None:
detail_str = json.dumps(detail, ensure_ascii=False) if isinstance(detail, dict) else str(detail)
entry = AuditLog(
operator_id=operator_id,
action=action,
target_type=target_type,
target_id=target_id,
detail=detail_str,
)
db.add(entry)
await db.flush()
return entry