feat(blog): add admin endpoint to list all blog posts with status filtering
This commit is contained in:
@@ -149,6 +149,37 @@ class BlogController extends BaseController
|
||||
|
||||
// ── Admin CRUD ────────────────────────────────────────────────────────────
|
||||
|
||||
#[OA\Get(
|
||||
path: '/api/v1/admin/blogs',
|
||||
summary: 'List blog posts of ALL statuses for the admin panel (draft/published/archived)',
|
||||
security: [['bearerAuth' => []]],
|
||||
parameters: [
|
||||
new OA\Parameter(name: 'page', in: 'query', required: false, schema: new OA\Schema(type: 'integer', default: 1)),
|
||||
new OA\Parameter(name: 'limit', in: 'query', required: false, schema: new OA\Schema(type: 'integer', default: 20, maximum: 50)),
|
||||
new OA\Parameter(name: 'status', in: 'query', required: false, schema: new OA\Schema(type: 'string', enum: ['draft', 'published', 'archived'])),
|
||||
new OA\Parameter(name: 'search', in: 'query', required: false, schema: new OA\Schema(type: 'string')),
|
||||
],
|
||||
responses: [new OA\Response(response: 200, description: 'Paginated blog list (all statuses)')]
|
||||
)]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
#[Route('/api/v1/admin/blogs', methods: ['GET'])]
|
||||
public function adminList(Request $request): JsonResponse
|
||||
{
|
||||
$page = max(1, (int) $request->query->get('page', 1));
|
||||
$limit = min(50, max(1, (int) $request->query->get('limit', 20)));
|
||||
$status = $request->query->get('status') ?: null;
|
||||
$search = $request->query->get('search') ?: null;
|
||||
|
||||
$items = array_map(
|
||||
fn(Blog $b) => $b->toListArray(),
|
||||
$this->blogRepo->findForAdmin($page, $limit, $status, $search)
|
||||
);
|
||||
$total = $this->blogRepo->countForAdmin($status, $search);
|
||||
|
||||
return $this->paginated($items, $total, $page, $limit);
|
||||
}
|
||||
|
||||
|
||||
#[OA\Post(
|
||||
path: '/api/v1/blog',
|
||||
summary: 'Create a new blog post (admin only)',
|
||||
|
||||
Reference in New Issue
Block a user