Skip to content

feat(doctrine): new iri search filters #7121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

vinceAmstoutz
Copy link
Member

@vinceAmstoutz vinceAmstoutz commented May 5, 2025

Q A
Branch? main
License MIT
Doc PR TBD

The aim of this PR is to have the API Platform search filters like API Platform eloquent filters.

This PR continues the improvements initiated in pull requests #7079 and #6865, aiming to finalize the efforts started initially in pull request #6775.

TODO (by order of priority) :

  • IriFiter ORM (made by @soyuka)
  • ExactFilter ORM
  • PartialSearchFilter ORM
  • Refactoring filter fixtures
  • IriFilter ODM
  • ExactFilter ODM
  • PartialSearchFilter ODM
  • OrFilter ORM
  • OrFilter ODM
  • Check OpenApi documentation
  • Fix ODM filters on relations

@vinceAmstoutz vinceAmstoutz force-pushed the feat/new-doctrine-iri-search-filters branch from 0271e3e to 774ba0c Compare May 5, 2025 03:17
@vinceAmstoutz vinceAmstoutz marked this pull request as draft May 5, 2025 03:18
@vinceAmstoutz vinceAmstoutz force-pushed the feat/new-doctrine-iri-search-filters branch 4 times, most recently from 8322356 to 773ce67 Compare May 5, 2025 04:54
@soyuka soyuka mentioned this pull request Jun 4, 2025
@vinceAmstoutz vinceAmstoutz force-pushed the feat/new-doctrine-iri-search-filters branch 4 times, most recently from ae2ad0e to 662ad04 Compare June 12, 2025 13:50
@vinceAmstoutz vinceAmstoutz force-pushed the feat/new-doctrine-iri-search-filters branch from 662ad04 to f6bbe8b Compare July 2, 2025 08:58
@vinceAmstoutz vinceAmstoutz marked this pull request as ready for review July 4, 2025 07:56
return;
}

$values = (array) $parameter->getValue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now castToArray therefore we don't really need to cast here, however we may need to fix how we build our aggregation see below

use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;

/**
* @author Vincent Amstoutz <[email protected]>

This comment was marked as outdated.

return new OpenApiParameter(name: $parameter->getKey().'[]', in: 'query', style: 'deepObject', explode: true);
}

public function getDescription(string $resourceClass): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this method to a trait inside Metadata, also add * @deprecated in 4.2, to be removed in 5.0 to the Metadata\FilterInterface (we'll handle the bc later)

Comment on lines +39 to +42
$aggregationBuilder
->match()
->field($property)
->in($values);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$aggregationBuilder
->match()
->field($property)
->in($values);
$aggregationBuilder
->match()
->field($property)
->{(is_iterable($value)) ? 'in' : 'equals'}($parameter->getValue());


$value = $parameter->getValue();
if (!\is_array($value)) {
$value = [$value];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is now castToArray therefore we don't really need to cast here, however we may need to fix how we build our aggregation see below

#[ODM\Document]
class Company
{
#[ODM\Id(strategy: 'INCREMENT', type: 'int')]
#[ODM\Id(type: 'int', strategy: 'INCREMENT')]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert

*/
protected function setUp(): void
{
self::$alwaysBootKernel = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    protected static ?bool $alwaysBootKernel = false;

'expectedNames' => ['Gertrude'],
];

yield 'filtre par ID du poulailler de Henriette' => [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the API Platform code base is in english :p

* @throws ServerExceptionInterface
*/
#[DataProvider('filterDataProvider')]
public function testOrFilter(string $url, int $expectedCount, array $expectedNames): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this correctly tests an Or filter

*/
protected function setUp(): void
{
self::$alwaysBootKernel = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    protected static ?bool $alwaysBootKernel = false;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants