mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-22 23:56:29 +00:00
Add since parameter
This commit is contained in:
parent
33e2aec18b
commit
e5fb89e5d3
3 changed files with 53 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue