diff --git a/core/filters.md b/core/filters.md index 0a7868e06b0..410ae1fa82e 100644 --- a/core/filters.md +++ b/core/filters.md @@ -519,6 +519,28 @@ It will return all offers with `price` between 12.99 and 15.99. You can filter offers by joining two values, for example: `/offers?price[gt]=12.99&price[lt]=19.99`. +### Uuid Range Filter + +In case you want to filter based on UUIDs (V1 and V6) you'll need to use the `UuidRangeFilter` instead of the `RangeFilter`. +The syntax and behaviour is the same as the normal `RangeFilter`: + +```php +<?php +// api/src/Entity/Offer.php +namespace App\Entity; + +use ApiPlatform\Core\Annotation\ApiFilter; +use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\UuidRangeFilter; + +#[ApiResource] +#[ApiFilter(UuidRangeFilter::class, properties: ['price'])] +class Offer +{ + // ... +} +``` + ### Exists Filter The exists filter allows you to select items based on a nullable field value. diff --git a/core/pagination.md b/core/pagination.md index aeb318bd7a0..c11b0b50083 100644 --- a/core/pagination.md +++ b/core/pagination.md @@ -312,12 +312,14 @@ class Book To configure your resource to use the cursor-based pagination, select your unique sorted field as well as the direction you’ll like the pagination to go via filters and enable the `paginationViaCursor` option. Note that for now you have to declare a `RangeFilter` and an `OrderFilter` on the property used for the cursor-based pagination. +Please also keep in mind that the order is not applied by default, so you'll have to apply it yourself in order for the pagination to work correctly. + The following configuration also works on a specific operation: ```php <?php + // api/src/Entity/Book.php -namespace App\Entity; use ApiPlatform\Core\Annotation\ApiFilter; use ApiPlatform\Metadata\ApiResource; @@ -338,6 +340,32 @@ class Book } ``` +If you are using a UUID as primary key (Uuid V1 or V6) you'll have to use the `UuidRangeFilter` instead: + +```php +<?php + +// api/src/Entity/Book.php + +use ApiPlatform\Core\Annotation\ApiFilter; +use ApiPlatform\Metadata\ApiResource; +use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\OrderFilter; +use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\UuidRangeFilter; + +#[ApiResource(attributes: [ + paginationPartial: true, + paginationViaCursor: [ + ['field' => 'id', 'direction' => 'DESC'] + ] +)] +#[ApiFilter(UuidRangeFilter::class, properties: ["id"])] +#[ApiFilter(OrderFilter::class, properties: ["id" => "DESC"])] +class Book +{ + // ... +} +``` + To know more about cursor-based pagination take a look at [this blog post on medium (draft)](https://medium.com/@sroze/74fd1d324723). ## Controlling The Behavior of The Doctrine ORM Paginator