Replies: 3 comments
-
About |
Beta Was this translation helpful? Give feedback.
-
I developed another solution for my current project. I needed to provide a single input to my users to search in several fields. They will be able to search for example in firstname, lastname, username and email using only one query parameter. The annotation look like this:
Assuming the database contains 2 users:
Searching for "Jon" => will return only "Jon Doe" |
Beta Was this translation helpful? Give feedback.
-
I found the following (mostly other issues etc. here):
And then there is the api of the existing ORM Filter classes. They can become composable by implementing an extra interface, see my comment on RFC Filter composition For a Filter whose composition can be configured one could do something similar to this WhereFilter (FilterLogic), but as input use an array from the configuration specifying nested logic and the results of evaluating Symfony Expressions that have access to $context. Such an expression will throw an exception if a key from $context it accesses is not present. That exception should be caught resulting in the result of only that expression not getting added to the logic. Here is an example: @ApiFilter(SearchFilter:class, properties={"sku": "iexact", "name": "iword_start", "description": "iword_start"})
@ApiFilter(DateFilter::class, properties={"published": DateFilter::EXCLUDE_NULL})
@ApiFilter(Compose:class, arguments={
"composition": {
"or": {
"filter('sku', context.filters.q)",
"filter('name', filters.q)",
"filter('description', context.filters.q)",
"logic.and(
filter('published[after]', context.filters.from),
filter('published[before]', context.filters.through)
)"
}
},
"apply": "andWhere"
}) |
Beta Was this translation helpful? Give feedback.
-
We're looking for popular opinions about filters RFC. Here are two examples of well-done filter composition:
Do you know other similar APIs that could inspire us? Please share!
Linked issues:
Beta Was this translation helpful? Give feedback.
All reactions