From: Nicolas LÅ“uillet Date: Thu, 26 Feb 2015 13:25:40 +0000 (+0100) Subject: replace Response with JsonResponse X-Git-Tag: 2.0.0-alpha.0~73^2~10 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=0ca374e6a1698926b08635d6a276ff3bf91c76a5;p=github%2Fwallabag%2Fwallabag.git replace Response with JsonResponse --- diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 4215e447..a382caf7 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -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); } } diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index e102edc7..04fe6aa3 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -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(); } } diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 0f362f79..52f319f1 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -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; - } }