Skip to content

Commit bf669e5

Browse files
committed
ISSUE-344: add get subscriber by id route
1 parent 76360d6 commit bf669e5

File tree

2 files changed

+88
-4
lines changed

2 files changed

+88
-4
lines changed

src/Controller/ListController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function deleteList(
269269

270270
#[Route('/lists/{id}/subscribers', name: 'get_subscriber_from_list', methods: ['GET'])]
271271
#[OA\Get(
272-
path: '/lists/{list}/subscribers',
272+
path: '/lists/{id}/subscribers',
273273
description: 'Returns a JSON list of all subscribers for a subscriber list.',
274274
summary: 'Gets a list of all subscribers of a subscriber list.',
275275
tags: ['lists'],
@@ -282,7 +282,7 @@ public function deleteList(
282282
schema: new OA\Schema(type: 'string')
283283
),
284284
new OA\Parameter(
285-
name: 'list',
285+
name: 'id',
286286
description: 'List ID',
287287
in: 'path',
288288
required: true,
@@ -353,7 +353,7 @@ public function getListMembers(
353353

354354
#[Route('/lists/{id}/subscribers/count', name: 'get_subscribers_count_from_list', methods: ['GET'])]
355355
#[OA\Get(
356-
path: '/lists/{list}/count',
356+
path: '/lists/{id}/count',
357357
description: 'Returns a count of all subscribers in a given list.',
358358
summary: 'Gets the total number of subscribers of a list',
359359
tags: ['lists'],
@@ -366,7 +366,7 @@ public function getListMembers(
366366
schema: new OA\Schema(type: 'string')
367367
),
368368
new OA\Parameter(
369-
name: 'list',
369+
name: 'id',
370370
description: 'List ID',
371371
in: 'path',
372372
required: true,

src/Controller/SubscriberController.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\RestBundle\Controller;
66

7+
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
78
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
89
use PhpList\Core\Domain\Model\Subscription\Subscriber;
910
use PhpList\Core\Domain\Repository\Subscription\SubscriberRepository;
@@ -15,6 +16,7 @@
1516
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
1617
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
1718
use Symfony\Component\Routing\Attribute\Route;
19+
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
1820
use Symfony\Component\Serializer\SerializerInterface;
1921
use OpenApi\Attributes as OA;
2022

@@ -156,6 +158,88 @@ public function postAction(Request $request, SerializerInterface $serializer): J
156158
);
157159
}
158160

161+
#[Route('/subscribers/{subscriber}', name: 'get_subscriber_by_id', methods: ['GET'])]
162+
#[OA\Get(
163+
path: '/subscribers/{subscriber}',
164+
description: 'Get subscriber date by id.',
165+
summary: 'Get a subscriber',
166+
tags: ['subscribers'],
167+
parameters: [
168+
new OA\Parameter(
169+
name: 'session',
170+
description: 'Session ID obtained from authentication',
171+
in: 'header',
172+
required: true,
173+
schema: new OA\Schema(type: 'string')
174+
),
175+
new OA\Parameter(
176+
name: 'id',
177+
description: 'Subscriber ID',
178+
in: 'path',
179+
required: true,
180+
schema: new OA\Schema(type: 'string')
181+
)
182+
],
183+
responses: [
184+
new OA\Response(
185+
response: 200,
186+
description: 'Success',
187+
content: new OA\JsonContent(
188+
properties: [
189+
new OA\Property(
190+
property: 'creation_date',
191+
type: 'string',
192+
format: 'date-time',
193+
example: '2017-12-16T18:44:27+00:00'
194+
),
195+
new OA\Property(property: 'email', type: 'string', example: '[email protected]'),
196+
new OA\Property(property: 'confirmed', type: 'boolean', example: false),
197+
new OA\Property(property: 'blacklisted', type: 'boolean', example: false),
198+
new OA\Property(property: 'bounced', type: 'integer', example: 0),
199+
new OA\Property(
200+
property: 'unique_id',
201+
type: 'string',
202+
example: '69f4e92cf50eafca9627f35704f030f4'
203+
),
204+
new OA\Property(property: 'html_email', type: 'boolean', example: false),
205+
new OA\Property(property: 'disabled', type: 'boolean', example: false),
206+
new OA\Property(property: 'id', type: 'integer', example: 1)
207+
]
208+
)
209+
),
210+
new OA\Response(
211+
response: 403,
212+
description: 'Failure',
213+
content: new OA\JsonContent(
214+
properties: [
215+
new OA\Property(
216+
property: 'message',
217+
type: 'string',
218+
example: 'No valid session key was provided as basic auth password.'
219+
)
220+
]
221+
)
222+
),
223+
new OA\Response(
224+
response: 404,
225+
description: 'Not Found',
226+
)
227+
]
228+
)]
229+
public function getAction(
230+
Request $request,
231+
#[MapEntity(mapping: ['id' => 'id'])] Subscriber $subscriber,
232+
SerializerInterface $serializer
233+
): JsonResponse {
234+
$this->requireAuthentication($request);
235+
236+
$json = $serializer->serialize($subscriber, 'json', [
237+
AbstractNormalizer::GROUPS => 'SubscriberListMembers',
238+
]);
239+
240+
return new JsonResponse($json, Response::HTTP_OK, [], true);
241+
}
242+
159243
/**
160244
* @param Request $request
161245
*

0 commit comments

Comments
 (0)