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/WallabagAnnotationController.php | 28 +---- .../Controller/WallabagRestController.php | 132 +++++++++++++++++++++ 2 files changed, 138 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php index ad083e31..80ac0035 100644 --- a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php +++ b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php @@ -15,11 +15,9 @@ class WallabagAnnotationController extends FOSRestController /** * Retrieve annotations for an entry. * - * @ApiDoc( - * requirements={ - * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} - * } - * ) + * @param Entry $entry + * + * @see Wallabag\ApiBundle\Controller\WallabagRestController * * @return Response */ @@ -42,13 +40,7 @@ class WallabagAnnotationController extends FOSRestController * * @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"=""}, - * } - * ) + * @see Wallabag\ApiBundle\Controller\WallabagRestController * * @return Response */ @@ -81,11 +73,7 @@ class WallabagAnnotationController extends FOSRestController /** * Updates an annotation. * - * @ApiDoc( - * requirements={ - * {"name"="annotation", "dataType"="string", "requirement"="\w+", "description"="The annotation ID"} - * } - * ) + * @see Wallabag\ApiBundle\Controller\WallabagRestController * * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") * @@ -110,11 +98,7 @@ class WallabagAnnotationController extends FOSRestController /** * Removes an annotation. * - * @ApiDoc( - * requirements={ - * {"name"="annotation", "dataType"="string", "requirement"="\w+", "description"="The annotation ID"} - * } - * ) + * @see Wallabag\ApiBundle\Controller\WallabagRestController * * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") * 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 --- .../AnnotationBundle/Controller/WallabagAnnotationController.php | 1 - src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 3 --- 2 files changed, 4 deletions(-) (limited to 'src') diff --git a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php index 80ac0035..4143c1b6 100644 --- a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php +++ b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php @@ -3,7 +3,6 @@ namespace Wallabag\AnnotationBundle\Controller; use FOS\RestBundle\Controller\FOSRestController; -use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; 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/WallabagAnnotationController.php | 43 +++++------ .../Controller/WallabagRestController.php | 87 ++++++++-------------- 2 files changed, 48 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php index 4143c1b6..b04c0bc2 100644 --- a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php +++ b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php @@ -3,6 +3,7 @@ namespace Wallabag\AnnotationBundle\Controller; use FOS\RestBundle\Controller\FOSRestController; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; @@ -18,30 +19,30 @@ class WallabagAnnotationController extends FOSRestController * * @see Wallabag\ApiBundle\Controller\WallabagRestController * - * @return Response + * @return JsonResponse */ public function getAnnotationsAction(Entry $entry) { $annotationRows = $this - ->getDoctrine() - ->getRepository('WallabagAnnotationBundle:Annotation') - ->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId()); + ->getDoctrine() + ->getRepository('WallabagAnnotationBundle:Annotation') + ->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId()); $total = count($annotationRows); - $annotations = ['total' => $total, 'rows' => $annotationRows]; + $annotations = array('total' => $total, 'rows' => $annotationRows); $json = $this->get('serializer')->serialize($annotations, 'json'); - return $this->renderJsonResponse($json); + return (new JsonResponse())->setJson($json); } /** * Creates a new annotation. * + * @param Request $request * @param Entry $entry - * + * @return JsonResponse * @see Wallabag\ApiBundle\Controller\WallabagRestController * - * @return Response */ public function postAnnotationAction(Request $request, Entry $entry) { @@ -66,7 +67,7 @@ class WallabagAnnotationController extends FOSRestController $json = $this->get('serializer')->serialize($annotation, 'json'); - return $this->renderJsonResponse($json); + return (new JsonResponse())->setJson($json); } /** @@ -76,7 +77,9 @@ class WallabagAnnotationController extends FOSRestController * * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") * - * @return Response + * @param Annotation $annotation + * @param Request $request + * @return JsonResponse */ public function putAnnotationAction(Annotation $annotation, Request $request) { @@ -91,7 +94,7 @@ class WallabagAnnotationController extends FOSRestController $json = $this->get('serializer')->serialize($annotation, 'json'); - return $this->renderJsonResponse($json); + return (new JsonResponse())->setJson($json); } /** @@ -101,7 +104,8 @@ class WallabagAnnotationController extends FOSRestController * * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") * - * @return Response + * @param Annotation $annotation + * @return JsonResponse */ public function deleteAnnotationAction(Annotation $annotation) { @@ -111,19 +115,6 @@ class WallabagAnnotationController extends FOSRestController $json = $this->get('serializer')->serialize($annotation, 'json'); - return $this->renderJsonResponse($json); - } - - /** - * Send a JSON Response. - * We don't use the Symfony JsonRespone, because it takes an array as parameter instead of a JSON string. - * - * @param string $json - * - * @return Response - */ - private function renderJsonResponse($json, $code = 200) - { - return new Response($json, $code, ['application/json']); + return (new JsonResponse())->setJson($json); } } 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 --- .../Controller/WallabagAnnotationController.php | 10 ++++++---- .../ApiBundle/Controller/WallabagRestController.php | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php index b04c0bc2..519fd2f5 100644 --- a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php +++ b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php @@ -5,7 +5,6 @@ namespace Wallabag\AnnotationBundle\Controller; use FOS\RestBundle\Controller\FOSRestController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Wallabag\AnnotationBundle\Entity\Annotation; use Wallabag\CoreBundle\Entity\Entry; @@ -39,10 +38,11 @@ class WallabagAnnotationController extends FOSRestController * Creates a new annotation. * * @param Request $request - * @param Entry $entry + * @param Entry $entry + * * @return JsonResponse - * @see Wallabag\ApiBundle\Controller\WallabagRestController * + * @see Wallabag\ApiBundle\Controller\WallabagRestController */ public function postAnnotationAction(Request $request, Entry $entry) { @@ -78,7 +78,8 @@ class WallabagAnnotationController 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) @@ -105,6 +106,7 @@ class WallabagAnnotationController extends FOSRestController * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") * * @param Annotation $annotation + * * @return JsonResponse */ public function deleteAnnotationAction(Annotation $annotation) 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/WallabagAnnotationController.php | 2 +- .../Controller/WallabagRestController.php | 24 ++++++---------------- 2 files changed, 7 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php index 519fd2f5..c13a034f 100644 --- a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php +++ b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php @@ -27,7 +27,7 @@ class WallabagAnnotationController extends FOSRestController ->getRepository('WallabagAnnotationBundle:Annotation') ->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId()); $total = count($annotationRows); - $annotations = array('total' => $total, 'rows' => $annotationRows); + $annotations = ['total' => $total, 'rows' => $annotationRows]; $json = $this->get('serializer')->serialize($annotations, 'json'); 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') 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') 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 --- .../Repository/AnnotationRepository.php | 6 ++-- .../Controller/WallabagRestController.php | 33 +++++++++++----------- 2 files changed, 21 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php index 5f7da70e..8cccffba 100644 --- a/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php +++ b/src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php @@ -50,7 +50,8 @@ class AnnotationRepository extends EntityRepository { return $this->createQueryBuilder('a') ->andWhere('a.id = :annotationId')->setParameter('annotationId', $annotationId) - ->getQuery()->getSingleResult() + ->getQuery() + ->getSingleResult() ; } @@ -67,7 +68,8 @@ class AnnotationRepository extends EntityRepository return $this->createQueryBuilder('a') ->where('a.entry = :entryId')->setParameter('entryId', $entryId) ->andwhere('a.user = :userId')->setParameter('userId', $userId) - ->getQuery()->getResult() + ->getQuery() + ->getResult() ; } 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