I'm working with API Platform and I'm looking to make something. I made a Person Entity like this :
class Person
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstname;
/**
* @ORM\Column(type="datetime")
*/
private $birthdate;
}
With defined groups for the fields :
App\Entity\Person:
attributes:
id:
groups: ['private']
name:
groups: ['public']
firstname:
groups: ['public']
birthdate:
groups: ['public']
I also precised that if I want all the collection of that resource, only public fields should be serialized :
App\Entity\Person:
collectionOperations:
get:
filters: ['search_filter']
normalization_context:
groups: ['public']
formats: ['json']
As you can see, I applied a search filter. In that case I can retrieve resources from their fields precised as query parameters.
However, I want to apply this filter only with public fields. So I don't want that the http://localhost/api/people?id=1 request works, since the id field is private.
I see that it is possible to precise the fields wanted as arguments for SearchFilter, but it would be more useful to precise the group name instead, because I intend to work with more groups.
I tried to look in GroupFilters, but it doesn't help me, because it is a serializer filter...
What do you recommend me ?