X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FApiBundle%2FController%2FSearchRestController.php;fp=src%2FWallabag%2FApiBundle%2FController%2FSearchRestController.php;h=d9f99844c6a043c8210f873d6651c3067997d869;hb=c6024246b744e411175318065f7c396bbb5a213e;hp=0000000000000000000000000000000000000000;hpb=a8f4f7665c98753cca15140c283d49e0aa4cd0ab;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ApiBundle/Controller/SearchRestController.php b/src/Wallabag/ApiBundle/Controller/SearchRestController.php new file mode 100644 index 00000000..d9f99844 --- /dev/null +++ b/src/Wallabag/ApiBundle/Controller/SearchRestController.php @@ -0,0 +1,65 @@ +validateAuthentication(); + + $term = $request->query->get('term'); + $page = (int) $request->query->get('page', 1); + $perPage = (int) $request->query->get('perPage', 30); + + $qb = $this->get('wallabag_core.entry_repository') + ->getBuilderForSearchByUser( + $this->getUser()->getId(), + $term, + null + ); + + $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); + $pager = new Pagerfanta($pagerAdapter); + + $pager->setMaxPerPage($perPage); + $pager->setCurrentPage($page); + + $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); + $paginatedCollection = $pagerfantaFactory->createRepresentation( + $pager, + new Route( + 'api_get_search', + [ + 'term' => $term, + 'page' => $page, + 'perPage' => $perPage, + ], + true + ) + ); + + return $this->sendResponse($paginatedCollection); + } +}