-
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. * Apply php-cs-fixer changes * Add responses and new way for default responses * Apply php-cs-fixer changes * Add user permission guard * Add delete controller and service methods, update descriptions of property controllers * Add method to interface * cleanup * Add feedback from sonar * Add more feedback * Add collection route to list notes in general, separation between notes and element notes * Adding json filter * Apply php-cs-fixer changes * Empty is enough * Apply sonar cloud feedback * Remove trailing spaces * Add filterservice test * Apply php-cs-fixer changes * Add sort parameters * Apply php-cs-fixer changes * Add space --------- Co-authored-by: mattamon <[email protected]>
- Loading branch information
Showing
42 changed files
with
2,052 additions
and
11 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,28 @@ | ||
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 | ||
|
||
Pimcore\Bundle\StudioBackendBundle\Note\Service\FilterServiceInterface: | ||
class: Pimcore\Bundle\StudioBackendBundle\Note\Service\FilterService |
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
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 InvalidFilterException extends AbstractApiException | ||
{ | ||
public function __construct(string $filter) | ||
{ | ||
parent::__construct( | ||
400, | ||
sprintf('Invalid filter: %s', $filter) | ||
); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Note/Attributes/Parameters/Query/NoteSortByParameter.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,50 @@ | ||
<?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\Parameters\Query; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\QueryParameter; | ||
use OpenApi\Attributes\Schema; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class NoteSortByParameter extends QueryParameter | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
name: 'sortBy', | ||
description: 'Sort by field. Only works in combination with sortOrder.', | ||
in: 'query', | ||
required: false, | ||
schema: new Schema( | ||
type: 'string', | ||
enum: [ | ||
'id', | ||
'type', | ||
'cId', | ||
'cType', | ||
'cPath', | ||
'date', | ||
'title', | ||
'description', | ||
'locked', | ||
], | ||
example: null, | ||
), | ||
); | ||
} | ||
} |
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,37 @@ | ||
<?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\Response\Property; | ||
|
||
use OpenApi\Attributes\Items; | ||
use OpenApi\Attributes\Property; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\Note; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class NoteCollection extends Property | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
'items', | ||
title: 'items', | ||
type: 'array', | ||
items: new Items(ref: Note::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,93 @@ | ||
<?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; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Attributes\Parameters\Query\NoteSortByParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Attributes\Response\Property\NoteCollection; | ||
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\Query\FieldFilterParameter; | ||
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\SortOrderParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\CollectionJson; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions; | ||
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\Security\Http\Attribute\IsGranted; | ||
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', name: 'pimcore_studio_api_get_notes', methods: ['GET'])] | ||
#[IsGranted(UserPermissions::NOTES_EVENTS->value)] | ||
#[Get( | ||
path: self::API_PATH . '/notes', | ||
operationId: 'getNotes', | ||
summary: 'Get notes', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Notes->name] | ||
)] | ||
#[PageParameter] | ||
#[PageSizeParameter(50)] | ||
#[NoteSortByParameter] | ||
#[SortOrderParameter] | ||
#[FilterParameter('notes')] | ||
#[FieldFilterParameter] | ||
#[SuccessResponse( | ||
description: 'Paginated assets with total count as header param', | ||
content: new CollectionJson(new NoteCollection()) | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED | ||
])] | ||
public function getNotes( | ||
#[MapQueryString] NoteParameters $parameters = new NoteParameters() | ||
): JsonResponse | ||
{ | ||
$collection = $this->noteService->listNotes(new NoteElement(), $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,74 @@ | ||
<?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; | ||
|
||
use OpenApi\Attributes\Delete; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\Note\Service\NoteServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\IdJson; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DeleteController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly NoteServiceInterface $noteService | ||
) | ||
{ | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws ElementNotFoundException | ||
*/ | ||
#[Route('/notes/{id}', name: 'pimcore_studio_api_delete_note', methods: ['DELETE'])] | ||
#[IsGranted(UserPermissions::NOTES_EVENTS->value)] | ||
#[Delete( | ||
path: self::API_PATH . '/notes/{id}', | ||
operationId: 'deleteNote', | ||
summary: 'Deleting note by id', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Notes->name] | ||
)] | ||
#[IdParameter] | ||
#[SuccessResponse( | ||
description: 'Id of the note that got deleted', | ||
content: new IdJson('ID of deleted note') | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::NOT_FOUND, | ||
HttpResponseCodes::UNAUTHORIZED | ||
])] | ||
public function deleteNote(int $id): JsonResponse | ||
{ | ||
$this->noteService->deleteNote($id); | ||
return $this->jsonResponse(['id' => $id]); | ||
} | ||
} |
Oops, something went wrong.