feat(activity-log) : add paginated activity log endpoint and store constructeur names in audit
- New GET /api/activity-logs endpoint with pagination and filters
(entityType, action) for the global activity log page
- Add findAllPaginated() to AuditLogRepository
- normalizeCollection() now stores {id, name} objects instead of
bare IDs so constructeur changes display readable names
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,46 @@ final class AuditLogRepository extends ServiceEntityRepository
|
||||
->orderBy('a.createdAt', 'DESC')
|
||||
->setMaxResults($limit)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{entityType?: string, action?: string} $filters
|
||||
*
|
||||
* @return array{items: list<AuditLog>, total: int}
|
||||
*/
|
||||
public function findAllPaginated(int $page = 1, int $itemsPerPage = 30, array $filters = []): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('a')
|
||||
->orderBy('a.createdAt', 'DESC')
|
||||
;
|
||||
|
||||
if (!empty($filters['entityType'])) {
|
||||
$qb->andWhere('a.entityType = :entityType')
|
||||
->setParameter('entityType', $filters['entityType'])
|
||||
;
|
||||
}
|
||||
|
||||
if (!empty($filters['action'])) {
|
||||
$qb->andWhere('a.action = :action')
|
||||
->setParameter('action', $filters['action'])
|
||||
;
|
||||
}
|
||||
|
||||
$countQb = clone $qb;
|
||||
$countQb->select('COUNT(a.id)')
|
||||
->resetDQLPart('orderBy')
|
||||
;
|
||||
$total = (int) $countQb->getQuery()->getSingleScalarResult();
|
||||
|
||||
$qb->setFirstResult(($page - 1) * $itemsPerPage)
|
||||
->setMaxResults($itemsPerPage)
|
||||
;
|
||||
|
||||
return [
|
||||
'items' => $qb->getQuery()->getResult(),
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user