-
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 note controllers, service, hydrator, repo, etc.
- Loading branch information
Showing
23 changed files
with
1,022 additions
and
4 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\Note\Controller\: | ||
resource: '../src/Note/Controller' | ||
public: true | ||
tags: [ 'controller.service_arguments' ] | ||
|
||
# Hydrators | ||
Pimcore\Bundle\StudioBackendBundle\Note\Hydrator\NoteHydratorInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Note\Hydrator\NoteHydrator | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Note\Extractor\NoteDataExtractorInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Note\Extractor\NoteDataExtractor | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Note\Repository\NoteRepositoryInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Note\Repository\NoteRepository | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Note\Service\NoteServiceInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Note\Service\NoteService |
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
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\Note\Attributes\Request; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\RequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\CreateNote; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class CreateNoteRequestBody extends RequestBody | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
required: true, | ||
content: new JsonContent(ref: CreateNote::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,90 @@ | ||
<?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\Note\Controller\Element; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteElement; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteParameters; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Service\NoteServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\ElementTypeParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
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\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\Config\Tags; | ||
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 NoteServiceInterface $noteService | ||
) | ||
{ | ||
parent::__construct($serializer); | ||
} | ||
|
||
|
||
|
||
#[Route('/notes/{elementType}/{id}', name: 'pimcore_studio_api_get_element_notes', methods: ['GET'])] | ||
#[Get( | ||
path: self::API_PATH . '/notes/{elementType}/{id}', | ||
operationId: 'getNotesForElementByTypeAndId', | ||
summary: 'Get notes for an element', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Notes->name] | ||
)] | ||
#[ElementTypeParameter] | ||
#[IdParameter(type: 'element')] | ||
#[PageParameter] | ||
#[PageSizeParameter(50)] | ||
#[FilterParameter('notes')] | ||
#[BadRequestResponse] | ||
#[UnauthorizedResponse] | ||
#[MethodNotAllowedResponse] | ||
#[UnsupportedMediaTypeResponse] | ||
#[UnprocessableContentResponse] | ||
public function getNotes( | ||
string $elementType, | ||
int $id, | ||
#[MapQueryString] NoteParameters $parameters = new NoteParameters() | ||
): JsonResponse | ||
{ | ||
$collection = $this->noteService->listNotes(new NoteElement($elementType, $id), $parameters); | ||
|
||
return $this->getPaginatedCollection( | ||
$this->serializer, | ||
$collection->getItems(), | ||
$collection->getTotalItems() | ||
); | ||
} | ||
} |
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,75 @@ | ||
<?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\Note\Controller\Element; | ||
|
||
use OpenApi\Attributes\Post; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Attributes\Request\CreateNoteRequestBody; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Request\NoteElement; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\CreateNote; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Service\NoteServiceInterface; | ||
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\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\Config\Tags; | ||
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 NoteServiceInterface $noteService | ||
) | ||
{ | ||
parent::__construct($serializer); | ||
} | ||
|
||
#[Route('/notes/{elementType}/{id}', name: 'pimcore_studio_api_create_element_note', methods: ['POST'])] | ||
#[Post( | ||
path: self::API_PATH . '/notes/{elementType}/{id}', | ||
operationId: 'createNoteForElement', | ||
summary: 'Creating new note for element', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Notes->name] | ||
)] | ||
#[ElementTypeParameter] | ||
#[IdParameter(type: 'element')] | ||
#[CreateNoteRequestBody] | ||
#[BadRequestResponse] | ||
#[UnauthorizedResponse] | ||
#[MethodNotAllowedResponse] | ||
#[UnsupportedMediaTypeResponse] | ||
#[UnprocessableContentResponse] | ||
public function createNote( | ||
string $elementType, | ||
int $id, | ||
#[MapRequestPayload] CreateNote $createNote): JsonResponse | ||
{ | ||
$note = $this->noteService->createNote(new NoteElement($elementType, $id), $createNote); | ||
return $this->jsonResponse(['id' => $note->getId()]); | ||
} | ||
} |
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,104 @@ | ||
<?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\Note\Extractor; | ||
|
||
use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; | ||
use Pimcore\Bundle\StaticResolverBundle\Models\User\UserResolverInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\NoteUser; | ||
use Pimcore\Model\Element\ElementInterface; | ||
use Pimcore\Model\Element\Note as CoreNote; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class NoteDataExtractor implements NoteDataExtractorInterface | ||
{ | ||
public function __construct( | ||
private ServiceResolverInterface $serviceResolver, | ||
private UserResolverInterface $userResolver | ||
) | ||
{ | ||
} | ||
|
||
public function extractCPath(CoreNote $note) : string | ||
{ | ||
if (!$note->getCid() || !$note->getCtype()) { | ||
return ''; | ||
} | ||
$element = $this->serviceResolver->getElementById($note->getCtype(), $note->getCid()); | ||
|
||
if (!$element) { | ||
return ''; | ||
} | ||
|
||
return $element->getRealFullPath(); | ||
} | ||
|
||
public function extractUserData(CoreNote $note) : NoteUser | ||
{ | ||
$emptyUser = new NoteUser(); | ||
if(!$note->getUser()) { | ||
return $emptyUser; | ||
} | ||
|
||
$user = $this->userResolver->getById($note->getUser()); | ||
|
||
if(!$user) { | ||
return $emptyUser; | ||
} | ||
|
||
return new NoteUser( | ||
$user->getId(), | ||
$user->getName(), | ||
); | ||
} | ||
|
||
public function extractData(CoreNote $note): array | ||
{ | ||
// prepare key-values | ||
$keyValues = []; | ||
foreach ($note->getData() as $name => $d) { | ||
|
||
$type = $d['type']; | ||
|
||
$data = match($type) { | ||
'document', 'object', 'asset' => $this->extractElementData($d['data']), | ||
'date' => is_object($d['data']) ? $d['data']->getTimestamp() : $d['data'], | ||
default => $d['data'], | ||
}; | ||
|
||
$keyValue = [ | ||
'type' => $type, | ||
'name' => $name, | ||
'data' => $data, | ||
]; | ||
|
||
$keyValues[] = $keyValue; | ||
} | ||
|
||
return $keyValues; | ||
} | ||
|
||
private function extractElementData(ElementInterface $element): array | ||
{ | ||
return [ | ||
'id' => $element->getId(), | ||
'path' => $element->getRealFullPath(), | ||
'type' => $element->getType(), | ||
]; | ||
} | ||
} |
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,32 @@ | ||
<?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\Note\Extractor; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\NoteUser; | ||
use Pimcore\Model\Element\Note as CoreNote; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface NoteDataExtractorInterface | ||
{ | ||
public function extractUserData(CoreNote $note): NoteUser; | ||
|
||
public function extractCPath(CoreNote $note): string; | ||
|
||
public function extractData(CoreNote $note): array; | ||
} |
Oops, something went wrong.