修复审计日志字段格式与列表标识并补充回归测试

This commit is contained in:
xuans committed 2026-09-24 23:30:49 +08:00
1 parent fcad812c85
commit c4136cd8f3
3 files changed
+63 -8

No files matched your search

+2 -2
View File
@@ -18,7 +18,7 @@ func (r *SQLAuditRepository) ListAuditLogs(ctx context.Context, limit int) ([]Au
if limit <= 0 || limit > 200 {
limit = 50
}
rows, err := r.db.QueryContext(ctx, r.query(`SELECT action, resource_type, resource_id, status, message, created_at FROM audit_logs ORDER BY created_at DESC, id DESC LIMIT `+fmt.Sprintf("%d", limit)))
rows, err := r.db.QueryContext(ctx, r.query(`SELECT id, action, resource_type, resource_id, status, message, created_at FROM audit_logs ORDER BY created_at DESC, id DESC LIMIT `+fmt.Sprintf("%d", limit)))
if err != nil {
return nil, fmt.Errorf("查询审计日志失败:%w", err)
}
@@ -26,7 +26,7 @@ func (r *SQLAuditRepository) ListAuditLogs(ctx context.Context, limit int) ([]Au
logs := make([]AuditLog, 0)
for rows.Next() {
var item AuditLog
if err := rows.Scan(&item.Action, &item.ResourceType, &item.ResourceID, &item.Status, &item.Message, &item.CreatedAt); err != nil {
if err := rows.Scan(&item.ID, &item.Action, &item.ResourceType, &item.ResourceID, &item.Status, &item.Message, &item.CreatedAt); err != nil {
return nil, fmt.Errorf("读取审计日志失败:%w", err)
}
item.CreatedAt = item.CreatedAt.UTC()