aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/AnnotationBundle/Controller
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2016-10-05 19:16:57 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-22 09:06:07 +0200
commit1eea248bb0ebf49772878557211817905a4d6952 (patch)
tree987bf28959b70a469f6df95303dc462da14bd372 /src/Wallabag/AnnotationBundle/Controller
parentc7935f32d2cd7fd29dbc7b07c8f206f6e8b64fb4 (diff)
downloadwallabag-1eea248bb0ebf49772878557211817905a4d6952.tar.gz
wallabag-1eea248bb0ebf49772878557211817905a4d6952.tar.zst
wallabag-1eea248bb0ebf49772878557211817905a4d6952.zip
move code
Diffstat (limited to 'src/Wallabag/AnnotationBundle/Controller')
-rw-r--r--src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php43
1 files changed, 17 insertions, 26 deletions
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 @@
3namespace Wallabag\AnnotationBundle\Controller; 3namespace Wallabag\AnnotationBundle\Controller;
4 4
5use FOS\RestBundle\Controller\FOSRestController; 5use FOS\RestBundle\Controller\FOSRestController;
6use Symfony\Component\HttpFoundation\JsonResponse;
6use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
7use Symfony\Component\HttpFoundation\Response; 8use Symfony\Component\HttpFoundation\Response;
8use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; 9use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
@@ -18,30 +19,30 @@ class WallabagAnnotationController extends FOSRestController
18 * 19 *
19 * @see Wallabag\ApiBundle\Controller\WallabagRestController 20 * @see Wallabag\ApiBundle\Controller\WallabagRestController
20 * 21 *
21 * @return Response 22 * @return JsonResponse
22 */ 23 */
23 public function getAnnotationsAction(Entry $entry) 24 public function getAnnotationsAction(Entry $entry)
24 { 25 {
25 $annotationRows = $this 26 $annotationRows = $this
26 ->getDoctrine() 27 ->getDoctrine()
27 ->getRepository('WallabagAnnotationBundle:Annotation') 28 ->getRepository('WallabagAnnotationBundle:Annotation')
28 ->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId()); 29 ->findAnnotationsByPageId($entry->getId(), $this->getUser()->getId());
29 $total = count($annotationRows); 30 $total = count($annotationRows);
30 $annotations = ['total' => $total, 'rows' => $annotationRows]; 31 $annotations = array('total' => $total, 'rows' => $annotationRows);
31 32
32 $json = $this->get('serializer')->serialize($annotations, 'json'); 33 $json = $this->get('serializer')->serialize($annotations, 'json');
33 34
34 return $this->renderJsonResponse($json); 35 return (new JsonResponse())->setJson($json);
35 } 36 }
36 37
37 /** 38 /**
38 * Creates a new annotation. 39 * Creates a new annotation.
39 * 40 *
41 * @param Request $request
40 * @param Entry $entry 42 * @param Entry $entry
41 * 43 * @return JsonResponse
42 * @see Wallabag\ApiBundle\Controller\WallabagRestController 44 * @see Wallabag\ApiBundle\Controller\WallabagRestController
43 * 45 *
44 * @return Response
45 */ 46 */
46 public function postAnnotationAction(Request $request, Entry $entry) 47 public function postAnnotationAction(Request $request, Entry $entry)
47 { 48 {
@@ -66,7 +67,7 @@ class WallabagAnnotationController extends FOSRestController
66 67
67 $json = $this->get('serializer')->serialize($annotation, 'json'); 68 $json = $this->get('serializer')->serialize($annotation, 'json');
68 69
69 return $this->renderJsonResponse($json); 70 return (new JsonResponse())->setJson($json);
70 } 71 }
71 72
72 /** 73 /**
@@ -76,7 +77,9 @@ class WallabagAnnotationController extends FOSRestController
76 * 77 *
77 * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") 78 * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation")
78 * 79 *
79 * @return Response 80 * @param Annotation $annotation
81 * @param Request $request
82 * @return JsonResponse
80 */ 83 */
81 public function putAnnotationAction(Annotation $annotation, Request $request) 84 public function putAnnotationAction(Annotation $annotation, Request $request)
82 { 85 {
@@ -91,7 +94,7 @@ class WallabagAnnotationController extends FOSRestController
91 94
92 $json = $this->get('serializer')->serialize($annotation, 'json'); 95 $json = $this->get('serializer')->serialize($annotation, 'json');
93 96
94 return $this->renderJsonResponse($json); 97 return (new JsonResponse())->setJson($json);
95 } 98 }
96 99
97 /** 100 /**
@@ -101,7 +104,8 @@ class WallabagAnnotationController extends FOSRestController
101 * 104 *
102 * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") 105 * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation")
103 * 106 *
104 * @return Response 107 * @param Annotation $annotation
108 * @return JsonResponse
105 */ 109 */
106 public function deleteAnnotationAction(Annotation $annotation) 110 public function deleteAnnotationAction(Annotation $annotation)
107 { 111 {
@@ -111,19 +115,6 @@ class WallabagAnnotationController extends FOSRestController
111 115
112 $json = $this->get('serializer')->serialize($annotation, 'json'); 116 $json = $this->get('serializer')->serialize($annotation, 'json');
113 117
114 return $this->renderJsonResponse($json); 118 return (new JsonResponse())->setJson($json);
115 }
116
117 /**
118 * Send a JSON Response.
119 * We don't use the Symfony JsonRespone, because it takes an array as parameter instead of a JSON string.
120 *
121 * @param string $json
122 *
123 * @return Response
124 */
125 private function renderJsonResponse($json, $code = 200)
126 {
127 return new Response($json, $code, ['application/json']);
128 } 119 }
129} 120}