Skip to content

Commit

Permalink
Switched collection controller from get to post
Browse files Browse the repository at this point in the history
  • Loading branch information
mcop1 committed Jan 23, 2025
1 parent 4710085 commit d1313ec
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 28 deletions.
99 changes: 99 additions & 0 deletions src/Note/Attribute/Request/NotesCollectionRequestBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?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\Attribute\Request;

use Attribute;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\RequestBody;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Property\SaveConfigurationColumn;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Filter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\ListOfInteger;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\SingleBoolean;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\SingleInteger;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\SingleString;

/**
* @internal
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class NotesCollectionRequestBody extends RequestBody
{
public function __construct()
{
parent::__construct(
required: true,
content: new JsonContent(
required: ['page', 'pageSize'],
properties: [
new Property(
property: 'page',
type: 'integer',
example: 1
),
new Property(
property: 'pageSize',
type: 'integer',
example: 50
),
new Property(
property: 'sortOrder',
description: 'Sort order (asc or desc).',
type: 'string',
enum: [
'ASC',
'DESC',
],
example: 'ASC'
),
new Property(
property: 'sortBy',
description: 'Sort by field. Only works in combination with sortOrder.',
type: 'string',
enum: [
'id',
'type',
'cId',
'cType',
'cPath',
'date',
'title',
'description',
'locked',
],
example: 'id',
),
new Property(
property: 'filter',
description: 'Filter for notes',
type: 'string',
example: ''
),
new Property(
property: 'fieldFilters',
description: 'Filter for specific fields, will be json decoded to an array. e.g.
[{"operator":"like","value":"John","field":"name","type":"string"}]',
type: 'object',
example: '[{"operator":"like","value":"consent-given","field":"type","type":"string"}]'
),
],
type: 'object',
),
);
}
}
24 changes: 7 additions & 17 deletions src/Note/Controller/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@

namespace Pimcore\Bundle\StudioBackendBundle\Note\Controller;

use OpenApi\Attributes\Get;
use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidFilterException;
use Pimcore\Bundle\StudioBackendBundle\Note\Attribute\Parameter\Query\NoteSortByParameter;
use Pimcore\Bundle\StudioBackendBundle\Note\Attribute\Request\NotesCollectionRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Note\MappedParameter\NoteElementParameters;
use Pimcore\Bundle\StudioBackendBundle\Note\MappedParameter\NoteParameters;
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\Note;
use Pimcore\Bundle\StudioBackendBundle\Note\Service\NoteServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\FieldFilterParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\FilterParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageSizeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\SortOrderParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
Expand All @@ -38,7 +33,7 @@
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;
Expand All @@ -60,21 +55,16 @@ public function __construct(
/**
* @throws InvalidFilterException
*/
#[Route('/notes', name: 'pimcore_studio_api_get_notes', methods: ['GET'])]
#[Route('/notes', name: 'pimcore_studio_api_get_notes', methods: ['POST'])]
#[IsGranted(UserPermissions::NOTES_EVENTS->value)]
#[Get(
#[Post(
path: self::PREFIX . '/notes',
operationId: 'note_get_collection',
description: 'note_get_collection_description',
summary: 'note_get_collection_summary',
tags: [Tags::Notes->name]
)]
#[PageParameter]
#[PageSizeParameter(50)]
#[NoteSortByParameter]
#[SortOrderParameter]
#[FilterParameter('notes')]
#[FieldFilterParameter]
#[NotesCollectionRequestBody]
#[SuccessResponse(
description: 'note_get_collection_success_response',
content: new CollectionJson(new GenericCollection(Note::class))
Expand All @@ -83,7 +73,7 @@ public function __construct(
HttpResponseCodes::UNAUTHORIZED,
])]
public function getNotes(
#[MapQueryString] NoteParameters $parameters = new NoteParameters()
#[MapRequestPayload] NoteParameters $parameters
): JsonResponse {
$collection = $this->noteService->listNotes(new NoteElementParameters(), $parameters);

Expand Down
13 changes: 2 additions & 11 deletions src/Note/MappedParameter/NoteParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
private ?string $sortBy = null,
private ?string $sortOrder = null,
private ?string $filter = null,
private ?string $fieldFilters = null,
private ?array $fieldFilters = null,
) {
parent::__construct($page, $pageSize);
}
Expand All @@ -50,17 +50,8 @@ public function getFilter(): ?string
return $this->filter;
}

/**
* @throws JsonException
*/
public function getFieldFilters(): ?array
{
return $this->fieldFilters === null ? null :
json_decode(
$this->fieldFilters,
true,
512,
JSON_THROW_ON_ERROR
);
return $this->fieldFilters;
}
}

0 comments on commit d1313ec

Please sign in to comment.