feat(blog): add admin endpoint to list all blog posts with status filtering
This commit is contained in:
@@ -40,6 +40,40 @@ class BlogRepository extends ServiceEntityRepository
|
||||
->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin list — ALL statuses (draft/published/archived), newest first, with
|
||||
* optional status + title search. The public list only returns published, so
|
||||
* the admin panel must use this to see drafts.
|
||||
* @return Blog[]
|
||||
*/
|
||||
public function findForAdmin(int $page, int $limit, ?string $status = null, ?string $search = null): array
|
||||
{
|
||||
$qb = $this->adminQb($status, $search)
|
||||
->leftJoin('b.city', 'c')->addSelect('c')
|
||||
->orderBy('b.createdAt', 'DESC')
|
||||
->setFirstResult(($page - 1) * $limit)
|
||||
->setMaxResults($limit);
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function countForAdmin(?string $status = null, ?string $search = null): int
|
||||
{
|
||||
return (int) $this->adminQb($status, $search)
|
||||
->select('COUNT(b.id)')->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
private function adminQb(?string $status, ?string $search): \Doctrine\ORM\QueryBuilder
|
||||
{
|
||||
$qb = $this->createQueryBuilder('b');
|
||||
if ($status !== null && $status !== '') {
|
||||
$qb->andWhere('b.status = :status')->setParameter('status', $status);
|
||||
}
|
||||
if ($search !== null && $search !== '') {
|
||||
$qb->andWhere('b.title LIKE :q')->setParameter('q', '%' . $search . '%');
|
||||
}
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* A representative's own posts, newest first, optionally filtered by status.
|
||||
* @return Blog[]
|
||||
|
||||
Reference in New Issue
Block a user