From 351eb8d97ea1520f87ae762faf297083a716c945 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 18 Mar 2016 16:41:23 +0100 Subject: bring annotations to API --- .../Controller/WallabagRestController.php | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 3437bb9b..6275afa0 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -6,12 +6,14 @@ 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 Wallabag\AnnotationBundle\Entity\Annotation; class WallabagRestController extends FOSRestController { @@ -517,6 +519,136 @@ 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"} + * } + * ) + * + * @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'); + + return $this->renderJsonResponse($json); + } + + /** + * Updates an annotation. + * + * @ApiDoc( + * requirements={ + * {"name"="annotation", "dataType"="string", "requirement"="\w+", "description"="The annotation ID"} + * } + * ) + * + * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") + * + * @return Response + */ + 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); + } + + /** + * Removes an annotation. + * + * @ApiDoc( + * requirements={ + * {"name"="annotation", "dataType"="string", "requirement"="\w+", "description"="The annotation ID"} + * } + * ) + * + * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") + * + * @return Response + */ + 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); + } + /** * Retrieve version number. * -- cgit v1.2.3 From c7935f32d2cd7fd29dbc7b07c8f206f6e8b64fb4 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 18 Mar 2016 22:23:49 +0100 Subject: cs --- src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 6275afa0..07d0e1e9 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -532,7 +532,6 @@ class WallabagRestController extends FOSRestController */ public function getAnnotationsAction(Entry $entry) { - $this->validateAuthentication(); $annotationRows = $this @@ -605,7 +604,6 @@ class WallabagRestController extends FOSRestController */ public function putAnnotationAction(Annotation $annotation, Request $request) { - $this->validateAuthentication(); $data = json_decode($request->getContent(), true); @@ -637,7 +635,6 @@ class WallabagRestController extends FOSRestController */ public function deleteAnnotationAction(Annotation $annotation) { - $this->validateAuthentication(); $em = $this->getDoctrine()->getManager(); -- cgit v1.2.3 From 1eea248bb0ebf49772878557211817905a4d6952 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 5 Oct 2016 19:16:57 +0200 Subject: move code --- .../Controller/WallabagRestController.php | 87 ++++++++-------------- 1 file changed, 31 insertions(+), 56 deletions(-) (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 07d0e1e9..e2e4924b 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -528,29 +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); + $response = $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', + [ + 'entry' => $entry + ]); + return $response; } /** * 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"}, @@ -559,34 +556,17 @@ class WallabagRestController extends FOSRestController * } * ) * - * @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); + $response = $this->forward('WallabagApiBundle:WallabagRest:postAnnotation', + [ + 'request' => $request, + 'entry' => $entry + ]); + return $response; } /** @@ -600,24 +580,20 @@ 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); + $response = $this->forward('WallabagApiBundle:WallabagRest:putAnnotation', + [ + 'annotation' => $annotation, + 'request' => $request + ]); + return $response; } /** @@ -631,19 +607,18 @@ 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); + $response = $this->forward('WallabagApiBundle:WallabagRest:deleteAnnotation', + [ + 'annotation' => $annotation, + ]); + return $response; } /** -- cgit v1.2.3 From b1e92f8c14d3d506f2bfab628ba8ed95de0e8b51 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 6 Oct 2016 11:40:14 +0200 Subject: cs --- .../ApiBundle/Controller/WallabagRestController.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index e2e4924b..b30ab267 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -529,6 +529,7 @@ class WallabagRestController extends FOSRestController * ) * * @param Entry $entry + * * @return JsonResponse */ public function getAnnotationsAction(Entry $entry) @@ -537,8 +538,9 @@ class WallabagRestController extends FOSRestController $response = $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', [ - 'entry' => $entry + 'entry' => $entry, ]); + return $response; } @@ -546,7 +548,8 @@ class WallabagRestController extends FOSRestController * Creates a new annotation. * * @param Request $request - * @param Entry $entry + * @param Entry $entry + * * @return JsonResponse * @ApiDoc( * requirements={ @@ -555,7 +558,6 @@ class WallabagRestController extends FOSRestController * {"name"="text", "dataType"="string", "required"=true, "description"=""}, * } * ) - * */ public function postAnnotationAction(Request $request, Entry $entry) { @@ -564,8 +566,9 @@ class WallabagRestController extends FOSRestController $response = $this->forward('WallabagApiBundle:WallabagRest:postAnnotation', [ 'request' => $request, - 'entry' => $entry + 'entry' => $entry, ]); + return $response; } @@ -581,7 +584,8 @@ class WallabagRestController extends FOSRestController * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") * * @param Annotation $annotation - * @param Request $request + * @param Request $request + * * @return JsonResponse */ public function putAnnotationAction(Annotation $annotation, Request $request) @@ -591,8 +595,9 @@ class WallabagRestController extends FOSRestController $response = $this->forward('WallabagApiBundle:WallabagRest:putAnnotation', [ 'annotation' => $annotation, - 'request' => $request + 'request' => $request, ]); + return $response; } @@ -608,6 +613,7 @@ class WallabagRestController extends FOSRestController * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") * * @param Annotation $annotation + * * @return JsonResponse */ public function deleteAnnotationAction(Annotation $annotation) @@ -618,6 +624,7 @@ class WallabagRestController extends FOSRestController [ 'annotation' => $annotation, ]); + return $response; } -- cgit v1.2.3 From 0c271b9eb0813162b82c6b3bc38604716398ddd1 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 9 Oct 2016 14:01:28 +0200 Subject: fix cs and phpdoc --- .../Controller/WallabagRestController.php | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index b30ab267..0c709ca0 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -536,12 +536,9 @@ class WallabagRestController extends FOSRestController { $this->validateAuthentication(); - $response = $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', - [ - 'entry' => $entry, - ]); - - return $response; + return $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', [ + 'entry' => $entry, + ]); } /** @@ -563,13 +560,10 @@ class WallabagRestController extends FOSRestController { $this->validateAuthentication(); - $response = $this->forward('WallabagApiBundle:WallabagRest:postAnnotation', - [ + return $this->forward('WallabagApiBundle:WallabagRest:postAnnotation', [ 'request' => $request, 'entry' => $entry, ]); - - return $response; } /** @@ -592,13 +586,10 @@ class WallabagRestController extends FOSRestController { $this->validateAuthentication(); - $response = $this->forward('WallabagApiBundle:WallabagRest:putAnnotation', - [ + return $this->forward('WallabagApiBundle:WallabagRest:putAnnotation', [ 'annotation' => $annotation, 'request' => $request, ]); - - return $response; } /** @@ -620,12 +611,9 @@ class WallabagRestController extends FOSRestController { $this->validateAuthentication(); - $response = $this->forward('WallabagApiBundle:WallabagRest:deleteAnnotation', - [ + return $this->forward('WallabagApiBundle:WallabagRest:deleteAnnotation', [ 'annotation' => $annotation, ]); - - return $response; } /** -- cgit v1.2.3 From d9b7768dca0049e76fc7b5cf6cc6cba0e2b40f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 14 Oct 2016 15:00:42 +0200 Subject: Added a missing namespace --- src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 0c709ca0..b6b6c9bf 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -14,6 +14,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\AnnotationBundle\Entity\Annotation; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; class WallabagRestController extends FOSRestController { -- cgit v1.2.3 From 3199ec4702cec9c10ad0c663bcf6ce799068c9aa Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 22 Oct 2016 09:17:01 +0200 Subject: CS --- src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 1 - 1 file changed, 1 deletion(-) (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index b6b6c9bf..0c709ca0 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -14,7 +14,6 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\AnnotationBundle\Entity\Annotation; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; class WallabagRestController extends FOSRestController { -- cgit v1.2.3 From aa4741091f3f2cc7e4a7ef061a04678597ddeca8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 22 Oct 2016 12:09:20 +0200 Subject: Add test on /api/annotations Fix controller forward in WallabagRestController. Update PHPDoc so it is sorted the same way as others one Duplicate all annotations test to use both api & normal way Also, make annotation tests independent to each other --- .../Controller/WallabagRestController.php | 33 +++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 0c709ca0..a73d44ca 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -536,7 +536,7 @@ class WallabagRestController extends FOSRestController { $this->validateAuthentication(); - return $this->forward('WallabagApiBundle:WallabagRest:getAnnotations', [ + return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:getAnnotations', [ 'entry' => $entry, ]); } @@ -544,10 +544,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 +551,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 +587,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 +612,9 @@ class WallabagRestController extends FOSRestController { $this->validateAuthentication(); - return $this->forward('WallabagApiBundle:WallabagRest:deleteAnnotation', [ - 'annotation' => $annotation, - ]); + return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:deleteAnnotation', [ + 'annotation' => $annotation, + ]); } /** -- cgit v1.2.3