From: Thomas Citharel Date: Mon, 8 Feb 2016 21:00:38 +0000 (+0100) Subject: add more properties for entries #1634 X-Git-Tag: 2.0.0-beta.2~14^2~2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=816ad4051baa401e46b42121e6813345a8030032;p=github%2Fwallabag%2Fwallabag.git add more properties for entries #1634 --- diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 03990088..ad85a177 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -97,6 +97,9 @@ class WallabagRestController extends FOSRestController * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."}, * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."}, * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, + * {"name"="starred", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already starred"}, + * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already archived"}, + * {"name"="content", "dataType"="string", "required"=false, "format"="content", "description"="content you want to pass directly"}, * } * ) * @@ -107,6 +110,9 @@ class WallabagRestController extends FOSRestController $this->validateAuthentication(); $url = $request->request->get('url'); + $content = $request->request->get('content'); + $isArchived = $request->request->get('archive'); + $isStarred = $request->request->get('starred'); $entry = $this->get('wallabag_core.content_proxy')->updateEntry( new Entry($this->getUser()), @@ -118,8 +124,21 @@ class WallabagRestController extends FOSRestController $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); } + if (!empty($isStarred)) { + $entry->setStarred($isStarred); + } + + if (!empty($isArchived)) { + $entry->setArchived($isArchived); + } + + if (!empty($content)) { + $entry->setContent($content); + } + $em = $this->getDoctrine()->getManager(); $em->persist($entry); + $em->flush(); $json = $this->get('serializer')->serialize($entry, 'json'); diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php index 22894a77..6e64d84f 100644 --- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php @@ -162,6 +162,40 @@ class WallabagRestControllerTest extends WallabagApiTestCase $this->assertCount(1, $content['tags']); } + public function testPostArchivedEntry() + { + $this->client->request('POST', '/api/entries.json', array( + 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', + 'archive' => true, + 'starred' => false, + )); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThan(0, $content['id']); + $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); + $this->assertEquals(true, $content['is_archived']); + $this->assertEquals(false, $content['is_starred']); + } + + public function testPostEntryWithContent() + { + $this->client->request('POST', '/api/entries.json', array( + 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', + 'content' => 'This is a new content for my entry', + )); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThan(0, $content['id']); + $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); + $this->assertEquals('This is a new content for my entry', $content['content']); + } + public function testPatchEntry() { $entry = $this->client->getContainer()