Files
sam-api/app/Services/Audit/AuditLogService.php
hskwon 785e367472 feat: 통합 감사 로그 도입 및 조회 API/스케줄러 추가
- DB: 감사 로그 테이블(audit_logs) 마이그레이션 및 인덱스 추가
- Config: audit.php 추가(AUDIT_RETENTION_DAYS, AUDIT_LOG_READS 토글)
- Model/Service: AuditLog 모델, AuditLogger 서비스 생성
- 도메인 훅: ModelVersion.release(released), BomTemplate upsert/update/delete/replaceItems/clone 기록, diff 조회는 설정 기반 기록
- API: GET /api/v1/design/audit-logs 추가(FormRequest/Service/Controller, 필터 page/size/target_type/target_id/action/actor_id/from/to/sort/order)
- Swagger: 감사 로그 조회 문서 추가(Design Audit 태그)
- Console: audit:prune 커맨드 추가 및 스케줄러 매일 03:10 실행 등록(시스템 크론 schedule:run 필요)
- Fix: PruneAuditLogs import 충돌 제거(Google ServiceControl AuditLog 제거)
2025-09-11 14:39:55 +09:00

44 lines
1.3 KiB
PHP

<?php
namespace App\Services\Audit;
use App\Models\Audit\AuditLog;
use App\Services\Service;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
class AuditLogService extends Service
{
public function paginate(array $filters): LengthAwarePaginator
{
$tenantId = $this->tenantId();
$page = (int)($filters['page'] ?? 1);
$size = (int)($filters['size'] ?? 20);
$sort = $filters['sort'] ?? 'created_at';
$order = $filters['order'] ?? 'desc';
$q = AuditLog::query()->where('tenant_id', $tenantId);
if (!empty($filters['target_type'])) {
$q->where('target_type', $filters['target_type']);
}
if (!empty($filters['target_id'])) {
$q->where('target_id', (int)$filters['target_id']);
}
if (!empty($filters['action'])) {
$q->where('action', $filters['action']);
}
if (!empty($filters['actor_id'])) {
$q->where('actor_id', (int)$filters['actor_id']);
}
if (!empty($filters['from'])) {
$q->where('created_at', '>=', $filters['from']);
}
if (!empty($filters['to'])) {
$q->where('created_at', '<=', $filters['to']);
}
return $q->orderBy($sort, $order)->paginate($size, ['*'], 'page', $page);
}
}