From: Thomas Citharel Date: Sat, 25 Jun 2016 19:05:50 +0000 (+0200) Subject: Add since parameter X-Git-Tag: 2.1.0~66^2~1 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=e5fb89e5d31c1c0645e8dd252bb4f970dc5f3226;p=github%2Fwallabag%2Fwallabag.git Add since parameter --- diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index af24e498..7d624812 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -34,6 +34,7 @@ class WallabagRestController extends FOSRestController * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, * {"name"="tags", "dataType"="string", "required"=false, "format"="api,rest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, + * {"name"="since", "dataType"="integer", "required"=false, "format"="default '0'", "description"="The timestamp since when you want entries updated."}, * } * ) * @@ -49,10 +50,11 @@ class WallabagRestController extends FOSRestController $order = $request->query->get('order', 'desc'); $page = (int) $request->query->get('page', 1); $perPage = (int) $request->query->get('perPage', 30); + $since = $request->query->get('since',0); $pager = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Entry') - ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); + ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order, $since); $pager->setCurrentPage($page); $pager->setMaxPerPage($perPage); diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 4d45e5f5..4b607c81 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -95,7 +95,7 @@ class EntryRepository extends EntityRepository * * @return array */ - public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC') + public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC', $since = 0) { $qb = $this->createQueryBuilder('e') ->where('e.user =:userId')->setParameter('userId', $userId); @@ -108,6 +108,10 @@ class EntryRepository extends EntityRepository $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); } + if ($since >= 0) { + $qb->andWhere('e.updatedAt > :since')->setParameter('since', new \DateTime(date('Y-m-d H:i:s', $since))); + } + if ('created' === $sort) { $qb->orderBy('e.id', $order); } elseif ('updated' === $sort) { diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index c39cc357..f256a7f9 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -121,6 +121,51 @@ class WallabagRestControllerTest extends WallabagApiTestCase ); } + public function testGetDatedEntries() + { + $this->client->request('GET', '/api/entries', ['since' => 1]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertNotEmpty($content['_embedded']['items']); + $this->assertGreaterThanOrEqual(1, $content['total']); + $this->assertEquals(1, $content['page']); + $this->assertGreaterThanOrEqual(1, $content['pages']); + + $this->assertTrue( + $this->client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + } + + public function testGetDatedSupEntries() + { + $future = new \DateTime(date('Y-m-d H:i:s')); + $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertEmpty($content['_embedded']['items']); + $this->assertEquals(0, $content['total']); + $this->assertEquals(1, $content['page']); + $this->assertEquals(1, $content['pages']); + + $this->assertTrue( + $this->client->getResponse()->headers->contains( + 'Content-Type', + 'application/json' + ) + ); + } + public function testDeleteEntry() { $entry = $this->client->getContainer()