:sparkles: aggregates support + filterable includes / aggregates
closes #127
Hello,
Here you can find the PR to allow aggregates. This also includes filtering on aggregates / filters.
Two way of doing this: Using query params (no filters):
localhost/api/users/search?include=posts&aggregateAvg=posts.id
Using post params (search):
{
"aggregate": [
{
"relation": "posts",
"type": "count",
"filters": [
{"field" : "created_at", "operator" : ">=", "value" : "2020-01-01"},
{"nested": [
{"field": "id", "operator": ">", "value": 20},
{"field": "id", "operator": ">", "value": 21, "type": "or"}
]}
]
},
{
"relation": "posts.id",
"type": "avg",
"filters": [
{"field" : "created_at", "operator" : ">=", "value" : "2020-01-01"},
{"nested": [
{"field": "id", "operator": ">", "value": 20},
{"field": "id", "operator": ">", "value": 21, "type": "or"}
]}
]
},
{
"relation": "posts.id",
"type": "sum"
}
],
"include": [
{
"relation": "posts",
"filters": [
{"field" : "created_at", "operator" : ">=", "value" : "2020-01-01"},
{"nested": [
{"field": "id", "operator": ">", "value": 10},
{"field": "id", "operator": ">", "value": 11, "type": "or"}
]}
]
}
]
}
Nested filters are also possible on aggregates / includes.
Filters works natively with "filterableBy" present in controller.
I took time to refactor some of my previous code. I also rewrote the "include" part to make it compatible with post params and remove some duplicated code.
TODO IN PROGRESS:
- [x] Documentation
- [x] Testing
Please do not merge without these, i'm currently working on it
@alexzarbn Do you have any idea why I have some checks (depending on PHP version and Laravel) that gives query params to
$request->post()
This was a requirement on my side to keep harmonisation, i'm quite confused this happens I didn't know about it
@alexzarbn PR is almost ready i need to update tests for older versions, add documentation and change one bribe of logic in the app (see @TODO in code). Could you make your code review while waiting since this feature is heavy ?
Thanks, Gautier
Hi @GautierDele,
Thank you so much for the PR! The implementation looks great, let me review it in depth right now ~
Can I have your help with those tests @alexzarbn i did set up an environment on my side with php 7.4 and Laravel 6 using your sample projet and i can't manage to reproduce the error giving by automation ...
Can you reproduce those non assertions on your side ?
All ready on my side @alexzarbn, waiting for your feedback 😄
Awesome, merging ✨