aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-02-24 22:00:24 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2015-03-06 20:50:31 +0100
commita36737f4859e3acbddf5cfe90c279ba725a6d88a (patch)
treeb65709740a5e92bc53eeb0e3e050e0df3e78f3bb /src/Wallabag/CoreBundle/Controller/WallabagRestController.php
parent46bbd8d321e6a00131f0e6ed96fa6f3d693b3678 (diff)
downloadwallabag-a36737f4859e3acbddf5cfe90c279ba725a6d88a.tar.gz
wallabag-a36737f4859e3acbddf5cfe90c279ba725a6d88a.tar.zst
wallabag-a36737f4859e3acbddf5cfe90c279ba725a6d88a.zip
POST entries/tags with test
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/WallabagRestController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/WallabagRestController.php28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
index db9cf1be..e59ad4b7 100644
--- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php
@@ -213,8 +213,34 @@ class WallabagRestController extends Controller
213 * } 213 * }
214 * ) 214 * )
215 */ 215 */
216 public function postEntriesTagsAction(Entry $entry) 216 public function postEntriesTagsAction(Request $request, Entry $entry)
217 { 217 {
218 $tags = explode(',', $request->request->get('tags'));
219
220 foreach ($tags as $label) {
221 $tagEntity = $this
222 ->getDoctrine()
223 ->getRepository('WallabagCoreBundle:Tag')
224 ->findOneByLabel($label);
225
226 if (is_null($tagEntity)) {
227 $tagEntity = new Tag();
228 $tagEntity->setLabel($label);
229 }
230
231 // only add the tag on the entry if the relation doesn't exist
232 if (!$entry->getTags()->contains($tagEntity)) {
233 $entry->addTag($tagEntity);
234 }
235 }
236
237 $em = $this->getDoctrine()->getManager();
238 $em->persist($entry);
239 $em->flush();
240
241 $json = $this->get('serializer')->serialize($entry, 'json');
242
243 return new Response($json, 200, array('application/json'));
218 } 244 }
219 245
220 /** 246 /**