]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ApiBundle/Controller/WallabagRestController.php
fix cs and phpdoc
[github/wallabag/wallabag.git] / src / Wallabag / ApiBundle / Controller / WallabagRestController.php
index 6275afa0afc006c4d7b65c17c982d029f56eff34..0c709ca099dfb964715338ce96ab413ef4310900 100644 (file)
@@ -528,30 +528,26 @@ class WallabagRestController extends FOSRestController
      *      }
      * )
      *
-     * @return Response
+     * @param Entry $entry
+     *
+     * @return JsonResponse
      */
     public function getAnnotationsAction(Entry $entry)
     {
-
         $this->validateAuthentication();
 
-        $annotationRows = $this
-                ->getDoctrine()
-                ->getRepository('WallabagAnnotationBundle:Annotation')
-                ->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId());
-        $total = count($annotationRows);
-        $annotations = array('total' => $total, 'rows' => $annotationRows);
-
-        $json = $this->get('serializer')->serialize($annotations, 'json');
-
-        return $this->renderJsonResponse($json);
+        return $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', [
+            'entry' => $entry,
+        ]);
     }
 
     /**
      * Creates a new annotation.
      *
-     * @param Entry $entry
+     * @param Request $request
+     * @param Entry   $entry
      *
+     * @return JsonResponse
      * @ApiDoc(
      *      requirements={
      *          {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"},
@@ -559,35 +555,15 @@ class WallabagRestController extends FOSRestController
      *          {"name"="text", "dataType"="string", "required"=true, "description"=""},
      *      }
      * )
-     *
-     * @return Response
      */
     public function postAnnotationAction(Request $request, Entry $entry)
     {
         $this->validateAuthentication();
 
-        $data = json_decode($request->getContent(), true);
-
-        $em = $this->getDoctrine()->getManager();
-
-        $annotation = new Annotation($this->getUser());
-
-        $annotation->setText($data['text']);
-        if (array_key_exists('quote', $data)) {
-            $annotation->setQuote($data['quote']);
-        }
-        if (array_key_exists('ranges', $data)) {
-            $annotation->setRanges($data['ranges']);
-        }
-
-        $annotation->setEntry($entry);
-
-        $em->persist($annotation);
-        $em->flush();
-
-        $json = $this->get('serializer')->serialize($annotation, 'json');
-
-        return $this->renderJsonResponse($json);
+        return $this->forward('WallabagApiBundle:WallabagRest:postAnnotation', [
+                'request' => $request,
+                'entry' => $entry,
+            ]);
     }
 
     /**
@@ -601,25 +577,19 @@ class WallabagRestController extends FOSRestController
      *
      * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation")
      *
-     * @return Response
+     * @param Annotation $annotation
+     * @param Request    $request
+     *
+     * @return JsonResponse
      */
     public function putAnnotationAction(Annotation $annotation, Request $request)
     {
-
         $this->validateAuthentication();
 
-        $data = json_decode($request->getContent(), true);
-
-        if (!is_null($data['text'])) {
-            $annotation->setText($data['text']);
-        }
-
-        $em = $this->getDoctrine()->getManager();
-        $em->flush();
-
-        $json = $this->get('serializer')->serialize($annotation, 'json');
-
-        return $this->renderJsonResponse($json);
+        return $this->forward('WallabagApiBundle:WallabagRest:putAnnotation', [
+                'annotation' => $annotation,
+                'request' => $request,
+            ]);
     }
 
     /**
@@ -633,20 +603,17 @@ class WallabagRestController extends FOSRestController
      *
      * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation")
      *
-     * @return Response
+     * @param Annotation $annotation
+     *
+     * @return JsonResponse
      */
     public function deleteAnnotationAction(Annotation $annotation)
     {
-
         $this->validateAuthentication();
 
-        $em = $this->getDoctrine()->getManager();
-        $em->remove($annotation);
-        $em->flush();
-
-        $json = $this->get('serializer')->serialize($annotation, 'json');
-
-        return $this->renderJsonResponse($json);
+        return $this->forward('WallabagApiBundle:WallabagRest:deleteAnnotation', [
+                'annotation' => $annotation,
+            ]);
     }
 
     /**