]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #1754 from wallabag/v2-api-new-properties-light
authorNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 4 Mar 2016 11:31:27 +0000 (12:31 +0100)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 4 Mar 2016 11:31:27 +0000 (12:31 +0100)
Add starred & archive properties to API

src/Wallabag/ApiBundle/Controller/WallabagRestController.php
src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php

index 03990088218971850a9c87240381e911c3a1a2e0..35a90edde12bee3bc8b923edda9fa7311a4ff963 100644 (file)
@@ -97,6 +97,8 @@ 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"},
      *       }
      * )
      *
@@ -107,6 +109,8 @@ class WallabagRestController extends FOSRestController
         $this->validateAuthentication();
 
         $url = $request->request->get('url');
+        $isArchived = $request->request->get('archive');
+        $isStarred = $request->request->get('starred');
 
         $entry = $this->get('wallabag_core.content_proxy')->updateEntry(
             new Entry($this->getUser()),
@@ -118,8 +122,17 @@ class WallabagRestController extends FOSRestController
             $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags);
         }
 
+        if (true === (bool) $isStarred) {
+            $entry->setStarred(true);
+        }
+
+        if (true === (bool) $isArchived) {
+            $entry->setArchived(true);
+        }
+
         $em = $this->getDoctrine()->getManager();
         $em->persist($entry);
+
         $em->flush();
 
         $json = $this->get('serializer')->serialize($entry, 'json');
index 22894a77f756e6ededda60123699abeb30b80b21..630b75bfe62adb2bbd21d387635e8613a027a587 100644 (file)
@@ -162,6 +162,24 @@ 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 testPatchEntry()
     {
         $entry = $this->client->getContainer()