Skip to content

Commit 65d3e3f

Browse files
committed
Add: get subscribers endpoint
1 parent aacaf11 commit 65d3e3f

2 files changed

Lines changed: 69 additions & 7 deletions

File tree

src/Subscription/Controller/SubscriberController.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpList\Core\Security\Authentication;
1313
use PhpList\RestBundle\Common\Controller\BaseController;
1414
use PhpList\RestBundle\Common\Validator\RequestValidator;
15+
use PhpList\RestBundle\Common\Service\Provider\PaginatedDataProvider;
1516
use PhpList\RestBundle\Subscription\Request\CreateSubscriberRequest;
1617
use PhpList\RestBundle\Subscription\Request\UpdateSubscriberRequest;
1718
use PhpList\RestBundle\Subscription\Serializer\SubscriberNormalizer;
@@ -39,11 +40,79 @@ public function __construct(
3940
private readonly SubscriberNormalizer $subscriberNormalizer,
4041
private readonly SubscriberHistoryService $subscriberHistoryService,
4142
private readonly EntityManagerInterface $entityManager,
43+
private readonly PaginatedDataProvider $paginatedDataProvider,
4244
) {
4345
parent::__construct($authentication, $validator);
4446
$this->authentication = $authentication;
4547
}
4648

49+
#[Route('', name: 'get_list', methods: ['GET'])]
50+
#[OA\Get(
51+
path: '/api/v2/subscribers',
52+
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
53+
'Returns a JSON list of all subscribers.',
54+
summary: 'Gets a list of all subscribers.',
55+
tags: ['subscribers'],
56+
parameters: [
57+
new OA\Parameter(
58+
name: 'php-auth-pw',
59+
description: 'Session key obtained from login',
60+
in: 'header',
61+
required: true,
62+
schema: new OA\Schema(type: 'string')
63+
),
64+
new OA\Parameter(
65+
name: 'after_id',
66+
description: 'Last id (starting from 0)',
67+
in: 'query',
68+
required: false,
69+
schema: new OA\Schema(type: 'integer', default: 1, minimum: 1)
70+
),
71+
new OA\Parameter(
72+
name: 'limit',
73+
description: 'Number of results per page',
74+
in: 'query',
75+
required: false,
76+
schema: new OA\Schema(type: 'integer', default: 25, maximum: 100, minimum: 1)
77+
)
78+
],
79+
responses: [
80+
new OA\Response(
81+
response: 200,
82+
description: 'Success',
83+
content: new OA\JsonContent(
84+
properties: [
85+
new OA\Property(
86+
property: 'items',
87+
type: 'array',
88+
items: new OA\Items(ref: '#/components/schemas/Subscriber')
89+
),
90+
new OA\Property(property: 'pagination', ref: '#/components/schemas/CursorPagination')
91+
],
92+
type: 'object'
93+
)
94+
),
95+
new OA\Response(
96+
response: 403,
97+
description: 'Failure',
98+
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
99+
)
100+
]
101+
)]
102+
public function getSubscribers(Request $request): JsonResponse
103+
{
104+
$this->requireAuthentication($request);
105+
106+
return $this->json(
107+
$this->paginatedDataProvider->getPaginatedList(
108+
$request,
109+
$this->subscriberNormalizer,
110+
Subscriber::class
111+
),
112+
Response::HTTP_OK
113+
);
114+
}
115+
47116
#[Route('', name: 'create', methods: ['POST'])]
48117
#[OA\Post(
49118
path: '/api/v2/subscribers',

tests/Integration/Subscription/Controller/SubscriberControllerTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ public function testControllerIsAvailableViaContainer()
3535
);
3636
}
3737

38-
public function testGetSubscribersIsNotAllowed()
39-
{
40-
self::getClient()->request('get', '/api/v2/subscribers');
41-
42-
$this->assertHttpMethodNotAllowed();
43-
}
44-
4538
public function testPostSubscribersWithoutSessionKeyReturnsForbiddenStatus()
4639
{
4740
$this->jsonRequest('post', '/api/v2/subscribers');

0 commit comments

Comments
 (0)