]> 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 fa573988b9c90b60628514850e4e5e9d633d7d2f..50652b777e9fe9b9bf9127640193be9b7405cc85 100644 (file)
@@ -6,13 +6,16 @@ use FOS\RestBundle\Controller\FOSRestController;
 use Hateoas\Configuration\Route as HateoasRoute;
 use Hateoas\Representation\Factory\PagerfantaFactory;
 use Nelmio\ApiDocBundle\Annotation\ApiDoc;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
 use Symfony\Component\Security\Core\Exception\AccessDeniedException;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\Tag;
-use FOS\RestBundle\Controller\Annotations\Route;
+use Wallabag\AnnotationBundle\Entity\Annotation;
+use Wallabag\CoreBundle\Event\EntrySavedEvent;
+use Wallabag\CoreBundle\Event\EntryDeletedEvent;
 
 class WallabagRestController extends FOSRestController
 {
@@ -167,8 +170,6 @@ class WallabagRestController extends FOSRestController
      *      }
      * )
      *
-     * @Route(requirements={"_format"="epub|mobi|pdf|txt|csv"})
-     *
      * @return Response
      */
     public function getEntryExportAction(Entry $entry, Request $request)
@@ -234,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);
@@ -309,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();
@@ -520,6 +526,104 @@ class WallabagRestController extends FOSRestController
         return (new JsonResponse())->setJson($json);
     }
 
+    /**
+     * Retrieve annotations for an entry.
+     *
+     * @ApiDoc(
+     *      requirements={
+     *          {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
+     *      }
+     * )
+     *
+     * @param Entry $entry
+     *
+     * @return JsonResponse
+     */
+    public function getAnnotationsAction(Entry $entry)
+    {
+        $this->validateAuthentication();
+
+        return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:getAnnotations', [
+            'entry' => $entry,
+        ]);
+    }
+
+    /**
+     * Creates a new annotation.
+     *
+     * @ApiDoc(
+     *      requirements={
+     *          {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"},
+     *          {"name"="quote", "dataType"="string", "required"=false, "description"="Optional, quote for the annotation"},
+     *          {"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('WallabagAnnotationBundle:WallabagAnnotation:postAnnotation', [
+            'request' => $request,
+            'entry' => $entry,
+        ]);
+    }
+
+    /**
+     * Updates an annotation.
+     *
+     * @ApiDoc(
+     *      requirements={
+     *          {"name"="annotation", "dataType"="string", "requirement"="\w+", "description"="The annotation ID"}
+     *      }
+     * )
+     *
+     * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation")
+     *
+     * @param Annotation $annotation
+     * @param Request    $request
+     *
+     * @return JsonResponse
+     */
+    public function putAnnotationAction(Annotation $annotation, Request $request)
+    {
+        $this->validateAuthentication();
+
+        return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:putAnnotation', [
+            'annotation' => $annotation,
+            'request' => $request,
+        ]);
+    }
+
+    /**
+     * Removes an annotation.
+     *
+     * @ApiDoc(
+     *      requirements={
+     *          {"name"="annotation", "dataType"="string", "requirement"="\w+", "description"="The annotation ID"}
+     *      }
+     * )
+     *
+     * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation")
+     *
+     * @param Annotation $annotation
+     *
+     * @return JsonResponse
+     */
+    public function deleteAnnotationAction(Annotation $annotation)
+    {
+        $this->validateAuthentication();
+
+        return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:deleteAnnotation', [
+            'annotation' => $annotation,
+        ]);
+    }
+
     /**
      * Retrieve version number.
      *