diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php index eb1de49d3..7643db0e9 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php @@ -48,18 +48,18 @@ class ApiController extends AbstractCRUDController return $response; } - $response = $this->onPostCheckACL($action, $request, $entity, $_format); + $response = $this->onPostCheckACL($action, $request, $_format, $entity); if ($response instanceof Response) { return $response; } - $response = $this->onBeforeSerialize($action, $request, $entity, $_format); + $response = $this->onBeforeSerialize($action, $request, $_format, $entity); if ($response instanceof Response) { return $response; } if ($_format === 'json') { - $context = $this->getContextForSerialization($action, $request, $entity, $_format); + $context = $this->getContextForSerialization($action, $request, $_format, $entity); return $this->json($entity, Response::HTTP_OK, [], $context); } else { @@ -67,7 +67,7 @@ class ApiController extends AbstractCRUDController } } - public function onBeforeSerialize(string $action, Request $request, $entity, string $_format): ?Response + public function onBeforeSerialize(string $action, Request $request, $_format, $entity): ?Response { return null; } @@ -118,15 +118,7 @@ class ApiController extends AbstractCRUDController * 3. build a query, using `queryEntities` * x. fetch the results, using `getQueryResult` * x. Launch `onPostIndexFetchQuery`. If it does return a response instance, return it - * 4. create default parameters: - * - * The default parameters are: - * - * * entities: the list en entities ; - * * crud_name: the name of the crud ; - * * paginator: a paginator element ; - * 5. Launch rendering, the parameter is fetch using `getTemplateFor` - * The parameters may be personnalized using `generateTemplateParameter`. + * 4. Serialize the entities in a Collection, using `SerializeCollection` * * @param string $action * @param Request $request @@ -178,22 +170,24 @@ class ApiController extends AbstractCRUDController return $response; } - return $this->serializeCollectionItems($action, $request, $_format, $paginator, $entities); + return $this->serializeCollection($action, $request, $_format, $paginator, $entities); } /** * Serialize collections * */ - protected function serializeCollectionItems(string $action, Request $request, string $_format, PaginatorInterface $paginator, $entities): Response + protected function serializeCollection(string $action, Request $request, string $_format, PaginatorInterface $paginator, $entities): Response { - $model = new Collection($entities, $paginator); + $model = new Collection($entities, $paginator); - return $this->json($model); + $context = $this->getContextForSerialization($action, $request, $_format, $entities); + + return $this->json($model, Response::HTTP_OK, [], $context); } - protected function getContextForSerialization(string $action, Request $request, $entity, $_format): array + protected function getContextForSerialization(string $action, Request $request, string $_format, $entity): array { return []; } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php index 9227a8d58..55857de4c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php @@ -22,7 +22,7 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Entity\AccompanyingPeriod\OriginRepository; +use Chill\PersonBundle\Repository\AccompanyingPeriod\OriginRepository; use Doctrine\ORM\Mapping as ORM; /** diff --git a/src/Bundle/ChillPersonBundle/config/services/repository.yaml b/src/Bundle/ChillPersonBundle/config/services/repository.yaml index e899ba9e1..b99402bcf 100644 --- a/src/Bundle/ChillPersonBundle/config/services/repository.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/repository.yaml @@ -23,3 +23,8 @@ services: arguments: - '@Doctrine\Persistence\ManagerRegistry' tags: [ doctrine.repository_service ] + + Chill\PersonBundle\Repository\AccompanyingPeriod\OriginRepository: + arguments: + - '@Doctrine\Persistence\ManagerRegistry' + tags: [ doctrine.repository_service ]