]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ApiBundle/Controller/WallabagRestController.php
Merge pull request #2180 from wallabag/download-pictures
[github/wallabag/wallabag.git] / src / Wallabag / ApiBundle / Controller / WallabagRestController.php
index 0c709ca099dfb964715338ce96ab413ef4310900..50652b777e9fe9b9bf9127640193be9b7405cc85 100644 (file)
@@ -14,6 +14,8 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\Tag;
 use Wallabag\AnnotationBundle\Entity\Annotation;
+use Wallabag\CoreBundle\Event\EntrySavedEvent;
+use Wallabag\CoreBundle\Event\EntryDeletedEvent;
 
 class WallabagRestController extends FOSRestController
 {
@@ -233,9 +235,11 @@ class WallabagRestController extends FOSRestController
 
         $em = $this->getDoctrine()->getManager();
         $em->persist($entry);
-
         $em->flush();
 
+        // entry saved, dispatch event about it!
+        $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
+
         $json = $this->get('serializer')->serialize($entry, 'json');
 
         return (new JsonResponse())->setJson($json);
@@ -308,6 +312,9 @@ class WallabagRestController extends FOSRestController
         $this->validateAuthentication();
         $this->validateUserAccess($entry->getUser()->getId());
 
+        // entry deleted, dispatch event about it!
+        $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
+
         $em = $this->getDoctrine()->getManager();
         $em->remove($entry);
         $em->flush();
@@ -536,7 +543,7 @@ class WallabagRestController extends FOSRestController
     {
         $this->validateAuthentication();
 
-        return $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', [
+        return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:getAnnotations', [
             'entry' => $entry,
         ]);
     }
@@ -544,10 +551,6 @@ class WallabagRestController extends FOSRestController
     /**
      * Creates a new annotation.
      *
-     * @param Request $request
-     * @param Entry   $entry
-     *
-     * @return JsonResponse
      * @ApiDoc(
      *      requirements={
      *          {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"},
@@ -555,15 +558,20 @@ class WallabagRestController extends FOSRestController
      *          {"name"="text", "dataType"="string", "required"=true, "description"=""},
      *      }
      * )
+     *
+     * @param Request $request
+     * @param Entry   $entry
+     *
+     * @return JsonResponse
      */
     public function postAnnotationAction(Request $request, Entry $entry)
     {
         $this->validateAuthentication();
 
-        return $this->forward('WallabagApiBundle:WallabagRest:postAnnotation', [
-                'request' => $request,
-                'entry' => $entry,
-            ]);
+        return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:postAnnotation', [
+            'request' => $request,
+            'entry' => $entry,
+        ]);
     }
 
     /**
@@ -586,10 +594,10 @@ class WallabagRestController extends FOSRestController
     {
         $this->validateAuthentication();
 
-        return $this->forward('WallabagApiBundle:WallabagRest:putAnnotation', [
-                'annotation' => $annotation,
-                'request' => $request,
-            ]);
+        return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:putAnnotation', [
+            'annotation' => $annotation,
+            'request' => $request,
+        ]);
     }
 
     /**
@@ -611,9 +619,9 @@ class WallabagRestController extends FOSRestController
     {
         $this->validateAuthentication();
 
-        return $this->forward('WallabagApiBundle:WallabagRest:deleteAnnotation', [
-                'annotation' => $annotation,
-            ]);
+        return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:deleteAnnotation', [
+            'annotation' => $annotation,
+        ]);
     }
 
     /**