Skip to content

Commit eb03daf

Browse files
tischsoicbarw4
authored andcommitted
split controllers - one action per controller: URLWildcard without services
1 parent 3c2c53f commit eb03daf

File tree

5 files changed

+404
-4
lines changed

5 files changed

+404
-4
lines changed

src/bundle/Resources/config/routing.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,24 +761,24 @@ ibexa.rest.restore_trash_item:
761761

762762
ibexa.rest.list_url_wildcards:
763763
path: /content/urlwildcards
764-
controller: Ibexa\Rest\Server\Controller\URLWildcard::listURLWildcards
764+
controller: Ibexa\Rest\Server\Controller\URLWildcard\URLWildcardListController::listURLWildcards
765765
methods: [GET]
766766

767767
ibexa.rest.create_url_wildcard:
768768
path: /content/urlwildcards
769-
controller: Ibexa\Rest\Server\Controller\URLWildcard::createURLWildcard
769+
controller: Ibexa\Rest\Server\Controller\URLWildcard\URLWildcardCreateController::createURLWildcard
770770
methods: [POST]
771771

772772
ibexa.rest.load_url_wildcard:
773773
path: /content/urlwildcards/{urlWildcardId}
774-
controller: Ibexa\Rest\Server\Controller\URLWildcard::loadURLWildcard
774+
controller: Ibexa\Rest\Server\Controller\URLWildcard\URLWildcardLoadByIdController::loadURLWildcard
775775
methods: [GET]
776776
requirements:
777777
urlWildcardId: \d+
778778

779779
ibexa.rest.delete_url_wildcard:
780780
path: /content/urlwildcards/{urlWildcardId}
781-
controller: Ibexa\Rest\Server\Controller\URLWildcard::deleteURLWildcard
781+
controller: Ibexa\Rest\Server\Controller\URLWildcard\URLWildcardDeleteController::deleteURLWildcard
782782
methods: [DELETE]
783783
requirements:
784784
urlWildcardId: \d+
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
8+
namespace Ibexa\Rest\Server\Controller\URLWildcard;
9+
10+
use ApiPlatform\Metadata\Delete;
11+
use ApiPlatform\Metadata\Get;
12+
use ApiPlatform\Metadata\Post;
13+
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
14+
use ApiPlatform\OpenApi\Model;
15+
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
16+
use Ibexa\Contracts\Core\Repository\URLWildcardService;
17+
use Ibexa\Rest\Message;
18+
use Ibexa\Rest\Server\Controller as RestController;
19+
use Ibexa\Rest\Server\Exceptions\ForbiddenException;
20+
use Ibexa\Rest\Server\Values;
21+
use JMS\TranslationBundle\Annotation\Ignore;
22+
use Symfony\Component\HttpFoundation\Request;
23+
use Symfony\Component\HttpFoundation\Response;
24+
25+
#[Post(
26+
uriTemplate: '/content/urlwildcards',
27+
name: 'Create URL wildcard',
28+
extraProperties: [OpenApiFactory::OVERRIDE_OPENAPI_RESPONSES => false],
29+
openapi: new Model\Operation(
30+
summary: 'Creates a new URL wildcard.',
31+
tags: [
32+
'Url Wildcard',
33+
],
34+
parameters: [
35+
new Model\Parameter(
36+
name: 'Accept',
37+
in: 'header',
38+
required: true,
39+
description: 'If set, the new URL wildcard is returned in XML or JSON format.',
40+
schema: [
41+
'type' => 'string',
42+
],
43+
),
44+
new Model\Parameter(
45+
name: 'Content-Type',
46+
in: 'header',
47+
required: true,
48+
description: 'The URL Wildcard input schema encoded in XML or JSON format.',
49+
schema: [
50+
'type' => 'string',
51+
],
52+
),
53+
],
54+
requestBody: new Model\RequestBody(
55+
content: new \ArrayObject([
56+
'application/vnd.ibexa.api.UrlWildcardCreate+xml' => [
57+
'schema' => [
58+
'$ref' => '#/components/schemas/UrlWildcardCreate',
59+
],
60+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/urlwildcards/POST/UrlWildcardCreate.xml.example',
61+
],
62+
'application/vnd.ibexa.api.UrlWildcardCreate+json' => [
63+
'schema' => [
64+
'$ref' => '#/components/schemas/UrlWildcardCreateWrapper',
65+
],
66+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/urlwildcards/POST/UrlWildcardCreate.json.example',
67+
],
68+
]),
69+
),
70+
responses: [
71+
Response::HTTP_CREATED => [
72+
'description' => 'URL wildcard created.',
73+
'content' => [
74+
'application/vnd.ibexa.api.UrlWildcard+xml' => [
75+
'schema' => [
76+
'$ref' => '#/components/schemas/UrlWildcard',
77+
],
78+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/urlwildcards/wildcard_id/GET/UrlWildcard.xml.example',
79+
],
80+
'application/vnd.ibexa.api.UrlWildcard+json' => [
81+
'schema' => [
82+
'$ref' => '#/components/schemas/UrlWildcardWrapper',
83+
],
84+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/urlwildcards/wildcard_id/GET/UrlWildcard.json.example',
85+
],
86+
],
87+
],
88+
Response::HTTP_BAD_REQUEST => [
89+
'description' => 'Error - The input does not match the input schema definition.',
90+
],
91+
Response::HTTP_UNAUTHORIZED => [
92+
'description' => 'Error - The user is not authorized to create a URL wildcard.',
93+
],
94+
Response::HTTP_FORBIDDEN => [
95+
'description' => 'Error - A URL wildcard with the same identifier already exists.',
96+
],
97+
],
98+
),
99+
)]
100+
class URLWildcardCreateController extends RestController
101+
{
102+
public function __construct(
103+
protected URLWildcardService $urlWildcardService
104+
) {
105+
}
106+
107+
/**
108+
* Creates a new URL wildcard.
109+
*
110+
* @throws \Ibexa\Rest\Server\Exceptions\ForbiddenException
111+
*
112+
* @return \Ibexa\Rest\Server\Values\CreatedURLWildcard
113+
*/
114+
public function createURLWildcard(Request $request)
115+
{
116+
$urlWildcardCreate = $this->inputDispatcher->parse(
117+
new Message(
118+
['Content-Type' => $request->headers->get('Content-Type')],
119+
$request->getContent()
120+
)
121+
);
122+
123+
try {
124+
$createdURLWildcard = $this->urlWildcardService->create(
125+
$urlWildcardCreate['sourceUrl'],
126+
$urlWildcardCreate['destinationUrl'],
127+
$urlWildcardCreate['forward']
128+
);
129+
} catch (InvalidArgumentException $e) {
130+
throw new ForbiddenException(/** @Ignore */ $e->getMessage());
131+
}
132+
133+
return new Values\CreatedURLWildcard(
134+
[
135+
'urlWildcard' => $createdURLWildcard,
136+
]
137+
);
138+
}
139+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
8+
namespace Ibexa\Rest\Server\Controller\URLWildcard;
9+
10+
use ApiPlatform\Metadata\Delete;
11+
use ApiPlatform\Metadata\Get;
12+
use ApiPlatform\Metadata\Post;
13+
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
14+
use ApiPlatform\OpenApi\Model;
15+
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
16+
use Ibexa\Contracts\Core\Repository\URLWildcardService;
17+
use Ibexa\Rest\Message;
18+
use Ibexa\Rest\Server\Controller as RestController;
19+
use Ibexa\Rest\Server\Exceptions\ForbiddenException;
20+
use Ibexa\Rest\Server\Values;
21+
use JMS\TranslationBundle\Annotation\Ignore;
22+
use Symfony\Component\HttpFoundation\Request;
23+
use Symfony\Component\HttpFoundation\Response;
24+
25+
#[Delete(
26+
uriTemplate: '/content/urlwildcards/{wildcardId}',
27+
name: 'Delete URL wildcard',
28+
openapi: new Model\Operation(
29+
summary: 'Deletes the given URL wildcard.',
30+
tags: [
31+
'Url Wildcard',
32+
],
33+
parameters: [
34+
new Model\Parameter(
35+
name: 'wildcardId',
36+
in: 'path',
37+
required: true,
38+
schema: [
39+
'type' => 'string',
40+
],
41+
),
42+
],
43+
responses: [
44+
Response::HTTP_NO_CONTENT => [
45+
'description' => 'No Content - URL wildcard deleted.',
46+
],
47+
Response::HTTP_UNAUTHORIZED => [
48+
'description' => 'Error - The user is not authorized to delete a URL wildcard.',
49+
],
50+
Response::HTTP_NOT_FOUND => [
51+
'description' => 'Error - The URL wildcard does not exist.',
52+
],
53+
],
54+
),
55+
)]
56+
class URLWildcardDeleteController extends RestController
57+
{
58+
public function __construct(
59+
protected URLWildcardService $urlWildcardService
60+
) {
61+
}
62+
63+
/**
64+
* The given URL wildcard is deleted.
65+
*
66+
* @param $urlWildcardId
67+
*
68+
* @return \Ibexa\Rest\Server\Values\NoContent
69+
*/
70+
public function deleteURLWildcard($urlWildcardId)
71+
{
72+
$this->urlWildcardService->remove(
73+
$this->urlWildcardService->load($urlWildcardId)
74+
);
75+
76+
return new Values\NoContent();
77+
}
78+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
8+
namespace Ibexa\Rest\Server\Controller\URLWildcard;
9+
10+
use ApiPlatform\Metadata\Delete;
11+
use ApiPlatform\Metadata\Get;
12+
use ApiPlatform\Metadata\Post;
13+
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
14+
use ApiPlatform\OpenApi\Model;
15+
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
16+
use Ibexa\Contracts\Core\Repository\URLWildcardService;
17+
use Ibexa\Rest\Message;
18+
use Ibexa\Rest\Server\Controller as RestController;
19+
use Ibexa\Rest\Server\Exceptions\ForbiddenException;
20+
use Ibexa\Rest\Server\Values;
21+
use JMS\TranslationBundle\Annotation\Ignore;
22+
use Symfony\Component\HttpFoundation\Request;
23+
use Symfony\Component\HttpFoundation\Response;
24+
25+
#[Get(
26+
uriTemplate: '/content/urlwildcards',
27+
name: 'List URL wildcards',
28+
openapi: new Model\Operation(
29+
summary: 'Returns a list of URL wildcards.',
30+
tags: [
31+
'Url Wildcard',
32+
],
33+
parameters: [
34+
new Model\Parameter(
35+
name: 'Accept',
36+
in: 'header',
37+
required: true,
38+
description: 'If set, the URL wildcard is returned in XML or JSON format.',
39+
schema: [
40+
'type' => 'string',
41+
],
42+
),
43+
],
44+
responses: [
45+
Response::HTTP_OK => [
46+
'description' => 'OK - returns a list of URL wildcards.',
47+
'content' => [
48+
'application/vnd.ibexa.api.UrlWildcardList+xml' => [
49+
'schema' => [
50+
'$ref' => '#/components/schemas/UrlWildcardList',
51+
],
52+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/urlwildcards/GET/UrlWildcardList.xml.example',
53+
],
54+
'application/vnd.ibexa.api.UrlWildcardList+json' => [
55+
'schema' => [
56+
'$ref' => '#/components/schemas/UrlWildcardListWrapper',
57+
],
58+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/urlwildcards/GET/UrlWildcardList.json.example',
59+
],
60+
],
61+
],
62+
Response::HTTP_UNAUTHORIZED => [
63+
'description' => 'Error - The user has no permission to read URL wildcards.',
64+
],
65+
],
66+
),
67+
)]
68+
class URLWildcardListController extends RestController
69+
{
70+
public function __construct(
71+
protected URLWildcardService $urlWildcardService
72+
) {
73+
}
74+
75+
/**
76+
* Returns the list of URL wildcards.
77+
*
78+
* @return \Ibexa\Rest\Server\Values\URLWildcardList
79+
*/
80+
public function listURLWildcards()
81+
{
82+
return new Values\URLWildcardList(
83+
$this->urlWildcardService->loadAll()
84+
);
85+
}
86+
}

0 commit comments

Comments
 (0)