Skip to content

Commit 1aa05c3

Browse files
tischsoicbarw4
authored andcommitted
add missing Api Platform attributes in Location/ and ObjectState/
1 parent 308911c commit 1aa05c3

File tree

5 files changed

+369
-70
lines changed

5 files changed

+369
-70
lines changed

src/lib/Server/Controller/Location/LocationCreateController.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use ApiPlatform\Metadata\Delete;
1111
use ApiPlatform\Metadata\Get;
1212
use ApiPlatform\Metadata\Patch;
13+
use ApiPlatform\Metadata\Post;
1314
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
1415
use ApiPlatform\OpenApi\Model;
1516
use Ibexa\Contracts\Core\Repository\ContentService;
@@ -27,6 +28,88 @@
2728
use Symfony\Component\HttpFoundation\Request;
2829
use Symfony\Component\HttpFoundation\Response;
2930

31+
#[Post(
32+
uriTemplate: '/content/objects/{contentId}/locations',
33+
name: 'Create new Location for content item',
34+
extraProperties: [OpenApiFactory::OVERRIDE_OPENAPI_RESPONSES => false],
35+
openapi: new Model\Operation(
36+
summary: 'Creates a new Location for the given content item.',
37+
tags: [
38+
'Objects',
39+
],
40+
parameters: [
41+
new Model\Parameter(
42+
name: 'Accept',
43+
in: 'header',
44+
required: true,
45+
description: 'If set, the new Location is returned in XML or JSON format.',
46+
schema: [
47+
'type' => 'string',
48+
],
49+
),
50+
new Model\Parameter(
51+
name: 'Content-Type',
52+
in: 'header',
53+
required: true,
54+
description: 'The LocationCreate schema encoded in XML or JSON format.',
55+
schema: [
56+
'type' => 'string',
57+
],
58+
),
59+
new Model\Parameter(
60+
name: 'contentId',
61+
in: 'path',
62+
required: true,
63+
schema: [
64+
'type' => 'string',
65+
],
66+
),
67+
],
68+
requestBody: new Model\RequestBody(
69+
content: new \ArrayObject([
70+
'application/vnd.ibexa.api.LocationCreate+xml' => [
71+
'schema' => [
72+
'$ref' => '#/components/schemas/LocationCreate',
73+
],
74+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/locations/POST/LocationCreate.xml.example',
75+
],
76+
'application/vnd.ibexa.api.LocationCreate+json' => [
77+
'schema' => [
78+
'$ref' => '#/components/schemas/LocationCreateWrapper',
79+
],
80+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/locations/POST/LocationCreate.json.example',
81+
],
82+
]),
83+
),
84+
responses: [
85+
Response::HTTP_CREATED => [
86+
'content' => [
87+
'application/vnd.ibexa.api.Location+xml' => [
88+
'schema' => [
89+
'$ref' => '#/components/schemas/Location',
90+
],
91+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/locations/POST/Location.xml.example',
92+
],
93+
'application/vnd.ibexa.api.Location+json' => [
94+
'schema' => [
95+
'$ref' => '#/components/schemas/LocationWrapper',
96+
],
97+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/locations/POST/Location.json.example',
98+
],
99+
],
100+
],
101+
Response::HTTP_BAD_REQUEST => [
102+
'description' => 'Error - the input does not match the input schema definition.',
103+
],
104+
Response::HTTP_UNAUTHORIZED => [
105+
'description' => 'Error - the user is not authorized to create this Location.',
106+
],
107+
Response::HTTP_FORBIDDEN => [
108+
'description' => 'Error - a Location under the given parent ID already exists.',
109+
],
110+
],
111+
),
112+
)]
30113
class LocationCreateController extends LocationBaseController
31114
{
32115
/**

src/lib/Server/Controller/Location/LocationForContentListController.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use ApiPlatform\Metadata\Delete;
1111
use ApiPlatform\Metadata\Get;
1212
use ApiPlatform\Metadata\Patch;
13+
use ApiPlatform\Metadata\Post;
1314
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
1415
use ApiPlatform\OpenApi\Model;
1516
use Ibexa\Contracts\Core\Repository\ContentService;
@@ -27,6 +28,68 @@
2728
use Symfony\Component\HttpFoundation\Request;
2829
use Symfony\Component\HttpFoundation\Response;
2930

31+
#[Get(
32+
uriTemplate: '/content/objects/{contentId}/locations',
33+
name: 'Get Locations for content item',
34+
openapi: new Model\Operation(
35+
summary: 'Loads all Locations for the given content item.',
36+
tags: [
37+
'Objects',
38+
],
39+
parameters: [
40+
new Model\Parameter(
41+
name: 'Accept',
42+
in: 'header',
43+
required: true,
44+
description: 'If set, the Location list is returned in XML or JSON format.',
45+
schema: [
46+
'type' => 'string',
47+
],
48+
),
49+
new Model\Parameter(
50+
name: 'If-None-Match',
51+
in: 'header',
52+
required: true,
53+
description: 'ETag',
54+
schema: [
55+
'type' => 'string',
56+
],
57+
),
58+
new Model\Parameter(
59+
name: 'contentId',
60+
in: 'path',
61+
required: true,
62+
schema: [
63+
'type' => 'string',
64+
],
65+
),
66+
],
67+
responses: [
68+
Response::HTTP_OK => [
69+
'content' => [
70+
'application/vnd.ibexa.api.LocationList+xml' => [
71+
'schema' => [
72+
'$ref' => '#/components/schemas/LocationList',
73+
],
74+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/locations/GET/LocationList.xml.example',
75+
],
76+
'application/vnd.ibexa.api.LocationList+json' => [
77+
'schema' => [
78+
'$ref' => '#/components/schemas/LocationListWrapper',
79+
],
80+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/locations/GET/LocationList.json.example',
81+
],
82+
],
83+
],
84+
Response::HTTP_UNAUTHORIZED => [
85+
'description' => 'Error - the user is not authorized to read this content item.',
86+
],
87+
Response::HTTP_NOT_FOUND => [
88+
'description' => 'Error - the content item with the given ID does not exist.',
89+
],
90+
],
91+
),
92+
)]
3093
class LocationForContentListController extends LocationBaseController
3194
{
3295
/**
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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\ObjectState;
9+
10+
use ApiPlatform\Metadata\Delete;
11+
use ApiPlatform\Metadata\Get;
12+
use ApiPlatform\Metadata\Patch;
13+
use ApiPlatform\Metadata\Post;
14+
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
15+
use ApiPlatform\OpenApi\Model;
16+
use Ibexa\Contracts\Core\Repository\ContentService;
17+
use Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException;
18+
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
19+
use Ibexa\Contracts\Core\Repository\ObjectStateService;
20+
use Ibexa\Contracts\Core\Repository\Values\Content\Language;
21+
use Ibexa\Rest\Message;
22+
use Ibexa\Rest\Server\Controller as RestController;
23+
use Ibexa\Rest\Server\Exceptions\ForbiddenException;
24+
use Ibexa\Rest\Server\Values;
25+
use Ibexa\Rest\Values\ContentObjectStates;
26+
use Ibexa\Rest\Values\RestObjectState;
27+
use JMS\TranslationBundle\Annotation\Ignore;
28+
use Symfony\Component\HttpFoundation\Request;
29+
use Symfony\Component\HttpFoundation\Response;
30+
31+
#[Get(
32+
uriTemplate: '/content/objects/{contentId}/objectstates',
33+
name: 'Get Object states of content item',
34+
openapi: new Model\Operation(
35+
summary: 'Returns the Object states of a content item',
36+
tags: [
37+
'Objects',
38+
],
39+
parameters: [
40+
new Model\Parameter(
41+
name: 'Accept',
42+
in: 'header',
43+
required: true,
44+
description: 'If set, the Object states are returned in XML or JSON format.',
45+
schema: [
46+
'type' => 'string',
47+
],
48+
),
49+
new Model\Parameter(
50+
name: 'If-None-Match',
51+
in: 'header',
52+
required: true,
53+
description: 'ETag',
54+
schema: [
55+
'type' => 'string',
56+
],
57+
),
58+
new Model\Parameter(
59+
name: 'contentId',
60+
in: 'path',
61+
required: true,
62+
schema: [
63+
'type' => 'string',
64+
],
65+
),
66+
],
67+
responses: [
68+
Response::HTTP_OK => [
69+
'description' => 'OK - returns the Object state.',
70+
'content' => [
71+
'application/vnd.ibexa.api.ContentObjectStates+xml' => [
72+
'schema' => [
73+
'$ref' => '#/components/schemas/ContentObjectStates',
74+
],
75+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/objectstates/PATCH/ContentObjectStates.response.xml.example',
76+
],
77+
'application/vnd.ibexa.api.ContentObjectStates+json' => [
78+
'schema' => [
79+
'$ref' => '#/components/schemas/ContentObjectStatesWrapper',
80+
],
81+
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/objectstates/GET/ContentObjectStates.json.example',
82+
],
83+
],
84+
],
85+
Response::HTTP_NOT_FOUND => [
86+
'description' => 'Error - The content item does not exist.',
87+
],
88+
],
89+
),
90+
)]
91+
class ObjectStatesForContentListController extends RestController
92+
{
93+
protected ObjectStateService $objectStateService;
94+
95+
protected ContentService $contentService;
96+
97+
public function __construct(ObjectStateService $objectStateService, ContentService $contentService)
98+
{
99+
$this->objectStateService = $objectStateService;
100+
$this->contentService = $contentService;
101+
}
102+
103+
/**
104+
* Returns the object states of content.
105+
*
106+
* @param $contentId
107+
*
108+
* @return \Ibexa\Rest\Values\ContentObjectStates
109+
*/
110+
public function getObjectStatesForContent($contentId)
111+
{
112+
$groups = $this->objectStateService->loadObjectStateGroups();
113+
$contentInfo = $this->contentService->loadContentInfo($contentId);
114+
115+
$contentObjectStates = [];
116+
117+
foreach ($groups as $group) {
118+
try {
119+
$state = $this->objectStateService->getContentState($contentInfo, $group);
120+
$contentObjectStates[] = new RestObjectState($state, $group->id);
121+
} catch (NotFoundException $e) {
122+
// Do nothing
123+
}
124+
}
125+
126+
return new ContentObjectStates($contentObjectStates);
127+
}
128+
}

0 commit comments

Comments
 (0)