diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-03-04 12:31:27 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-03-04 12:31:27 +0100 |
commit | e18138dbca536ebd49c938144f9d051e5276d4ea (patch) | |
tree | 501001e8866d7c1c7c4e22c384b208b68aff257b | |
parent | 9e3355ee4f9601cb4af95323c8b2935b6f2bd838 (diff) | |
parent | fba9e7d44d5987a603add50dc450f50079340dcc (diff) | |
download | wallabag-e18138dbca536ebd49c938144f9d051e5276d4ea.tar.gz wallabag-e18138dbca536ebd49c938144f9d051e5276d4ea.tar.zst wallabag-e18138dbca536ebd49c938144f9d051e5276d4ea.zip |
Merge pull request #1754 from wallabag/v2-api-new-properties-light
Add starred & archive properties to API
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 13 | ||||
-rw-r--r-- | src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php | 18 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 03990088..35a90edd 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -97,6 +97,8 @@ class WallabagRestController extends FOSRestController | |||
97 | * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."}, | 97 | * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."}, |
98 | * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."}, | 98 | * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."}, |
99 | * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, | 99 | * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, |
100 | * {"name"="starred", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already starred"}, | ||
101 | * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already archived"}, | ||
100 | * } | 102 | * } |
101 | * ) | 103 | * ) |
102 | * | 104 | * |
@@ -107,6 +109,8 @@ class WallabagRestController extends FOSRestController | |||
107 | $this->validateAuthentication(); | 109 | $this->validateAuthentication(); |
108 | 110 | ||
109 | $url = $request->request->get('url'); | 111 | $url = $request->request->get('url'); |
112 | $isArchived = $request->request->get('archive'); | ||
113 | $isStarred = $request->request->get('starred'); | ||
110 | 114 | ||
111 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry( | 115 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry( |
112 | new Entry($this->getUser()), | 116 | new Entry($this->getUser()), |
@@ -118,8 +122,17 @@ class WallabagRestController extends FOSRestController | |||
118 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); | 122 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); |
119 | } | 123 | } |
120 | 124 | ||
125 | if (true === (bool) $isStarred) { | ||
126 | $entry->setStarred(true); | ||
127 | } | ||
128 | |||
129 | if (true === (bool) $isArchived) { | ||
130 | $entry->setArchived(true); | ||
131 | } | ||
132 | |||
121 | $em = $this->getDoctrine()->getManager(); | 133 | $em = $this->getDoctrine()->getManager(); |
122 | $em->persist($entry); | 134 | $em->persist($entry); |
135 | |||
123 | $em->flush(); | 136 | $em->flush(); |
124 | 137 | ||
125 | $json = $this->get('serializer')->serialize($entry, 'json'); | 138 | $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..630b75bf 100644 --- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php | |||
@@ -162,6 +162,24 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
162 | $this->assertCount(1, $content['tags']); | 162 | $this->assertCount(1, $content['tags']); |
163 | } | 163 | } |
164 | 164 | ||
165 | public function testPostArchivedEntry() | ||
166 | { | ||
167 | $this->client->request('POST', '/api/entries.json', array( | ||
168 | 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', | ||
169 | 'archive' => true, | ||
170 | 'starred' => false, | ||
171 | )); | ||
172 | |||
173 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
174 | |||
175 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
176 | |||
177 | $this->assertGreaterThan(0, $content['id']); | ||
178 | $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']); | ||
179 | $this->assertEquals(true, $content['is_archived']); | ||
180 | $this->assertEquals(false, $content['is_starred']); | ||
181 | } | ||
182 | |||
165 | public function testPatchEntry() | 183 | public function testPatchEntry() |
166 | { | 184 | { |
167 | $entry = $this->client->getContainer() | 185 | $entry = $this->client->getContainer() |