-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tag create, read and update controllers
- Loading branch information
Showing
18 changed files
with
949 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
# controllers are imported separately to make sure they're public | ||
# and have a tag that allows actions to type-hint services | ||
Pimcore\Bundle\StudioBackendBundle\Tag\Controller\: | ||
resource: '../src/Tag/Controller' | ||
public: true | ||
tags: [ 'controller.service_arguments' ] | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Tag\Repository\TagRepositoryInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Tag\Repository\TagRepository | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Tag\Hydrator\TagHydratorInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Tag\Hydrator\TagHydrator | ||
|
||
# Services | ||
Pimcore\Bundle\StudioBackendBundle\Tag\Service\TagServiceInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Tag\Service\TagService | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class InvalidParentIdException extends AbstractApiException | ||
{ | ||
public function __construct(int $parentId) | ||
{ | ||
parent::__construct(400, sprintf( | ||
'Invalid parent id: %s', | ||
$parentId | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Tag\Attributes\Request; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\RequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Request\CreateTagParameters; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class CreateTagRequestBody extends RequestBody | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
required: true, | ||
content: new JsonContent(ref: CreateTagParameters::class) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Tag\Attributes\Request; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\RequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Request\UpdateTagParameters; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class UpdateTagRequestBody extends RequestBody | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
required: true, | ||
content: new JsonContent(ref: UpdateTagParameters::class) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Tag\Controller; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\InvalidQueryTypeException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Content\ItemsJson; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\ElementTypeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\FilterParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\PageParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\PageSizeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\ParentIdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\BadRequestResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\MethodNotAllowedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnauthorizedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnsupportedMediaTypeResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Request\TagsParameters; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Schema\Tag; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Service\TagServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\PaginatedResponseTrait; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapQueryString; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CollectionController extends AbstractApiController | ||
{ | ||
use PaginatedResponseTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly TagServiceInterface $tagService, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws InvalidQueryTypeException | ||
*/ | ||
#[Route('/tags', name: 'pimcore_studio_api_tags', methods: ['GET'])] | ||
//#[IsGranted('STUDIO_API')] | ||
#[Get( | ||
path: self::API_PATH . '/tags', | ||
operationId: 'getTags', | ||
summary: 'Get all tags for a parent id. You can filter by type and query', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Tags->name] | ||
)] | ||
#[PageParameter] | ||
#[PageSizeParameter] | ||
#[ElementTypeParameter(false, null)] | ||
#[FilterParameter] | ||
#[ParentIdParameter] | ||
#[SuccessResponse( | ||
description: 'Tags filtered based on type and query parameters', | ||
content: new ItemsJson(Tag::class) | ||
)] | ||
#[BadRequestResponse] | ||
#[UnauthorizedResponse] | ||
#[MethodNotAllowedResponse] | ||
#[UnsupportedMediaTypeResponse] | ||
#[UnprocessableContentResponse] | ||
public function getTags( | ||
#[MapQueryString] TagsParameters $parameters): JsonResponse | ||
{ | ||
return $this->jsonResponse(['items' => $this->tagService->listTags($parameters)]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Tag\Controller; | ||
|
||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\Post; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\NotWriteableException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\BadRequestResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\MethodNotAllowedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnauthorizedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnsupportedMediaTypeResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Attributes\Request\CreateTagRequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Request\CreateTagParameters; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Schema\Tag; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Service\TagServiceInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CreateController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly TagServiceInterface $tagService, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws NotWriteableException | ||
*/ | ||
#[Route('/tag', name: 'pimcore_studio_api_create_tag', methods: ['POST'])] | ||
#[POST( | ||
path: self::API_PATH . '/tag', | ||
operationId: 'createTag', | ||
summary: 'Creating a new tag', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Tags->name] | ||
)] | ||
#[CreateTagRequestBody] | ||
#[SuccessResponse( | ||
description: 'Tag data as json', | ||
content: new JsonContent(ref: Tag::class, type: 'object') | ||
)] | ||
#[BadRequestResponse] | ||
#[UnauthorizedResponse] | ||
#[MethodNotAllowedResponse] | ||
#[UnsupportedMediaTypeResponse] | ||
#[UnprocessableContentResponse] | ||
public function createTag(#[MapRequestPayload] CreateTagParameters $parameters): JsonResponse | ||
{ | ||
|
||
return $this->jsonResponse($this->tagService->createTag($parameters)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Tag\Controller; | ||
|
||
use OpenApi\Attributes\Get; | ||
use OpenApi\Attributes\JsonContent; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\MethodNotAllowedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\NotFoundResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnauthorizedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnsupportedMediaTypeResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Schema\Tag; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Service\TagServiceInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class GetController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly TagServiceInterface $tagService, | ||
) | ||
{ | ||
parent::__construct($serializer); | ||
} | ||
|
||
#[Route('/tags/{id}', name: 'pimcore_studio_api_get_tag', methods: ['GET'])] | ||
//#[IsGranted('STUDIO_API')] | ||
#[Get( | ||
path: self::API_PATH . '/tags/{id}', | ||
operationId: 'getTagById', | ||
description: 'Get tag based on the tag ID', | ||
summary: 'Get tag by ID', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Tags->name] | ||
)] | ||
#[IdParameter(type: 'tag')] | ||
#[SuccessResponse( | ||
description: 'Tag data as json', | ||
content: new JsonContent(ref: Tag::class) | ||
)] | ||
#[UnauthorizedResponse] | ||
#[NotFoundResponse] | ||
#[MethodNotAllowedResponse] | ||
#[UnsupportedMediaTypeResponse] | ||
#[UnprocessableContentResponse] | ||
public function getTags(int $id): JsonResponse | ||
{ | ||
return $this->jsonResponse( | ||
$this->tagService->getTag($id) | ||
|
||
); | ||
} | ||
} |
Oops, something went wrong.