First of all, I want to inform you that I already read the docs about the problem I'm having today, and I also made a search on StackOverflow and Google, but didn't find a proper solution.
I am building a Customer Relationship Management API for practice sake with Symfony 4 and API Platform. I already learned a lot about API Platform, and even though I could have used annotations for resources configuration, I forced myself to use YAML in order to learn more about it.
So, I have a Customer resource which has several attributes: id, firstname, lastname, emailAddress, company, createdAt, updatedAt, and owner. My goal is to add a SearchFilter on this resource (in YAML) and add most of the attributes as properties of this filter.
I already tried the solution given here: https://github.com/api-platform/core/issues/1755. The problem is that I can't manage to make it work. In services.yaml, I see that you can add arguments, but I don't know what equivalent you can find in annotations...
In config/services.yaml
:
# filters
app.my_filter:
parent: 'api_platform.doctrine.orm.search_filter'
tags: ['api_platform.filter']
autowire: false
autoconfigure: false
public: false
In resources/customer.yaml
:
App\Entity\Customer:
collectionOperations:
get:
normalization_context:
groups: ['Customer:Get']
filters: ['app.my_filter']
What I intend to is something similar to this with annotations in src/Entity/Customer.php
:
/**
* @ApiResource
*
* [...]
*
* @ApiFilter(SearchFilter::class, properties={
* "firstname": "partial",
* "lastname": "partial",
* "emailAddress": "partial",
* "company": "partial"
* })
*/
class Customer
{
...
}
I hope that you'll be able to help and that my problem is clearly explained. If not, please tell me and I'll do my best to give your more details.
Thanks!