Skip to content

Commit 6071dad

Browse files
authored
[Object Bricks][Config]: Endpoints part 2 (#1674)
* add first endpoints for field collections * add endpoints for object bricks * add endpoints for object bricks * remove test controller * add event docs * Apply php-cs-fixer changes * fix merge issue
1 parent 05b6297 commit 6071dad

18 files changed

+1194
-1
lines changed

doc/05_Additional_Custom_Attributes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ final class AssetEvent extends AbstractPreResponseEvent
149149
- `pre_response.objectBrick.detail`
150150
- `pre_response.objectBrick.layout_definition`
151151
- `pre_response.objectBrick.tree`
152+
- `pre_response.objectBrick.usage_data`
152153
- `pre_response.perspective.config.get`
153154
- `pre_response.perspective.widget.config.get`
154155
- `pre_response.perspective.widget.type`
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Class\Attribute\Request;
15+
16+
use Attribute;
17+
use OpenApi\Attributes\JsonContent;
18+
use OpenApi\Attributes\RequestBody;
19+
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ObjectBrickUpdate;
20+
21+
#[Attribute(Attribute::TARGET_METHOD)]
22+
final class ObjectBrickUpdateRequestBody extends RequestBody
23+
{
24+
public function __construct()
25+
{
26+
parent::__construct(
27+
required: true,
28+
content: new JsonContent(
29+
ref: ObjectBrickUpdate::class,
30+
type: 'object'
31+
)
32+
);
33+
}
34+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller\ObjectBrick;
15+
16+
use OpenApi\Attributes\JsonContent;
17+
use OpenApi\Attributes\Post;
18+
use Pimcore\Bundle\StudioBackendBundle\Class\MappedParameter\CreateObjectBrickParameters;
19+
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\CreateObjectBrick;
20+
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\ObjectBrick\ObjectBrickDetail;
21+
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ObjectBrick\ObjectBrickServiceInterface;
22+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
23+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ElementExistsException;
24+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ElementSavingFailedException;
25+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotWriteableException;
26+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Request\ReferenceRequestBody;
27+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
28+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
29+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
30+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
31+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
32+
use Symfony\Component\HttpFoundation\JsonResponse;
33+
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
34+
use Symfony\Component\Routing\Attribute\Route;
35+
use Symfony\Component\Security\Http\Attribute\IsGranted;
36+
use Symfony\Component\Serializer\SerializerInterface;
37+
38+
/**
39+
* @internal
40+
*/
41+
final class CreateController extends AbstractApiController
42+
{
43+
private const string ROUTE = '/class/object-brick';
44+
45+
public function __construct(
46+
SerializerInterface $serializer,
47+
private readonly ObjectBrickServiceInterface $objectBrickService,
48+
) {
49+
parent::__construct($serializer);
50+
}
51+
52+
/**
53+
* @throws ElementExistsException|ElementSavingFailedException|NotWriteableException
54+
*/
55+
#[Route(
56+
self::ROUTE,
57+
name: 'pimcore_studio_api_class_object_brick_create',
58+
methods: ['POST']
59+
)]
60+
#[IsGranted(UserPermissions::OBJECT_BRICKS->value)]
61+
#[Post(
62+
path: self::PREFIX . self::ROUTE,
63+
operationId: 'class_object_brick_create',
64+
description: 'class_object_brick_create_description',
65+
summary: 'class_object_brick_create_summary',
66+
tags: [Tags::ClassDefinition->value],
67+
)]
68+
#[ReferenceRequestBody(CreateObjectBrick::class)]
69+
#[SuccessResponse(
70+
description: 'class_object_brick_create_success_response',
71+
content: new JsonContent(ref: ObjectBrickDetail::class)
72+
)]
73+
#[DefaultResponses([
74+
HttpResponseCodes::CONFLICT,
75+
HttpResponseCodes::INTERNAL_SERVER_ERROR,
76+
HttpResponseCodes::UNAUTHORIZED,
77+
])]
78+
public function createObjectBrick(
79+
#[MapRequestPayload] CreateObjectBrickParameters $parameters,
80+
): JsonResponse {
81+
return $this->jsonResponse(
82+
$this->objectBrickService->createObjectBrick($parameters)
83+
);
84+
}
85+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller\ObjectBrick;
15+
16+
use OpenApi\Attributes\Delete;
17+
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ObjectBrick\ObjectBrickServiceInterface;
18+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
19+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
20+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotWriteableException;
21+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter;
22+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
23+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
24+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
25+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
26+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
27+
use Symfony\Component\HttpFoundation\Response;
28+
use Symfony\Component\Routing\Attribute\Route;
29+
use Symfony\Component\Security\Http\Attribute\IsGranted;
30+
use Symfony\Component\Serializer\SerializerInterface;
31+
32+
/**
33+
* @internal
34+
*/
35+
final class DeleteController extends AbstractApiController
36+
{
37+
private const string ROUTE = '/class/object-brick/{key}';
38+
39+
public function __construct(
40+
SerializerInterface $serializer,
41+
private readonly ObjectBrickServiceInterface $objectBrickService,
42+
) {
43+
parent::__construct($serializer);
44+
}
45+
46+
/**
47+
* @throws NotFoundException|NotWriteableException
48+
*/
49+
#[Route(
50+
self::ROUTE,
51+
name: 'pimcore_studio_api_class_object_brick_delete',
52+
methods: ['DELETE']
53+
)]
54+
#[IsGranted(UserPermissions::OBJECT_BRICKS->value)]
55+
#[Delete(
56+
path: self::PREFIX . self::ROUTE,
57+
operationId: 'class_object_brick_delete',
58+
description: 'class_object_brick_delete_description',
59+
summary: 'class_object_brick_delete_summary',
60+
tags: [Tags::ClassDefinition->value],
61+
)]
62+
#[StringParameter(
63+
name: 'key',
64+
example: 'MyObjectBrick',
65+
description: 'Object brick unique key',
66+
required: true
67+
)]
68+
#[SuccessResponse(
69+
description: 'class_object_brick_delete_success_response'
70+
)]
71+
#[DefaultResponses([
72+
HttpResponseCodes::INTERNAL_SERVER_ERROR,
73+
HttpResponseCodes::NOT_FOUND,
74+
HttpResponseCodes::UNAUTHORIZED,
75+
])]
76+
public function deleteObjectBrick(string $key): Response
77+
{
78+
$this->objectBrickService->deleteObjectBrick($key);
79+
80+
return new Response();
81+
}
82+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* This source file is available under the terms of the
6+
* Pimcore Open Core License (POCL)
7+
* Full copyright and license information is available in
8+
* LICENSE.md which is distributed with this source code.
9+
*
10+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
11+
* @license Pimcore Open Core License (POCL)
12+
*/
13+
14+
namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller\ObjectBrick;
15+
16+
use OpenApi\Attributes\Get;
17+
use Pimcore\Bundle\StudioBackendBundle\Class\Service\ObjectBrick\ObjectBrickServiceInterface;
18+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
19+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
20+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\StringParameter;
21+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType;
22+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
23+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Header\ContentDisposition;
24+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
25+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
26+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\Asset\MimeTypes;
27+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
28+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
29+
use Symfony\Component\HttpFoundation\Response;
30+
use Symfony\Component\Routing\Attribute\Route;
31+
use Symfony\Component\Security\Http\Attribute\IsGranted;
32+
use Symfony\Component\Serializer\SerializerInterface;
33+
34+
/**
35+
* @internal
36+
*/
37+
final class ExportController extends AbstractApiController
38+
{
39+
private const string ROUTE = '/class/object-brick/{key}/export';
40+
41+
public function __construct(
42+
SerializerInterface $serializer,
43+
private readonly ObjectBrickServiceInterface $objectBrickService,
44+
) {
45+
parent::__construct($serializer);
46+
}
47+
48+
/**
49+
* @throws NotFoundException
50+
*/
51+
#[Route(
52+
self::ROUTE,
53+
name: 'pimcore_studio_api_class_object_brick_export',
54+
methods: ['GET']
55+
)]
56+
#[IsGranted(UserPermissions::OBJECT_BRICKS->value)]
57+
#[Get(
58+
path: self::PREFIX . self::ROUTE,
59+
operationId: 'class_object_brick_export',
60+
description: 'class_object_brick_export_description',
61+
summary: 'class_object_brick_export_summary',
62+
tags: [Tags::ClassDefinition->value],
63+
)]
64+
#[StringParameter(
65+
name: 'key',
66+
example: 'MyObjectBrick',
67+
description: 'Object brick unique key',
68+
required: true
69+
)]
70+
#[SuccessResponse(
71+
description: 'class_object_brick_export_success_response',
72+
content: [new MediaType(MimeTypes::JSON->value)],
73+
headers: [new ContentDisposition(fileName: 'objectbrick_MyObjectBrick_export.json')]
74+
)]
75+
#[DefaultResponses([
76+
HttpResponseCodes::NOT_FOUND,
77+
HttpResponseCodes::UNAUTHORIZED,
78+
])]
79+
public function exportObjectBrick(string $key): Response
80+
{
81+
return $this->objectBrickService->exportObjectBrick($key);
82+
}
83+
}

0 commit comments

Comments
 (0)