Skip to content

Commit 980696c

Browse files
committed
Add public page to return list data
1 parent f03fe55 commit 980696c

3 files changed

Lines changed: 70 additions & 3 deletions

File tree

src/Subscription/Controller/SubscribePageController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ className: SubscribePage::class,
122122
name: 'php-auth-pw',
123123
description: 'Session key obtained from login',
124124
in: 'header',
125-
required: true,
125+
required: false,
126126
schema: new OA\Schema(type: 'string')
127127
),
128128
new OA\Parameter(

src/Subscription/Controller/SubscriberListController.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,73 @@ public function getList(
181181
return $this->json($this->normalizer->normalize($list), Response::HTTP_OK);
182182
}
183183

184+
#[Route('/{listId}/public', name: 'get_one_public', requirements: ['listId' => '\d+'], methods: ['GET'])]
185+
#[OA\Get(
186+
path: '/api/v2/lists/{listId}/public',
187+
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
188+
'Returns a single subscriber list with specified ID.',
189+
summary: 'Gets a subscriber list.',
190+
tags: ['lists'],
191+
parameters: [
192+
new OA\Parameter(
193+
name: 'listId',
194+
description: 'List ID',
195+
in: 'path',
196+
required: true,
197+
schema: new OA\Schema(type: 'string')
198+
),
199+
],
200+
responses: [
201+
new OA\Response(
202+
response: 200,
203+
description: 'Success',
204+
content: [
205+
'application/json' => new OA\MediaType(
206+
schema: new OA\Schema(
207+
properties: [
208+
new OA\Property(property: 'id', type: 'integer', example: 1),
209+
new OA\Property(property: 'name', type: 'string', example: 'Newsletter subscribers'),
210+
new OA\Property(
211+
property: 'description',
212+
type: 'string',
213+
example: 'Main public list',
214+
nullable: true
215+
)
216+
],
217+
type: 'object'
218+
)
219+
)
220+
]
221+
),
222+
new OA\Response(
223+
response: 404,
224+
description: 'Failure',
225+
content: new OA\JsonContent(
226+
properties: [
227+
new OA\Property(
228+
property: 'message',
229+
type: 'string',
230+
example: 'There is no list with that ID.'
231+
)
232+
],
233+
type: 'object'
234+
)
235+
),
236+
]
237+
)]
238+
public function getPublicList(#[MapEntity(mapping: ['listId' => 'id'])] ?SubscriberList $list = null): JsonResponse
239+
{
240+
if (!$list) {
241+
throw $this->createNotFoundException('Subscriber list not found.');
242+
}
243+
244+
return $this->json([
245+
'id' => $list->getId(),
246+
'name' => $list->getName(),
247+
'description' => $list->getDescription(),
248+
], Response::HTTP_OK);
249+
}
250+
184251
#[Route('/{listId}', name: 'delete', requirements: ['listId' => '\d+'], methods: ['DELETE'])]
185252
#[OA\Delete(
186253
path: '/api/v2/lists/{listId}',

tests/Integration/Subscription/Controller/SubscribePageControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public function testControllerIsAvailableViaContainer(): void
2020
);
2121
}
2222

23-
public function testGetSubscribePageWithoutSessionReturnsForbidden(): void
23+
public function testGetSubscribePageWithoutSessionReturnsPageIfItIsActive(): void
2424
{
2525
$this->loadFixtures([AdministratorFixture::class, SubscribePageFixture::class]);
2626

2727
self::getClient()->request('GET', '/api/v2/subscribe-pages/1');
28-
$this->assertHttpForbidden();
28+
$this->assertHttpOkay();
2929
}
3030

3131
public function testGetSubscribePageWithSessionReturnsPage(): void

0 commit comments

Comments
 (0)