I am using a state provider of API-Platfrom in symfony project to represent my data and using built-in API platform filters I need to add totalCost, the total number in the meta property in the paginated result.
I could not find any clear solution for that:
{
"links": {
"self": "/bmp-api/campaign-management/campaign-overview?page=1",
"first": "/bmp-api/campaign-management/campaign-overview?page=1",
"last": "/bmp-api/campaign-management/campaign-overview?page=821",
"next": "/bmp-api/campaign-management/campaign-overview?page=2"
},
"meta": {
"totalItems": 8210,
"itemsPerPage": 10,
"currentPage": 1
},
"data": [
this is my state provider:
class CampaignOverviewCollectionProvider implements ProviderInterface
{
public function __construct(
private readonly ProviderInterface $provider,
) {
}
public function provide(Operation $operation, array $uriVariables = [], array $context = [])
{
/** @var Paginator $campaignCollection */
$campaignCollection = $this->provider->provide($operation, $uriVariables, $context);
return $campaignCollection;
}