diff options
author | Thomas Citharel <tcit@tcit.fr> | 2016-02-08 22:00:38 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-03-04 11:39:20 +0100 |
commit | 816ad4051baa401e46b42121e6813345a8030032 (patch) | |
tree | cc0214648df9ef95da733ee3b1fd22cc302cd7a7 /src | |
parent | 9e3355ee4f9601cb4af95323c8b2935b6f2bd838 (diff) | |
download | wallabag-816ad4051baa401e46b42121e6813345a8030032.tar.gz wallabag-816ad4051baa401e46b42121e6813345a8030032.tar.zst wallabag-816ad4051baa401e46b42121e6813345a8030032.zip |
add more properties for entries #1634
Diffstat (limited to 'src')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 19 | ||||
-rw-r--r-- | src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php | 34 |
2 files changed, 53 insertions, 0 deletions
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 | |||
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"}, | ||
102 | * {"name"="content", "dataType"="string", "required"=false, "format"="content", "description"="content you want to pass directly"}, | ||
100 | * } | 103 | * } |
101 | * ) | 104 | * ) |
102 | * | 105 | * |
@@ -107,6 +110,9 @@ class WallabagRestController extends FOSRestController | |||
107 | $this->validateAuthentication(); | 110 | $this->validateAuthentication(); |
108 | 111 | ||
109 | $url = $request->request->get('url'); | 112 | $url = $request->request->get('url'); |
113 | $content = $request->request->get('content'); | ||
114 | $isArchived = $request->request->get('archive'); | ||
115 | $isStarred = $request->request->get('starred'); | ||
110 | 116 | ||
111 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry( | 117 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry( |
112 | new Entry($this->getUser()), | 118 | new Entry($this->getUser()), |
@@ -118,8 +124,21 @@ class WallabagRestController extends FOSRestController | |||
118 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); | 124 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); |
119 | } | 125 | } |
120 | 126 | ||
127 | if (!empty($isStarred)) { | ||
128 | $entry->setStarred($isStarred); | ||
129 | } | ||
130 | |||
131 | if (!empty($isArchived)) { | ||
132 | $entry->setArchived($isArchived); | ||
133 | } | ||
134 | |||
135 | if (!empty($content)) { | ||
136 | $entry->setContent($content); | ||
137 | } | ||
138 | |||
121 | $em = $this->getDoctrine()->getManager(); | 139 | $em = $this->getDoctrine()->getManager(); |
122 | $em->persist($entry); | 140 | $em->persist($entry); |
141 | |||
123 | $em->flush(); | 142 | $em->flush(); |
124 | 143 | ||
125 | $json = $this->get('serializer')->serialize($entry, 'json'); | 144 | $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 | |||
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 | |||
183 | public function testPostEntryWithContent() | ||
184 | { | ||
185 | $this->client->request('POST', '/api/entries.json', array( | ||
186 | 'url' => 'http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', | ||
187 | 'content' => 'This is a new content for my entry', | ||
188 | )); | ||
189 | |||
190 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
191 | |||
192 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
193 | |||
194 | $this->assertGreaterThan(0, $content['id']); | ||
195 | $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']); | ||
196 | $this->assertEquals('This is a new content for my entry', $content['content']); | ||
197 | } | ||
198 | |||
165 | public function testPatchEntry() | 199 | public function testPatchEntry() |
166 | { | 200 | { |
167 | $entry = $this->client->getContainer() | 201 | $entry = $this->client->getContainer() |