Skip to content

Commit e4874b2

Browse files
committed
Update: admin routes + swagger
1 parent 3f084aa commit e4874b2

File tree

5 files changed

+75
-76
lines changed

5 files changed

+75
-76
lines changed

src/Identity/Controller/AdminAttributeValueController.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Symfony\Component\HttpFoundation\Response;
2323
use Symfony\Component\Routing\Attribute\Route;
2424

25-
#[Route('/administrators/attribute-values', name: 'admin_attribute_value_')]
25+
#[Route('/administrators', name: 'admin_attribute_value_')]
2626
class AdminAttributeValueController extends BaseController
2727
{
2828
private AdminAttributeManager $attributeManager;
@@ -46,13 +46,13 @@ public function __construct(
4646
}
4747

4848
#[Route(
49-
path: '/{adminId}/{definitionId}',
49+
path: '/{adminId}/attributes/{definitionId}',
5050
name: 'create',
5151
requirements: ['adminId' => '\d+', 'definitionId' => '\d+'],
5252
methods: ['POST', 'PUT'],
5353
)]
5454
#[OA\Post(
55-
path: '/api/v2/administrators/attribute-values/{adminId}/{definitionId}',
55+
path: '/api/v2/administrators/{adminId}/attributes/{definitionId}',
5656
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
5757
'Returns created/updated admin attribute.',
5858
summary: 'Create/update an admin attribute.',
@@ -133,13 +133,13 @@ public function createOrUpdate(
133133
}
134134

135135
#[Route(
136-
path: '/{adminId}/{definitionId}',
136+
path: '/{adminId}/attributes/{definitionId}',
137137
name: 'delete',
138138
requirements: ['adminId' => '\d+', 'definitionId' => '\d+'],
139139
methods: ['DELETE'],
140140
)]
141141
#[OA\Delete(
142-
path: '/api/v2/administrators/attribute-values/{adminId}/{definitionId}',
142+
path: '/api/v2/administrators/{adminId}/attributes/{definitionId}',
143143
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
144144
'Deletes a single admin attribute.',
145145
summary: 'Deletes an attribute.',
@@ -203,9 +203,9 @@ public function delete(
203203
return $this->json(null, Response::HTTP_NO_CONTENT);
204204
}
205205

206-
#[Route('/{adminId}', name: 'get__list', requirements: ['adminId' => '\d+'], methods: ['GET'])]
206+
#[Route('/{adminId}/attributes', name: 'get_list', requirements: ['adminId' => '\d+'], methods: ['GET'])]
207207
#[OA\Get(
208-
path: '/api/v2/administrators/attribute-values/{adminId}',
208+
path: '/api/v2/administrators/{adminId}/attributes',
209209
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
210210
'Returns a JSON list of all admin attributes.',
211211
summary: 'Gets a list of all admin attributes.',
@@ -260,6 +260,11 @@ public function delete(
260260
response: 403,
261261
description: 'Failure',
262262
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
263+
),
264+
new OA\Response(
265+
response: 404,
266+
description: 'Failure',
267+
content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse')
263268
)
264269
]
265270
)]
@@ -276,18 +281,18 @@ public function getPaginated(
276281

277282
return $this->json(
278283
$this->paginatedDataProvider->getPaginatedList(
279-
$request,
280-
$this->normalizer,
281-
AdminAttributeValue::class,
282-
$filter
284+
request: $request,
285+
normalizer:$this->normalizer,
286+
className: AdminAttributeValue::class,
287+
filter: $filter
283288
),
284289
Response::HTTP_OK
285290
);
286291
}
287292

288-
#[Route('/{adminId}/{definitionId}', name: 'get_one', methods: ['GET'])]
293+
#[Route('/{adminId}/attributes/{definitionId}', name: 'get_one', methods: ['GET'])]
289294
#[OA\Get(
290-
path: '/api/v2/administrators/attribute-values/{adminId}/{definitionId}',
295+
path: '/api/v2/administrators/{adminId}/attributes/{definitionId}',
291296
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
292297
'Returns a single attribute.',
293298
summary: 'Gets admin attribute.',
@@ -355,8 +360,6 @@ public function getAttributeDefinition(
355360
adminId: $admin->getId(),
356361
attributeDefinitionId: $definition->getId()
357362
);
358-
$this->attributeManager->delete($attribute);
359-
$this->entityManager->flush();
360363

361364
return $this->json(
362365
$this->normalizer->normalize($attribute),

src/Messaging/Controller/TemplateController.php

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ public function getTemplates(Request $request): JsonResponse
105105

106106
return $this->json(
107107
$this->paginatedDataProvider->getPaginatedList(
108-
$request,
109-
$this->normalizer,
110-
Template::class,
108+
request: $request,
109+
normalizer: $this->normalizer,
110+
className: Template::class,
111111
),
112112
Response::HTTP_OK
113113
);
@@ -178,51 +178,7 @@ public function getTemplate(
178178
required: true,
179179
content: new OA\MediaType(
180180
mediaType: 'multipart/form-data',
181-
schema: new OA\Schema(
182-
required: ['title'],
183-
properties: [
184-
new OA\Property(
185-
property: 'title',
186-
type: 'string',
187-
example: 'Newsletter Template'
188-
),
189-
new OA\Property(
190-
property: 'content',
191-
type: 'string',
192-
example: '<html><body>[CONTENT]</body></html>'
193-
),
194-
new OA\Property(
195-
property: 'text',
196-
type: 'string',
197-
example: '[CONTENT]'
198-
),
199-
new OA\Property(
200-
property: 'file',
201-
description: 'Optional file upload for HTML content',
202-
type: 'string',
203-
format: 'binary'
204-
),
205-
new OA\Property(
206-
property: 'check_links',
207-
description: 'Check that all links have full URLs',
208-
type: 'boolean',
209-
example: true
210-
),
211-
new OA\Property(
212-
property: 'check_images',
213-
description: 'Check that all images have full URLs',
214-
type: 'boolean',
215-
example: false
216-
),
217-
new OA\Property(
218-
property: 'check_external_images',
219-
description: 'Check that all external images exist',
220-
type: 'boolean',
221-
example: true
222-
),
223-
],
224-
type: 'object'
225-
)
181+
schema: new OA\Schema(ref: '#/components/schemas/CreateTemplateRequest')
226182
)
227183
),
228184
tags: ['templates'],

src/Messaging/Request/CreateTemplateRequest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,47 @@
44

55
namespace PhpList\RestBundle\Messaging\Request;
66

7+
use OpenApi\Attributes as OA;
78
use PhpList\Core\Domain\Messaging\Model\Dto\CreateTemplateDto;
89
use PhpList\RestBundle\Common\Request\RequestInterface;
910
use PhpList\RestBundle\Messaging\Validator\Constraint\ContainsPlaceholder;
1011
use Symfony\Component\HttpFoundation\File\UploadedFile;
1112
use Symfony\Component\Validator\Constraints as Assert;
1213

14+
#[OA\Schema(
15+
schema: 'CreateTemplateRequest',
16+
required: ['title'],
17+
properties: [
18+
new OA\Property(property: 'title', type: 'string', example: 'Newsletter Template'),
19+
new OA\Property(property: 'content', type: 'string', example: '<html><body>[CONTENT]</body></html>'),
20+
new OA\Property(property: 'text', type: 'string', example: '[CONTENT]'),
21+
new OA\Property(
22+
property: 'file',
23+
description: 'Optional file upload for HTML content',
24+
type: 'string',
25+
format: 'binary'
26+
),
27+
new OA\Property(
28+
property: 'check_links',
29+
description: 'Check that all links have full URLs',
30+
type: 'boolean',
31+
example: true
32+
),
33+
new OA\Property(
34+
property: 'check_images',
35+
description: 'Check that all images have full URLs',
36+
type: 'boolean',
37+
example: false
38+
),
39+
new OA\Property(
40+
property: 'check_external_images',
41+
description: 'Check that all external images exist',
42+
type: 'boolean',
43+
example: true
44+
),
45+
],
46+
type: 'object'
47+
)]
1348
class CreateTemplateRequest implements RequestInterface
1449
{
1550
#[Assert\NotBlank(normalizer: 'trim')]

src/Subscription/Controller/ListMembersController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ public function getListMembers(
113113

114114
return $this->json(
115115
$this->paginatedProvider->getPaginatedList(
116-
$request,
117-
$this->subscriberNormalizer,
118-
Subscriber::class,
119-
new SubscriberFilter($list->getId())
116+
request: $request,
117+
normalizer: $this->subscriberNormalizer,
118+
className: Subscriber::class,
119+
filter: new SubscriberFilter($list->getId())
120120
),
121121
Response::HTTP_OK
122122
);
@@ -164,6 +164,11 @@ public function getListMembers(
164164
response: 403,
165165
description: 'Failure',
166166
content: new OA\JsonContent(ref: '#/components/schemas/UnauthorizedResponse')
167+
),
168+
new OA\Response(
169+
response: 404,
170+
description: 'Failure',
171+
content: new OA\JsonContent(ref: '#/components/schemas/NotFoundErrorResponse')
167172
)
168173
]
169174
)]

tests/Integration/Identity/Controller/AdminAttributeValueControllerTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCreateOrUpdateAttributeValueWithValidDataReturnsCreated(): v
2828

2929
$this->authenticatedJsonRequest(
3030
'post',
31-
'/api/v2/administrators/attribute-values/' . $adminId . '/' . $definitionId,
31+
'/api/v2/administrators/' . $adminId . '/attributes/' . $definitionId,
3232
[],
3333
[],
3434
[],
@@ -54,7 +54,7 @@ public function testUpdateAttributeValueReturnsOk(): void
5454

5555
$this->authenticatedJsonRequest(
5656
'post',
57-
'/api/v2/administrators/attribute-values/' . $adminId . '/' . $definitionId,
57+
'/api/v2/administrators/' . $adminId . '/attributes/' . $definitionId,
5858
[],
5959
[],
6060
[],
@@ -78,7 +78,7 @@ public function testDeleteAttributeValueReturnsNoContent(): void
7878

7979
$this->authenticatedJsonRequest(
8080
'delete',
81-
'/api/v2/administrators/attribute-values/' . $adminId . '/' . $definitionId
81+
'/api/v2/administrators/' . $adminId . '/attributes/' . $definitionId
8282
);
8383
$this->assertHttpNoContent();
8484
}
@@ -92,7 +92,7 @@ public function testGetPaginatedReturnsOk(): void
9292
]);
9393
$adminId = 1;
9494

95-
$this->authenticatedJsonRequest('get', '/api/v2/administrators/attribute-values/' . $adminId);
95+
$this->authenticatedJsonRequest('get', '/api/v2/administrators/' . $adminId . '/attributes');
9696
$this->assertHttpOkay();
9797
$data = $this->getDecodedJsonResponseContent();
9898
self::assertArrayHasKey('items', $data);
@@ -112,7 +112,7 @@ public function testGetAttributeValueReturnsData(): void
112112

113113
$this->authenticatedJsonRequest(
114114
'get',
115-
'/api/v2/administrators/attribute-values/' . $adminId . '/' . $definitionId
115+
'/api/v2/administrators/' . $adminId . '/attributes/' . $definitionId
116116
);
117117
$this->assertHttpOkay();
118118
$data = $this->getDecodedJsonResponseContent();
@@ -126,7 +126,7 @@ public function testGetAttributeValueNotFound(): void
126126

127127
$this->authenticatedJsonRequest(
128128
'get',
129-
'/api/v2/administrators/attribute-values/' . $adminId . '/999999'
129+
'/api/v2/administrators/' . $adminId . '/attributes/999999'
130130
);
131131
$this->assertHttpNotFound();
132132
}
@@ -142,7 +142,7 @@ public function testCreateAttributeValueWithInvalidJsonReturns400(): void
142142

143143
$this->authenticatedJsonRequest(
144144
'post',
145-
'/api/v2/administrators/attribute-values/' . $adminId . '/' . $definitionId,
145+
'/api/v2/administrators/' . $adminId . '/attributes/' . $definitionId,
146146
[],
147147
[],
148148
[],
@@ -158,7 +158,7 @@ public function testCreateAttributeValueWithInvalidDefinitionIdReturns404(): voi
158158

159159
$this->authenticatedJsonRequest(
160160
'post',
161-
'/api/v2/administrators/attribute-values/' . $adminId . '/999999',
161+
'/api/v2/administrators/' . $adminId . '/attributes/999999',
162162
[],
163163
[],
164164
[],
@@ -174,7 +174,7 @@ public function testCreateAttributeValueWithInvalidAdminIdReturns404(): void
174174

175175
$this->authenticatedJsonRequest(
176176
'post',
177-
'/api/v2/administrators/attribute-values/999999/' . $definitionId,
177+
'/api/v2/administrators/999999/attributes/' . $definitionId,
178178
[],
179179
[],
180180
[],

0 commit comments

Comments
 (0)