-
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 asign tag methods including batch
- Loading branch information
Showing
13 changed files
with
619 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,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\Schema\ElementTag; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class ElementTagRequestBody extends RequestBody | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
required: true, | ||
content: new JsonContent(ref: ElementTag::class) | ||
); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Tag/Attributes/Request/ElementsTagsCollectionRequestBody.php
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\Schema\ElementTagIdCollection; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class ElementsTagsCollectionRequestBody extends RequestBody | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
required: true, | ||
content: new JsonContent(ref: ElementTagIdCollection::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,79 @@ | ||
<?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\Element; | ||
|
||
use OpenApi\Attributes\Post; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementSavingFailedException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\ElementTypeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Attributes\Request\ElementTagRequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Request\TagElement; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Schema\ElementTag; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Service\TagServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class AssignController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly TagServiceInterface $tagService, | ||
) | ||
{ | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws ElementSavingFailedException|ElementNotFoundException | ||
*/ | ||
#[Route('/tags/{elementType}/{id}', name: 'pimcore_studio_api_assign_element_tag', methods: ['POST'])] | ||
//#[IsGranted(UserPermissions::TAGS_ASSIGNMENT->value)] | ||
#[Post( | ||
path: self::API_PATH . '/tags/{elementType}/{id}', | ||
operationId: 'assignTagForElement', | ||
summary: 'Assign tag for element', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::TagsForElement->value] | ||
)] | ||
#[ElementTypeParameter] | ||
#[IdParameter(type: 'element')] | ||
#[ElementTagRequestBody] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED | ||
])] | ||
public function assignTag( | ||
string $elementType, | ||
int $id, | ||
#[MapRequestPayload] ElementTag $assignTag | ||
): JsonResponse | ||
{ | ||
$this->tagService->assignTagToElement(new TagElement($elementType, $id), $assignTag->getTagId()); | ||
return $this->jsonResponse(['id' => $id]); | ||
} | ||
} |
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,82 @@ | ||
<?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\Element; | ||
|
||
use OpenApi\Attributes\Post; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementSavingFailedException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\ElementTypeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Attributes\Request\ElementsTagsCollectionRequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Request\BatchCollection; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Schema\ElementTagIdCollection; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Service\TagServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class BatchAssignController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly TagServiceInterface $tagService, | ||
) | ||
{ | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws ElementSavingFailedException|ElementNotFoundException | ||
*/ | ||
#[Route('/tags/batch/assign/{elementType}', name: 'pimcore_studio_api_batch_assign_elements_tags', methods: ['POST'])] | ||
//#[IsGranted(UserPermissions::TAGS_ASSIGNMENT->value)] | ||
#[Post( | ||
path: self::API_PATH . '/tags/batch/assign/{elementType}', | ||
operationId: 'batchAssignTagsForElements', | ||
summary: 'Batch assign tags for elements', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::TagsForElement->value] | ||
)] | ||
#[ElementTypeParameter] | ||
#[ElementsTagsCollectionRequestBody] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED | ||
])] | ||
public function assignTag( | ||
string $elementType, | ||
#[MapRequestPayload] ElementTagIdCollection $elementTagCollection | ||
): JsonResponse | ||
{ | ||
$this->tagService->batchAssignTagsToElements( | ||
new BatchCollection( | ||
$elementType, | ||
$elementTagCollection->getElementIds(), | ||
$elementTagCollection->getTagsIds() | ||
) | ||
); | ||
return $this->jsonResponse(['id' => 0]); | ||
} | ||
} |
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,82 @@ | ||
<?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\Element; | ||
|
||
use OpenApi\Attributes\Post; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementSavingFailedException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\ElementTypeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Attributes\Request\ElementsTagsCollectionRequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Request\BatchCollection; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Schema\ElementTagIdCollection; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Service\TagServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class BatchReplaceController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly TagServiceInterface $tagService, | ||
) | ||
{ | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws ElementSavingFailedException|ElementNotFoundException | ||
*/ | ||
#[Route('/tags/batch/replace/{elementType}', name: 'pimcore_studio_api_batch_replace_elements_tags', methods: ['POST'])] | ||
//#[IsGranted(UserPermissions::TAGS_ASSIGNMENT->value)] | ||
#[Post( | ||
path: self::API_PATH . '/tags/batch/replace/{elementType}', | ||
operationId: 'batchReplaceTagsForElements', | ||
summary: 'Batch replace tags for elements', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::TagsForElement->value] | ||
)] | ||
#[ElementTypeParameter] | ||
#[ElementsTagsCollectionRequestBody] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED | ||
])] | ||
public function assignTag( | ||
string $elementType, | ||
#[MapRequestPayload] ElementTagIdCollection $elementTagCollection | ||
): JsonResponse | ||
{ | ||
$this->tagService->batchReplaceTagsToElements( | ||
new BatchCollection( | ||
$elementType, | ||
$elementTagCollection->getElementIds(), | ||
$elementTagCollection->getTagsIds() | ||
) | ||
); | ||
return $this->jsonResponse(['id' => 0]); | ||
} | ||
} |
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,79 @@ | ||
<?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\Element; | ||
|
||
use OpenApi\Attributes\Delete; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementSavingFailedException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\ElementTypeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Attributes\Request\ElementTagRequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Request\TagElement; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Schema\ElementTag; | ||
use Pimcore\Bundle\StudioBackendBundle\Tag\Service\TagServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class UnassignController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly TagServiceInterface $tagService, | ||
) | ||
{ | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws ElementSavingFailedException|ElementNotFoundException | ||
*/ | ||
#[Route('/tags/{elementType}/{id}', name: 'pimcore_studio_api_unassign_element_tag', methods: ['DELETE'])] | ||
//#[IsGranted(UserPermissions::TAGS_ASSIGNMENT->value)] | ||
#[Delete( | ||
path: self::API_PATH . '/tags/{elementType}/{id}', | ||
operationId: 'unassignTagFromElement', | ||
summary: 'Unassign tag from element', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::TagsForElement->value] | ||
)] | ||
#[ElementTypeParameter] | ||
#[IdParameter(type: 'element')] | ||
#[ElementTagRequestBody] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED | ||
])] | ||
public function unassignTag( | ||
string $elementType, | ||
int $id, | ||
#[MapRequestPayload] ElementTag $unassignTag | ||
): JsonResponse | ||
{ | ||
$this->tagService->unassignTagFromElement(new TagElement($elementType, $id), $unassignTag->getTagId()); | ||
return $this->jsonResponse(['id' => $id]); | ||
} | ||
} |
Oops, something went wrong.