+ return (new JsonResponse())->setJson($json);
+ }
+
+ /**
+ * Retrieve annotations for an entry.
+ *
+ * @ApiDoc(
+ * requirements={
+ * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
+ * }
+ * )
+ *
+ * @return Response
+ */
+ 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);
+ }
+
+ /**
+ * Creates a new annotation.
+ *
+ * @param Entry $entry
+ *
+ * @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"=""},
+ * }
+ * )
+ *
+ * @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');
+