]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/WallabagRestController.php
fix tests for GET /entries/tags
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / WallabagRestController.php
index 81bfbe12a58bf40a0facf908f6f711a36a6b834a..e25ac6db8a545fd69bd96b7a0c46dc6e9319378c 100644 (file)
@@ -5,11 +5,11 @@ namespace Wallabag\CoreBundle\Controller;
 use Nelmio\ApiDocBundle\Annotation\ApiDoc;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\Response;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\Tag;
 use Wallabag\CoreBundle\Service\Extractor;
-use Symfony\Component\Security\Core\Exception\AccessDeniedException;
 
 class WallabagRestController extends Controller
 {
@@ -41,11 +41,7 @@ class WallabagRestController extends Controller
     /**
      * Retrieve salt for a giver user.
      *
-     * @ApiDoc(
-     *       parameters={
-     *          {"name"="username", "dataType"="string", "required"=true, "description"="username"}
-     *       }
-     * )
+     * @ApiDoc()
      * @return array
      */
     public function getSaltAction($username)
@@ -98,7 +94,7 @@ class WallabagRestController extends Controller
 
         $json = $this->get('serializer')->serialize($entries, 'json');
 
-        return new Response($json, 200, array('application/json'));
+        return new JsonResponse($json, 200);
     }
 
     /**
@@ -119,7 +115,7 @@ class WallabagRestController extends Controller
 
         $json = $this->get('serializer')->serialize($entry, 'json');
 
-        return new Response($json, 200, array('application/json'));
+        return new JsonResponse($json, 200);
     }
 
     /**
@@ -144,7 +140,10 @@ class WallabagRestController extends Controller
         $entry->setTitle($request->request->get('title') ?: $content->getTitle());
         $entry->setContent($content->getBody());
 
-        $this->assignTagsToEntry($entry, $request->request->get('tags', array()));
+        $tags = $request->request->get('tags', '');
+        if (!empty($tags)) {
+            $this->assignTagsToEntry($entry, $tags);
+        }
 
         $em = $this->getDoctrine()->getManager();
         $em->persist($entry);
@@ -152,7 +151,7 @@ class WallabagRestController extends Controller
 
         $json = $this->get('serializer')->serialize($entry, 'json');
 
-        return new Response($json, 200, array('application/json'));
+        return new JsonResponse($json, 200);
     }
 
     /**
@@ -193,12 +192,17 @@ class WallabagRestController extends Controller
             $entry->setStarred($isStarred);
         }
 
-        $this->assignTagsToEntry($entry, $request->request->get('tags', array()));
+        $tags = $request->request->get('tags', '');
+        if (!empty($tags)) {
+            $this->assignTagsToEntry($entry, $tags);
+        }
 
         $em = $this->getDoctrine()->getManager();
         $em->flush();
 
-        return $entry;
+        $json = $this->get('serializer')->serialize($entry, 'json');
+
+        return new JsonResponse($json, 200);
     }
 
     /**
@@ -223,7 +227,7 @@ class WallabagRestController extends Controller
 
         $json = $this->get('serializer')->serialize($entry, 'json');
 
-        return new Response($json, 200, array('application/json'));
+        return new JsonResponse($json, 200);
     }
 
     /**
@@ -237,8 +241,6 @@ class WallabagRestController extends Controller
      */
     public function getEntriesTagsAction(Entry $entry)
     {
-        var_dump($entry->getUser()->getId());
-        var_dump($this->getUser()->getId());
         if ($entry->getUser()->getId() != $this->getUser()->getId()) {
             throw $this->createAccessDeniedException();
         }
@@ -266,7 +268,10 @@ class WallabagRestController extends Controller
             throw $this->createAccessDeniedException();
         }
 
-        $this->assignTagsToEntry($entry, $request->request->get('tags', array()));
+        $tags = $request->request->get('tags', '');
+        if (!empty($tags)) {
+            $this->assignTagsToEntry($entry, $tags);
+        }
 
         $em = $this->getDoctrine()->getManager();
         $em->persist($entry);
@@ -274,7 +279,7 @@ class WallabagRestController extends Controller
 
         $json = $this->get('serializer')->serialize($entry, 'json');
 
-        return new Response($json, 200, array('application/json'));
+        return new JsonResponse($json, 200);
     }
 
     /**
@@ -300,7 +305,7 @@ class WallabagRestController extends Controller
 
         $json = $this->get('serializer')->serialize($entry, 'json');
 
-        return new Response($json, 200, array('application/json'));
+        return new JsonResponse($json, 200);
     }
 
     /**
@@ -312,7 +317,7 @@ class WallabagRestController extends Controller
     {
         $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json');
 
-        return new Response($json, 200, array('application/json'));
+        return new JsonResponse($json, 200);
     }
 
     /**
@@ -336,6 +341,6 @@ class WallabagRestController extends Controller
 
         $json = $this->get('serializer')->serialize($tag, 'json');
 
-        return new Response($json, 200, array('application/json'));
+        return new JsonResponse($json, 200);
     }
 }