Skip to content

Commit 58b8346

Browse files
committed
ISSUE-344: api doc
1 parent d93647d commit 58b8346

File tree

7 files changed

+22
-86
lines changed

7 files changed

+22
-86
lines changed

composer.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"require": {
3333
"php": "^8.1",
34-
"phplist/core": "dev-ISSUE-337",
34+
"phplist/core": "5.0.0-alpha1",
3535
"friendsofsymfony/rest-bundle": "*",
3636
"symfony/test-pack": "^1.0",
3737
"symfony/process": "^6.4",
@@ -85,9 +85,6 @@
8585
]
8686
},
8787
"extra": {
88-
"branch-alias": {
89-
"dev-ISSUE-337": "5.0.x-dev"
90-
},
9188
"symfony-app-dir": "bin",
9289
"symfony-bin-dir": "bin",
9390
"symfony-var-dir": "var",

docs/.gitkeep

Whitespace-only changes.

openapi.yaml

-55
This file was deleted.

src/Controller/ListController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ public function deleteList(
267267
return new JsonResponse(null, Response::HTTP_NO_CONTENT, [], false);
268268
}
269269

270-
#[Route('/lists/{id}/members', name: 'get_subscriber_from_list', methods: ['GET'])]
270+
#[Route('/lists/{id}/subscribers', name: 'get_subscriber_from_list', methods: ['GET'])]
271271
#[OA\Get(
272-
path: '/lists/{list}/members',
272+
path: '/lists/{list}/subscribers',
273273
description: 'Returns a JSON list of all subscribers for a subscriber list.',
274-
summary: 'Gets a list of all subscribers (members) of a subscriber list.',
274+
summary: 'Gets a list of all subscribers of a subscriber list.',
275275
tags: ['lists'],
276276
parameters: [
277277
new OA\Parameter(

src/Controller/SubscriberController.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(
3939

4040
#[Route('/subscribers', name: 'create_subscriber', methods: ['POST'])]
4141
#[OA\Post(
42-
path: '/subscriber',
42+
path: '/subscribers',
4343
description: 'Creates a new subscriber (if there is no subscriber with the given email address yet).',
4444
summary: 'Create a subscriber',
4545
requestBody: new OA\RequestBody(
@@ -49,10 +49,8 @@ public function __construct(
4949
required: ['email'],
5050
properties: [
5151
new OA\Property(property: 'email', type: 'string', format: 'string', example: 'admin@example.com'),
52-
new OA\Property(property: 'confirmed', type: 'boolean', example: false),
53-
new OA\Property(property: 'blacklisted', type: 'boolean', example: false),
52+
new OA\Property(property: 'request_confirmation', type: 'boolean', example: false),
5453
new OA\Property(property: 'html_email', type: 'boolean', example: false),
55-
new OA\Property(property: 'disabled', type: 'boolean', example: false)
5654
]
5755
)
5856
),
@@ -140,13 +138,13 @@ public function postAction(Request $request, SerializerInterface $serializer): J
140138
if ($this->subscriberRepository->findOneByEmail($email) !== null) {
141139
throw new ConflictHttpException('This resource already exists.', null, 1513439108);
142140
}
143-
// @phpstan-ignore-next-line
141+
$confirmed = (bool)$data->get('request_confirmation', true);
144142
$subscriber = new Subscriber();
145143
$subscriber->setEmail($email);
146-
$subscriber->setConfirmed((bool)$data->get('confirmed', false));
147-
$subscriber->setBlacklisted((bool)$data->get('blacklisted', false));
144+
$subscriber->setConfirmed(!$confirmed);
145+
$subscriber->setBlacklisted(false);
148146
$subscriber->setHtmlEmail((bool)$data->get('html_email', true));
149-
$subscriber->setDisabled((bool)$data->get('disabled', false));
147+
$subscriber->setDisabled(false);
150148

151149
$this->subscriberRepository->save($subscriber);
152150

@@ -173,7 +171,7 @@ private function validateSubscriber(Request $request): void
173171
$invalidFields[] = 'email';
174172
}
175173

176-
$booleanFields = ['confirmed', 'blacklisted', 'html_email', 'disabled'];
174+
$booleanFields = ['request_confirmation', 'html_email'];
177175
foreach ($booleanFields as $fieldKey) {
178176
if ($request->getPayload()->get($fieldKey) !== null
179177
&& !is_bool($request->getPayload()->get($fieldKey))

tests/Integration/Controller/ListControllerTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function testGetListMembersForExistingListWithoutSessionKeyReturnsForbidd
180180
{
181181
$this->loadFixtures([SubscriberListFixture::class]);
182182

183-
self::getClient()->request('get', '/api/v2/lists/1/members');
183+
self::getClient()->request('get', '/api/v2/lists/1/subscribers');
184184

185185
$this->assertHttpForbidden();
186186
}
@@ -195,7 +195,7 @@ public function testGetListMembersForExistingListWithExpiredSessionKeyReturnsFor
195195

196196
self::getClient()->request(
197197
'get',
198-
'/api/v2/lists/1/members',
198+
'/api/v2/lists/1/subscribers',
199199
[],
200200
[],
201201
['PHP_AUTH_USER' => 'unused', 'PHP_AUTH_PW' => 'cfdf64eecbbf336628b0f3071adba763']
@@ -206,7 +206,7 @@ public function testGetListMembersForExistingListWithExpiredSessionKeyReturnsFor
206206

207207
public function testGetListMembersWithCurrentSessionKeyForInexistentListReturnsNotFoundStatus()
208208
{
209-
$this->authenticatedJsonRequest('get', '/api/v2/lists/999/members');
209+
$this->authenticatedJsonRequest('get', '/api/v2/lists/999/subscribers');
210210

211211
$this->assertHttpNotFound();
212212
}
@@ -215,7 +215,7 @@ public function testGetListMembersWithCurrentSessionKeyForExistingListReturnsOka
215215
{
216216
$this->loadFixtures([SubscriberListFixture::class]);
217217

218-
$this->authenticatedJsonRequest('get', '/api/v2/lists/1/members');
218+
$this->authenticatedJsonRequest('get', '/api/v2/lists/1/subscribers');
219219

220220
$this->assertHttpOkay();
221221
}
@@ -224,7 +224,7 @@ public function testGetListMembersWithCurrentSessionKeyForExistingListWithoutSub
224224
{
225225
$this->loadFixtures([SubscriberListFixture::class]);
226226

227-
$this->authenticatedJsonRequest('get', '/api/v2/lists/1/members');
227+
$this->authenticatedJsonRequest('get', '/api/v2/lists/1/subscribers');
228228

229229
$this->assertJsonResponseContentEquals([]);
230230
}
@@ -233,7 +233,7 @@ public function testGetListMembersWithCurrentSessionKeyForExistingListWithSubscr
233233
{
234234
$this->loadFixtures([SubscriberListFixture::class, SubscriberFixture::class, SubscriptionFixture::class]);
235235

236-
$this->authenticatedJsonRequest('get', '/api/v2/lists/2/members');
236+
$this->authenticatedJsonRequest('get', '/api/v2/lists/2/subscribers');
237237

238238
$this->assertJsonResponseContentEquals(
239239
[

tests/Integration/Controller/SubscriberControllerTest.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,10 @@ public static function invalidSubscriberDataProvider(): array
106106
'email is an empty string' => [['email' => '']],
107107
'email is invalid string' => [['email' => 'coffee and cigarettes']],
108108
'email as boolean' => [['email' => true]],
109-
'confirmed as integer' => [['email' => 'kate@example.com', 'confirmed' => 1]],
110-
'confirmed as string' => [['email' => 'kate@example.com', 'confirmed' => 'yes']],
111-
'blacklisted as integer' => [['email' => 'kate@example.com', 'blacklisted' => 1]],
112-
'blacklisted as string' => [['email' => 'kate@example.com', 'blacklisted' => 'yes']],
113109
'html_email as integer' => [['email' => 'kate@example.com', 'html_email' => 1]],
114110
'html_email as string' => [['email' => 'kate@example.com', 'html_email' => 'yes']],
115-
'disabled as integer' => [['email' => 'kate@example.com', 'disabled' => 1]],
116-
'disabled as string' => [['email' => 'kate@example.com', 'disabled' => 'yes']],
111+
'request_confirmation as string' => [['email' => 'kate@example.com', 'request_confirmation' => 'needed']],
112+
'disabled as string' => [['email' => 'kate@example.com', 'request_confirmation' => 1]],
117113
];
118114
}
119115

@@ -144,9 +140,9 @@ public function testPostSubscribersWithValidSessionKeyAssignsProvidedSubscriberD
144140
$responseContent = $this->getDecodedJsonResponseContent();
145141

146142
static::assertSame($email, $responseContent['email']);
147-
static::assertTrue($responseContent['confirmed']);
148-
static::assertTrue($responseContent['blacklisted']);
143+
static::assertFalse($responseContent['confirmed']);
144+
static::assertFalse($responseContent['blacklisted']);
149145
static::assertTrue($responseContent['html_email']);
150-
static::assertTrue($responseContent['disabled']);
146+
static::assertFalse($responseContent['disabled']);
151147
}
152148
}

0 commit comments

Comments
 (0)