paginatorFactory = $paginatorFactory; $this->geographicalUnitRepository = $geographicalUnitRepository; $this->security = $security; $this->serializer = $serializer; } /** * @Route("/api/1.0/main/geographical-unit/by-address/{id}.{_format}", requirements={"_format": "json"}) */ public function getGeographicalUnitCoveringAddress(Address $address): JsonResponse { if (!$this->security->isGranted('ROLE_USER')) { throw new AccessDeniedHttpException(); } $count = $this->geographicalUnitRepository->countGeographicalUnitContainingAddress($address); $pagination = $this->paginatorFactory->create($count); $units = $this->geographicalUnitRepository->findGeographicalUnitContainingAddress($address, $pagination->getCurrentPageFirstItemNumber(), $pagination->getItemsPerPage()); $collection = new Collection($units, $pagination); return new JsonResponse( $this->serializer->serialize($collection, 'json', [AbstractNormalizer::GROUPS => ['read']]), JsonResponse::HTTP_OK, [], true ); } }