diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-09-08 12:28:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-08 12:28:46 +0200 |
commit | 5fc79381bb51220836d1c1db4cb5e9c7dec076b9 (patch) | |
tree | ef202ed124d6825138fc8570829909cc7c3db33f /src/Wallabag/ApiBundle | |
parent | 6f23289e721bd14710af1acc23466432c1312850 (diff) | |
parent | 60faee002ceff1d6f77996fc32a0023a140a2fe9 (diff) | |
download | wallabag-5fc79381bb51220836d1c1db4cb5e9c7dec076b9.tar.gz wallabag-5fc79381bb51220836d1c1db4cb5e9c7dec076b9.tar.zst wallabag-5fc79381bb51220836d1c1db4cb5e9c7dec076b9.zip |
Merge pull request #2274 from wallabag/json-response-created-at
Re-use JsonResponse
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 67 |
1 files changed, 27 insertions, 40 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 07fedeb0..fb7c6c1f 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -7,7 +7,7 @@ use Hateoas\Configuration\Route; | |||
7 | use Hateoas\Representation\Factory\PagerfantaFactory; | 7 | use Hateoas\Representation\Factory\PagerfantaFactory; |
8 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | 8 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
9 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Symfony\Component\HttpFoundation\Response; | 10 | use Symfony\Component\HttpFoundation\JsonResponse; |
11 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 11 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
12 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; | 12 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
13 | use Wallabag\CoreBundle\Entity\Entry; | 13 | use Wallabag\CoreBundle\Entity\Entry; |
@@ -38,7 +38,7 @@ class WallabagRestController extends FOSRestController | |||
38 | * } | 38 | * } |
39 | * ) | 39 | * ) |
40 | * | 40 | * |
41 | * @return Response | 41 | * @return JsonResponse |
42 | */ | 42 | */ |
43 | public function getEntriesAction(Request $request) | 43 | public function getEntriesAction(Request $request) |
44 | { | 44 | { |
@@ -68,7 +68,7 @@ class WallabagRestController extends FOSRestController | |||
68 | 68 | ||
69 | $json = $this->get('serializer')->serialize($paginatedCollection, 'json'); | 69 | $json = $this->get('serializer')->serialize($paginatedCollection, 'json'); |
70 | 70 | ||
71 | return $this->renderJsonResponse($json); | 71 | return (new JsonResponse())->setJson($json); |
72 | } | 72 | } |
73 | 73 | ||
74 | /** | 74 | /** |
@@ -80,7 +80,7 @@ class WallabagRestController extends FOSRestController | |||
80 | * } | 80 | * } |
81 | * ) | 81 | * ) |
82 | * | 82 | * |
83 | * @return Response | 83 | * @return JsonResponse |
84 | */ | 84 | */ |
85 | public function getEntryAction(Entry $entry) | 85 | public function getEntryAction(Entry $entry) |
86 | { | 86 | { |
@@ -89,7 +89,7 @@ class WallabagRestController extends FOSRestController | |||
89 | 89 | ||
90 | $json = $this->get('serializer')->serialize($entry, 'json'); | 90 | $json = $this->get('serializer')->serialize($entry, 'json'); |
91 | 91 | ||
92 | return $this->renderJsonResponse($json); | 92 | return (new JsonResponse())->setJson($json); |
93 | } | 93 | } |
94 | 94 | ||
95 | /** | 95 | /** |
@@ -105,7 +105,7 @@ class WallabagRestController extends FOSRestController | |||
105 | * } | 105 | * } |
106 | * ) | 106 | * ) |
107 | * | 107 | * |
108 | * @return Response | 108 | * @return JsonResponse |
109 | */ | 109 | */ |
110 | public function postEntriesAction(Request $request) | 110 | public function postEntriesAction(Request $request) |
111 | { | 111 | { |
@@ -149,7 +149,7 @@ class WallabagRestController extends FOSRestController | |||
149 | 149 | ||
150 | $json = $this->get('serializer')->serialize($entry, 'json'); | 150 | $json = $this->get('serializer')->serialize($entry, 'json'); |
151 | 151 | ||
152 | return $this->renderJsonResponse($json); | 152 | return (new JsonResponse())->setJson($json); |
153 | } | 153 | } |
154 | 154 | ||
155 | /** | 155 | /** |
@@ -167,7 +167,7 @@ class WallabagRestController extends FOSRestController | |||
167 | * } | 167 | * } |
168 | * ) | 168 | * ) |
169 | * | 169 | * |
170 | * @return Response | 170 | * @return JsonResponse |
171 | */ | 171 | */ |
172 | public function patchEntriesAction(Entry $entry, Request $request) | 172 | public function patchEntriesAction(Entry $entry, Request $request) |
173 | { | 173 | { |
@@ -200,7 +200,7 @@ class WallabagRestController extends FOSRestController | |||
200 | 200 | ||
201 | $json = $this->get('serializer')->serialize($entry, 'json'); | 201 | $json = $this->get('serializer')->serialize($entry, 'json'); |
202 | 202 | ||
203 | return $this->renderJsonResponse($json); | 203 | return (new JsonResponse())->setJson($json); |
204 | } | 204 | } |
205 | 205 | ||
206 | /** | 206 | /** |
@@ -212,7 +212,7 @@ class WallabagRestController extends FOSRestController | |||
212 | * } | 212 | * } |
213 | * ) | 213 | * ) |
214 | * | 214 | * |
215 | * @return Response | 215 | * @return JsonResponse |
216 | */ | 216 | */ |
217 | public function deleteEntriesAction(Entry $entry) | 217 | public function deleteEntriesAction(Entry $entry) |
218 | { | 218 | { |
@@ -225,7 +225,7 @@ class WallabagRestController extends FOSRestController | |||
225 | 225 | ||
226 | $json = $this->get('serializer')->serialize($entry, 'json'); | 226 | $json = $this->get('serializer')->serialize($entry, 'json'); |
227 | 227 | ||
228 | return $this->renderJsonResponse($json); | 228 | return (new JsonResponse())->setJson($json); |
229 | } | 229 | } |
230 | 230 | ||
231 | /** | 231 | /** |
@@ -237,7 +237,7 @@ class WallabagRestController extends FOSRestController | |||
237 | * } | 237 | * } |
238 | * ) | 238 | * ) |
239 | * | 239 | * |
240 | * @return Response | 240 | * @return JsonResponse |
241 | */ | 241 | */ |
242 | public function getEntriesTagsAction(Entry $entry) | 242 | public function getEntriesTagsAction(Entry $entry) |
243 | { | 243 | { |
@@ -246,7 +246,7 @@ class WallabagRestController extends FOSRestController | |||
246 | 246 | ||
247 | $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); | 247 | $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); |
248 | 248 | ||
249 | return $this->renderJsonResponse($json); | 249 | return (new JsonResponse())->setJson($json); |
250 | } | 250 | } |
251 | 251 | ||
252 | /** | 252 | /** |
@@ -261,7 +261,7 @@ class WallabagRestController extends FOSRestController | |||
261 | * } | 261 | * } |
262 | * ) | 262 | * ) |
263 | * | 263 | * |
264 | * @return Response | 264 | * @return JsonResponse |
265 | */ | 265 | */ |
266 | public function postEntriesTagsAction(Request $request, Entry $entry) | 266 | public function postEntriesTagsAction(Request $request, Entry $entry) |
267 | { | 267 | { |
@@ -279,7 +279,7 @@ class WallabagRestController extends FOSRestController | |||
279 | 279 | ||
280 | $json = $this->get('serializer')->serialize($entry, 'json'); | 280 | $json = $this->get('serializer')->serialize($entry, 'json'); |
281 | 281 | ||
282 | return $this->renderJsonResponse($json); | 282 | return (new JsonResponse())->setJson($json); |
283 | } | 283 | } |
284 | 284 | ||
285 | /** | 285 | /** |
@@ -292,7 +292,7 @@ class WallabagRestController extends FOSRestController | |||
292 | * } | 292 | * } |
293 | * ) | 293 | * ) |
294 | * | 294 | * |
295 | * @return Response | 295 | * @return JsonResponse |
296 | */ | 296 | */ |
297 | public function deleteEntriesTagsAction(Entry $entry, Tag $tag) | 297 | public function deleteEntriesTagsAction(Entry $entry, Tag $tag) |
298 | { | 298 | { |
@@ -306,7 +306,7 @@ class WallabagRestController extends FOSRestController | |||
306 | 306 | ||
307 | $json = $this->get('serializer')->serialize($entry, 'json'); | 307 | $json = $this->get('serializer')->serialize($entry, 'json'); |
308 | 308 | ||
309 | return $this->renderJsonResponse($json); | 309 | return (new JsonResponse())->setJson($json); |
310 | } | 310 | } |
311 | 311 | ||
312 | /** | 312 | /** |
@@ -314,7 +314,7 @@ class WallabagRestController extends FOSRestController | |||
314 | * | 314 | * |
315 | * @ApiDoc() | 315 | * @ApiDoc() |
316 | * | 316 | * |
317 | * @return Response | 317 | * @return JsonResponse |
318 | */ | 318 | */ |
319 | public function getTagsAction() | 319 | public function getTagsAction() |
320 | { | 320 | { |
@@ -328,7 +328,7 @@ class WallabagRestController extends FOSRestController | |||
328 | 328 | ||
329 | $json = $this->get('serializer')->serialize($tags, 'json'); | 329 | $json = $this->get('serializer')->serialize($tags, 'json'); |
330 | 330 | ||
331 | return $this->renderJsonResponse($json); | 331 | return (new JsonResponse())->setJson($json); |
332 | } | 332 | } |
333 | 333 | ||
334 | /** | 334 | /** |
@@ -340,7 +340,7 @@ class WallabagRestController extends FOSRestController | |||
340 | * } | 340 | * } |
341 | * ) | 341 | * ) |
342 | * | 342 | * |
343 | * @return Response | 343 | * @return JsonResponse |
344 | */ | 344 | */ |
345 | public function deleteTagLabelAction(Request $request) | 345 | public function deleteTagLabelAction(Request $request) |
346 | { | 346 | { |
@@ -359,7 +359,7 @@ class WallabagRestController extends FOSRestController | |||
359 | 359 | ||
360 | $json = $this->get('serializer')->serialize($tag, 'json'); | 360 | $json = $this->get('serializer')->serialize($tag, 'json'); |
361 | 361 | ||
362 | return $this->renderJsonResponse($json); | 362 | return (new JsonResponse())->setJson($json); |
363 | } | 363 | } |
364 | 364 | ||
365 | /** | 365 | /** |
@@ -371,7 +371,7 @@ class WallabagRestController extends FOSRestController | |||
371 | * } | 371 | * } |
372 | * ) | 372 | * ) |
373 | * | 373 | * |
374 | * @return Response | 374 | * @return JsonResponse |
375 | */ | 375 | */ |
376 | public function deleteTagsLabelAction(Request $request) | 376 | public function deleteTagsLabelAction(Request $request) |
377 | { | 377 | { |
@@ -399,7 +399,7 @@ class WallabagRestController extends FOSRestController | |||
399 | 399 | ||
400 | $json = $this->get('serializer')->serialize($tags, 'json'); | 400 | $json = $this->get('serializer')->serialize($tags, 'json'); |
401 | 401 | ||
402 | return $this->renderJsonResponse($json); | 402 | return (new JsonResponse())->setJson($json); |
403 | } | 403 | } |
404 | 404 | ||
405 | /** | 405 | /** |
@@ -411,7 +411,7 @@ class WallabagRestController extends FOSRestController | |||
411 | * } | 411 | * } |
412 | * ) | 412 | * ) |
413 | * | 413 | * |
414 | * @return Response | 414 | * @return JsonResponse |
415 | */ | 415 | */ |
416 | public function deleteTagAction(Tag $tag) | 416 | public function deleteTagAction(Tag $tag) |
417 | { | 417 | { |
@@ -423,7 +423,7 @@ class WallabagRestController extends FOSRestController | |||
423 | 423 | ||
424 | $json = $this->get('serializer')->serialize($tag, 'json'); | 424 | $json = $this->get('serializer')->serialize($tag, 'json'); |
425 | 425 | ||
426 | return $this->renderJsonResponse($json); | 426 | return (new JsonResponse())->setJson($json); |
427 | } | 427 | } |
428 | 428 | ||
429 | /** | 429 | /** |
@@ -431,7 +431,7 @@ class WallabagRestController extends FOSRestController | |||
431 | * | 431 | * |
432 | * @ApiDoc() | 432 | * @ApiDoc() |
433 | * | 433 | * |
434 | * @return Response | 434 | * @return JsonResponse |
435 | */ | 435 | */ |
436 | public function getVersionAction() | 436 | public function getVersionAction() |
437 | { | 437 | { |
@@ -439,7 +439,7 @@ class WallabagRestController extends FOSRestController | |||
439 | 439 | ||
440 | $json = $this->get('serializer')->serialize($version, 'json'); | 440 | $json = $this->get('serializer')->serialize($version, 'json'); |
441 | 441 | ||
442 | return $this->renderJsonResponse($json); | 442 | return (new JsonResponse())->setJson($json); |
443 | } | 443 | } |
444 | 444 | ||
445 | /** | 445 | /** |
@@ -455,17 +455,4 @@ class WallabagRestController extends FOSRestController | |||
455 | throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$requestUserId.', logged user id: '.$user->getId()); | 455 | throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$requestUserId.', logged user id: '.$user->getId()); |
456 | } | 456 | } |
457 | } | 457 | } |
458 | |||
459 | /** | ||
460 | * Send a JSON Response. | ||
461 | * We don't use the Symfony JsonRespone, because it takes an array as parameter instead of a JSON string. | ||
462 | * | ||
463 | * @param string $json | ||
464 | * | ||
465 | * @return Response | ||
466 | */ | ||
467 | private function renderJsonResponse($json) | ||
468 | { | ||
469 | return new Response($json, 200, ['application/json']); | ||
470 | } | ||
471 | } | 458 | } |