]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
replace Response with JsonResponse
authorNicolas Lœuillet <nicolas@loeuillet.org>
Thu, 26 Feb 2015 13:25:40 +0000 (14:25 +0100)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Fri, 6 Mar 2015 20:09:15 +0000 (21:09 +0100)
src/Wallabag/CoreBundle/Controller/WallabagRestController.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php
src/Wallabag/CoreBundle/Repository/TagRepository.php

index 4215e4478ddcfc66487ebbb9b5085f56a1072c1a..a382caf757b61fbbd89de3adbe0bcc841dfe804d 100644 (file)
@@ -5,11 +5,10 @@ namespace Wallabag\CoreBundle\Controller;
 use Nelmio\ApiDocBundle\Annotation\ApiDoc;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\JsonResponse;
 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
 {
@@ -48,12 +47,12 @@ class WallabagRestController extends Controller
      * )
      * @return array
      */
-    public function getSaltAction($username)
+    public function getSaltAction(Request $request)
     {
         $user = $this
             ->getDoctrine()
             ->getRepository('WallabagCoreBundle:User')
-            ->findOneByUsername($username);
+            ->findOneByUsername($request->query->get('username'));
 
         if (is_null($user)) {
             throw $this->createNotFoundException();
@@ -98,7 +97,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 +118,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 +143,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 +154,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 +195,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 +230,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);
     }
 
     /**
@@ -243,7 +250,7 @@ class WallabagRestController extends Controller
 
         $json = $this->get('serializer')->serialize($entry->getTags(), 'json');
 
-        return new Response($json, 200, array('application/json'));
+        return new JsonResponse($json, 200);
     }
 
     /**
@@ -264,7 +271,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);
@@ -272,7 +282,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);
     }
 
     /**
@@ -298,7 +308,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);
     }
 
     /**
@@ -310,7 +320,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);
     }
 
     /**
@@ -334,6 +344,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);
     }
 }
index e102edc7a3ffe4ae0d645694cc15f9a6c668a076..04fe6aa345137f78a0ef7934ae90782550c955a9 100644 (file)
@@ -128,9 +128,11 @@ class EntryRepository extends EntityRepository
     {
         $qb = $this->createQueryBuilder('e')
             ->innerJoin('e.tags', 't')
-            ->addSelect('t')
-            ->where('t.user=:userId')->setParameter('userId', 1);
+            ->innerJoin('e.user', 'u')
+            ->addSelect('t', 'u')
+            ->where('e.user=:userId')->setParameter('userId', $userId)
+        ;
 
-        return $qb->getQuery()->getOneOrNullResult();
+        return $qb->getQuery()->getResult();
     }
 }
index 0f362f79ebb0efdc37d4a9f2599e4100e24723e6..52f319f11158f69315b30650d5ba9ce0782f8fc8 100644 (file)
@@ -6,18 +6,4 @@ use Doctrine\ORM\EntityRepository;
 
 class TagRepository extends EntityRepository
 {
-    public function findByEntries($entryId)
-    {
-        $qb = $this->createQueryBuilder('t')
-            ->select('t')
-            ->leftJoin('t.id', 'u')
-            ->where('e.isStarred = true')
-            ->andWhere('u.id =:userId')->setParameter('userId', $userId)
-            ->orderBy('e.createdAt', 'desc')
-            ->getQuery();
-
-        $paginator = new Paginator($qb);
-
-        return $paginator;
-    }
 }