Skip to content
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

feat(doctrine): doctrine filters like laravel eloquent filters #6775

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vinceAmstoutz
Copy link
Contributor

@vinceAmstoutz vinceAmstoutz commented Nov 5, 2024

Q A
Branch? main
License MIT
Doc PR Coming soon

Completes #6749.

Goal:

Using Dotrine filters as we use Laravel Eloquent filters. Example using a BooleanFilter with Symfony and Doctrine:

#[ApiResource]
#[GetCollection(
    parameters: [
        'active' => new QueryParameter(
            filter: new BooleanFilter(),
        ),

        // support also for filter aliasing
        'enabled' => new QueryParameter(
            filter: new BooleanFilter(),
            property: 'active',
        ),
    ],
)]
#[ORM\Entity]
class FilteredBooleanParameter {
    // ...
}

TODO:

  • BooleanFilter
  • DateFilter
  • RangeFilter
  • Numeric
  • Exists
  • OrderFilter

Will be done in another PR:

  • SearchFilter

@vinceAmstoutz vinceAmstoutz force-pushed the feat-doctrine-filters-like-laravel-filters branch from fd22d9c to 93b3226 Compare November 5, 2024 13:07
@vinceAmstoutz vinceAmstoutz changed the title feat(doctrine): doctrine filters like laravel filters feat(doctrine): doctrine filters like laravel eloquent filters Nov 5, 2024
@vinceAmstoutz vinceAmstoutz force-pushed the feat-doctrine-filters-like-laravel-filters branch from 93b3226 to 6cfee88 Compare November 6, 2024 13:15
@vinceAmstoutz
Copy link
Contributor Author

@soyuka As requested, the swagger UI doc looks like this for the DateFilter:
image

@vinceAmstoutz vinceAmstoutz force-pushed the feat-doctrine-filters-like-laravel-filters branch 6 times, most recently from 77cb4c6 to fc7f5f1 Compare November 7, 2024 15:08
@vinceAmstoutz
Copy link
Contributor Author

@soyuka As requested, the swagger UI doc looks like this for the RangeFilter:

image

src/Doctrine/Odm/Extension/ParameterExtension.php Outdated Show resolved Hide resolved
src/Doctrine/Odm/Filter/AbstractFilter.php Outdated Show resolved Hide resolved
src/Doctrine/Odm/Filter/BooleanFilter.php Outdated Show resolved Hide resolved
src/Laravel/ApiPlatformProvider.php Outdated Show resolved Hide resolved
src/Symfony/Bundle/Resources/config/metadata/resource.xml Outdated Show resolved Hide resolved
tests/Functional/Parameters/BooleanFilterTest.php Outdated Show resolved Hide resolved
tests/Functional/Parameters/BooleanFilterTest.php Outdated Show resolved Hide resolved
@vinceAmstoutz vinceAmstoutz force-pushed the feat-doctrine-filters-like-laravel-filters branch 3 times, most recently from 2f4ec07 to 8f0620e Compare November 12, 2024 11:01
@vinceAmstoutz vinceAmstoutz force-pushed the feat-doctrine-filters-like-laravel-filters branch 14 times, most recently from 68d2dfb to 3736645 Compare November 13, 2024 13:11
@vinceAmstoutz vinceAmstoutz force-pushed the feat-doctrine-filters-like-laravel-filters branch from 3736645 to 74919ff Compare November 13, 2024 13:59
src/Doctrine/Odm/Extension/ParameterExtension.php Outdated Show resolved Hide resolved
src/Doctrine/Odm/Filter/ExistsFilter.php Outdated Show resolved Hide resolved
src/Doctrine/Odm/Filter/ExistsFilter.php Show resolved Hide resolved
src/Doctrine/Orm/Filter/ExistsFilter.php Outdated Show resolved Hide resolved
src/Doctrine/Odm/Filter/OrderFilter.php Show resolved Hide resolved
src/Doctrine/Orm/Extension/ParameterExtension.php Outdated Show resolved Hide resolved
src/Doctrine/Orm/Filter/ExistsFilter.php Show resolved Hide resolved
src/Doctrine/Orm/Filter/OrderFilter.php Show resolved Hide resolved
@vinceAmstoutz vinceAmstoutz force-pushed the feat-doctrine-filters-like-laravel-filters branch from 74919ff to 4456cb1 Compare November 18, 2024 11:06
@vinceAmstoutz vinceAmstoutz force-pushed the feat-doctrine-filters-like-laravel-filters branch from 4456cb1 to 7513e53 Compare November 18, 2024 13:02
Comment on lines +288 to +295
if (str_contains($parameter->getKey(), ':property')) {
$properties = [];
foreach (array_keys($parameter->getExtraProperties()['_properties'] ?? []) as $property) {
$properties[] = [$property => ['type' => 'string', 'enum' => ['asc', 'desc']]];
}

return ['type' => 'object', 'properties' => $properties];
}
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't need this as PropertyPlaceholderOpenApiParameterTrait alread declares a parameter per property. If this was for Validation we should move this to the ParameterValidationResourceMetadataCollectionFactory?

src/Symfony/Bundle/Resources/config/metadata/resource.xml Outdated Show resolved Hide resolved
src/Doctrine/Orm/Filter/ExistsFilter.php Outdated Show resolved Hide resolved
new OpenApiParameter(name: $key.'[strictly_after]', in: $in),
new OpenApiParameter(name: $key.'[strictly_before]', in: $in),
];
}
}
Copy link
Member

Choose a reason for hiding this comment

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

note to self: we should probably log if a filter doesn't support the :property placeholder.

@vinceAmstoutz vinceAmstoutz force-pushed the feat-doctrine-filters-like-laravel-filters branch from 7513e53 to eb9277d Compare November 22, 2024 14:13
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.

2 participants