diff --git a/src/Note/Attribute/Request/NotesCollectionRequestBody.php b/src/Note/Attribute/Request/NotesCollectionRequestBody.php new file mode 100644 index 000000000..0dd4d5d48 --- /dev/null +++ b/src/Note/Attribute/Request/NotesCollectionRequestBody.php @@ -0,0 +1,92 @@ +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)) @@ -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); diff --git a/src/Note/MappedParameter/NoteParameters.php b/src/Note/MappedParameter/NoteParameters.php index 041a4b962..bb59e1601 100644 --- a/src/Note/MappedParameter/NoteParameters.php +++ b/src/Note/MappedParameter/NoteParameters.php @@ -16,7 +16,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Note\MappedParameter; -use JsonException; use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParameters; /** @@ -30,7 +29,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); } @@ -50,17 +49,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; } } diff --git a/tests/Unit/Note/Service/FilterServiceTest.php b/tests/Unit/Note/Service/FilterServiceTest.php index 92c1e416b..b3000980a 100644 --- a/tests/Unit/Note/Service/FilterServiceTest.php +++ b/tests/Unit/Note/Service/FilterServiceTest.php @@ -58,14 +58,14 @@ public function testApplyFieldFiltersDate(): void { $noteListing = $this->getNoteListing(); $noteParameters = new NoteParameters( - fieldFilters: json_encode([ + fieldFilters: [ [ 'field' => 'date', 'type' => 'date', 'operator' => 'eq', 'value' => '05/04/2024', ], - ], JSON_THROW_ON_ERROR) + ], ); $this->filterService->applyFieldFilters($noteListing, $noteParameters); @@ -86,14 +86,14 @@ public function testApplyFieldFiltersNumeric(): void { $noteListing = $this->getNoteListing(); $noteParameters = new NoteParameters( - fieldFilters: json_encode([ + fieldFilters: [ [ 'field' => 'numeric', 'type' => 'numeric', 'operator' => 'eq', 'value' => 10, ], - ], JSON_THROW_ON_ERROR) + ], ); $this->filterService->applyFieldFilters($noteListing, $noteParameters); @@ -113,14 +113,14 @@ public function testApplyFieldFiltersBoolean(): void { $noteListing = $this->getNoteListing(); $noteParameters = new NoteParameters( - fieldFilters: json_encode([ + fieldFilters: [ [ 'field' => 'boolean', 'type' => 'boolean', 'operator' => 'boolean', 'value' => true, ], - ], JSON_THROW_ON_ERROR) + ], ); $this->filterService->applyFieldFilters($noteListing, $noteParameters); @@ -140,14 +140,14 @@ public function testApplyFieldFiltersList(): void { $noteListing = $this->getNoteListing(); $noteParameters = new NoteParameters( - fieldFilters: json_encode([ + fieldFilters: [ [ 'field' => 'list', 'type' => 'list', 'operator' => 'list', 'value' => 'list', ], - ], JSON_THROW_ON_ERROR) + ], ); $this->filterService->applyFieldFilters($noteListing, $noteParameters); @@ -167,14 +167,14 @@ public function testApplyFieldFiltersUser(): void { $noteListing = $this->getNoteListing(); $noteParameters = new NoteParameters( - fieldFilters: json_encode([ + fieldFilters: [ [ 'field' => 'user', 'type' => 'user', 'operator' => 'user', 'value' => 'admin', ], - ], JSON_THROW_ON_ERROR) + ], ); $this->filterService->applyFieldFilters($noteListing, $noteParameters); @@ -197,7 +197,11 @@ public function testApplyFieldFiltersInvalidJson(): void { $noteListing = $this->getNoteListing(); $noteParameters = new NoteParameters( - fieldFilters: 'invalid' + fieldFilters: [ + [ + 'invalidKey' => 'invalidValue', + ], + ], ); $this->expectException(InvalidFilterException::class);