diff options
author | Thomas Citharel <tcit@tcit.fr> | 2016-06-25 21:05:50 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2016-06-25 21:05:50 +0200 |
commit | e5fb89e5d31c1c0645e8dd252bb4f970dc5f3226 (patch) | |
tree | 4eff25e51efe9eeaaa4535621f67d3de734830d4 | |
parent | 33e2aec18b25d2c47774fede22ecd91e936b4400 (diff) | |
download | wallabag-e5fb89e5d31c1c0645e8dd252bb4f970dc5f3226.tar.gz wallabag-e5fb89e5d31c1c0645e8dd252bb4f970dc5f3226.tar.zst wallabag-e5fb89e5d31c1c0645e8dd252bb4f970dc5f3226.zip |
Add since parameter
3 files changed, 53 insertions, 2 deletions
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 | |||
34 | * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, | 34 | * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, |
35 | * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, | 35 | * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, |
36 | * {"name"="tags", "dataType"="string", "required"=false, "format"="api,rest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, | 36 | * {"name"="tags", "dataType"="string", "required"=false, "format"="api,rest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, |
37 | * {"name"="since", "dataType"="integer", "required"=false, "format"="default '0'", "description"="The timestamp since when you want entries updated."}, | ||
37 | * } | 38 | * } |
38 | * ) | 39 | * ) |
39 | * | 40 | * |
@@ -49,10 +50,11 @@ class WallabagRestController extends FOSRestController | |||
49 | $order = $request->query->get('order', 'desc'); | 50 | $order = $request->query->get('order', 'desc'); |
50 | $page = (int) $request->query->get('page', 1); | 51 | $page = (int) $request->query->get('page', 1); |
51 | $perPage = (int) $request->query->get('perPage', 30); | 52 | $perPage = (int) $request->query->get('perPage', 30); |
53 | $since = $request->query->get('since',0); | ||
52 | 54 | ||
53 | $pager = $this->getDoctrine() | 55 | $pager = $this->getDoctrine() |
54 | ->getRepository('WallabagCoreBundle:Entry') | 56 | ->getRepository('WallabagCoreBundle:Entry') |
55 | ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); | 57 | ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order, $since); |
56 | 58 | ||
57 | $pager->setCurrentPage($page); | 59 | $pager->setCurrentPage($page); |
58 | $pager->setMaxPerPage($perPage); | 60 | $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 | |||
95 | * | 95 | * |
96 | * @return array | 96 | * @return array |
97 | */ | 97 | */ |
98 | public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC') | 98 | public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC', $since = 0) |
99 | { | 99 | { |
100 | $qb = $this->createQueryBuilder('e') | 100 | $qb = $this->createQueryBuilder('e') |
101 | ->where('e.user =:userId')->setParameter('userId', $userId); | 101 | ->where('e.user =:userId')->setParameter('userId', $userId); |
@@ -108,6 +108,10 @@ class EntryRepository extends EntityRepository | |||
108 | $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); | 108 | $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); |
109 | } | 109 | } |
110 | 110 | ||
111 | if ($since >= 0) { | ||
112 | $qb->andWhere('e.updatedAt > :since')->setParameter('since', new \DateTime(date('Y-m-d H:i:s', $since))); | ||
113 | } | ||
114 | |||
111 | if ('created' === $sort) { | 115 | if ('created' === $sort) { |
112 | $qb->orderBy('e.id', $order); | 116 | $qb->orderBy('e.id', $order); |
113 | } elseif ('updated' === $sort) { | 117 | } 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 | |||
121 | ); | 121 | ); |
122 | } | 122 | } |
123 | 123 | ||
124 | public function testGetDatedEntries() | ||
125 | { | ||
126 | $this->client->request('GET', '/api/entries', ['since' => 1]); | ||
127 | |||
128 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
129 | |||
130 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
131 | |||
132 | $this->assertGreaterThanOrEqual(1, count($content)); | ||
133 | $this->assertNotEmpty($content['_embedded']['items']); | ||
134 | $this->assertGreaterThanOrEqual(1, $content['total']); | ||
135 | $this->assertEquals(1, $content['page']); | ||
136 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
137 | |||
138 | $this->assertTrue( | ||
139 | $this->client->getResponse()->headers->contains( | ||
140 | 'Content-Type', | ||
141 | 'application/json' | ||
142 | ) | ||
143 | ); | ||
144 | } | ||
145 | |||
146 | public function testGetDatedSupEntries() | ||
147 | { | ||
148 | $future = new \DateTime(date('Y-m-d H:i:s')); | ||
149 | $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]); | ||
150 | |||
151 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
152 | |||
153 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
154 | |||
155 | $this->assertGreaterThanOrEqual(1, count($content)); | ||
156 | $this->assertEmpty($content['_embedded']['items']); | ||
157 | $this->assertEquals(0, $content['total']); | ||
158 | $this->assertEquals(1, $content['page']); | ||
159 | $this->assertEquals(1, $content['pages']); | ||
160 | |||
161 | $this->assertTrue( | ||
162 | $this->client->getResponse()->headers->contains( | ||
163 | 'Content-Type', | ||
164 | 'application/json' | ||
165 | ) | ||
166 | ); | ||
167 | } | ||
168 | |||
124 | public function testDeleteEntry() | 169 | public function testDeleteEntry() |
125 | { | 170 | { |
126 | $entry = $this->client->getContainer() | 171 | $entry = $this->client->getContainer() |