Skip to content

Commit aa3f3c6

Browse files
committed
Add endpoint to retrieve all subscribe pages
1 parent addb913 commit aa3f3c6

2 files changed

Lines changed: 79 additions & 1 deletion

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"require": {
4444
"php": "^8.1",
45-
"phplist/core": "dev-main",
45+
"phplist/core": "dev-dev",
4646
"friendsofsymfony/rest-bundle": "*",
4747
"symfony/test-pack": "^1.0",
4848
"symfony/process": "^6.4",

src/Subscription/Controller/SubscribePageController.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
use Doctrine\ORM\EntityManagerInterface;
88
use OpenApi\Attributes as OA;
9+
use PhpList\Core\Domain\Common\Model\Filter\PaginatedFilter;
910
use PhpList\Core\Domain\Identity\Model\PrivilegeFlag;
1011
use PhpList\Core\Domain\Subscription\Model\SubscribePage;
1112
use PhpList\Core\Domain\Subscription\Service\Manager\SubscribePageManager;
1213
use PhpList\Core\Security\Authentication;
1314
use PhpList\RestBundle\Common\Controller\BaseController;
15+
use PhpList\RestBundle\Common\Service\Provider\PaginatedDataProvider;
1416
use PhpList\RestBundle\Common\Validator\RequestValidator;
1517
use PhpList\RestBundle\Subscription\Request\SubscribePageDataRequest;
1618
use PhpList\RestBundle\Subscription\Request\SubscribePageRequest;
@@ -30,10 +32,86 @@ public function __construct(
3032
private readonly SubscribePageManager $subscribePageManager,
3133
private readonly SubscribePageNormalizer $normalizer,
3234
private readonly EntityManagerInterface $entityManager,
35+
private readonly PaginatedDataProvider $paginatedProvider,
3336
) {
3437
parent::__construct($authentication, $validator);
3538
}
3639

40+
#[Route('/', name: 'get_all', methods: ['GET'])]
41+
#[OA\Get(
42+
path: '/api/v2/subscribe-pages',
43+
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production.',
44+
summary: 'Get subscribe pages list',
45+
tags: ['subscriptions'],
46+
parameters: [
47+
new OA\Parameter(
48+
name: 'php-auth-pw',
49+
description: 'Session key obtained from login',
50+
in: 'header',
51+
required: true,
52+
schema: new OA\Schema(type: 'string')
53+
),
54+
new OA\Parameter(
55+
name: 'after_id',
56+
description: 'Last id (starting from 0)',
57+
in: 'query',
58+
required: false,
59+
schema: new OA\Schema(type: 'integer', default: 1, minimum: 1)
60+
),
61+
new OA\Parameter(
62+
name: 'limit',
63+
description: 'Number of results per page',
64+
in: 'query',
65+
required: false,
66+
schema: new OA\Schema(type: 'integer', default: 25, maximum: 100, minimum: 1)
67+
)
68+
],
69+
responses: [
70+
new OA\Response(
71+
response: 200,
72+
description: 'Success',
73+
content: new OA\JsonContent(
74+
properties: [
75+
new OA\Property(
76+
property: 'items',
77+
type: 'array',
78+
items: new OA\Items(ref: '#/components/schemas/SubscribePage')
79+
),
80+
new OA\Property(property: 'pagination', ref: '#/components/schemas/CursorPagination')
81+
],
82+
type: 'object'
83+
)
84+
),
85+
new OA\Response(
86+
response: 403,
87+
description: 'Failure',
88+
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
89+
),
90+
new OA\Response(
91+
response: 404,
92+
description: 'Not Found',
93+
content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse')
94+
),
95+
]
96+
)]
97+
public function getPages(Request $request): JsonResponse
98+
{
99+
$admin = $this->requireAuthentication($request);
100+
if (!$admin->getPrivileges()->has(PrivilegeFlag::Subscribers)) {
101+
throw $this->createAccessDeniedException('You are not allowed to view subscribe pages.');
102+
}
103+
104+
return $this->json(
105+
$this->paginatedProvider->getPaginatedList(
106+
request: $request,
107+
normalizer: $this->normalizer,
108+
className: SubscribePage::class,
109+
filter: new PaginatedFilter(),
110+
),
111+
Response::HTTP_OK
112+
);
113+
}
114+
37115
#[Route('/{id}', name: 'get', requirements: ['id' => '\\d+'], methods: ['GET'])]
38116
#[OA\Get(
39117
path: '/api/v2/subscribe-pages/{id}',

0 commit comments

Comments
 (0)