aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Controller/WallabagRestController.php21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
index 3e25fe49..14f42c48 100644
--- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
@@ -9,6 +9,8 @@ use Symfony\Component\HttpFoundation\Response;
9use Wallabag\CoreBundle\Entity\Entry; 9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\CoreBundle\Entity\Tag; 10use Wallabag\CoreBundle\Entity\Tag;
11use Wallabag\CoreBundle\Service\Extractor; 11use Wallabag\CoreBundle\Service\Extractor;
12use Hateoas\Configuration\Route;
13use Hateoas\Representation\Factory\PagerfantaFactory;
12 14
13class WallabagRestController extends Controller 15class WallabagRestController extends Controller
14{ 16{
@@ -82,20 +84,29 @@ class WallabagRestController extends Controller
82 $isStarred = $request->query->get('star'); 84 $isStarred = $request->query->get('star');
83 $sort = $request->query->get('sort', 'created'); 85 $sort = $request->query->get('sort', 'created');
84 $order = $request->query->get('order', 'desc'); 86 $order = $request->query->get('order', 'desc');
85 $page = $request->query->get('page', 1); 87 $page = (int) $request->query->get('page', 1);
86 $perPage = $request->query->get('perPage', 30); 88 $perPage = (int) $request->query->get('perPage', 30);
87 $tags = $request->query->get('tags', array()); 89 $tags = $request->query->get('tags', array());
88 90
89 $entries = $this 91 $pager = $this
90 ->getDoctrine() 92 ->getDoctrine()
91 ->getRepository('WallabagCoreBundle:Entry') 93 ->getRepository('WallabagCoreBundle:Entry')
92 ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); 94 ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order);
93 95
94 if (!$entries) { 96 if (0 === $pager->getNbResults()) {
95 throw $this->createNotFoundException(); 97 throw $this->createNotFoundException();
96 } 98 }
97 99
98 $json = $this->get('serializer')->serialize($entries, 'json'); 100 $pager->setCurrentPage($page);
101 $pager->setMaxPerPage($perPage);
102
103 $pagerfantaFactory = new PagerfantaFactory('page', 'perPage');
104 $paginatedCollection = $pagerfantaFactory->createRepresentation(
105 $pager,
106 new Route('api_get_entries', [], $absolute = true)
107 );
108
109 $json = $this->get('serializer')->serialize($paginatedCollection, 'json');
99 110
100 return new Response($json, 200, array('application/json')); 111 return new Response($json, 200, array('application/json'));
101 } 112 }