diff options
3 files changed, 32 insertions, 34 deletions
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; | |||
5 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | 5 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | use Symfony\Component\HttpFoundation\Response; | 8 | use Symfony\Component\HttpFoundation\JsonResponse; |
9 | use Wallabag\CoreBundle\Entity\Entry; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
10 | use Wallabag\CoreBundle\Entity\Tag; | 10 | use Wallabag\CoreBundle\Entity\Tag; |
11 | use Wallabag\CoreBundle\Service\Extractor; | 11 | use Wallabag\CoreBundle\Service\Extractor; |
12 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; | ||
13 | 12 | ||
14 | class WallabagRestController extends Controller | 13 | class WallabagRestController extends Controller |
15 | { | 14 | { |
@@ -48,12 +47,12 @@ class WallabagRestController extends Controller | |||
48 | * ) | 47 | * ) |
49 | * @return array | 48 | * @return array |
50 | */ | 49 | */ |
51 | public function getSaltAction($username) | 50 | public function getSaltAction(Request $request) |
52 | { | 51 | { |
53 | $user = $this | 52 | $user = $this |
54 | ->getDoctrine() | 53 | ->getDoctrine() |
55 | ->getRepository('WallabagCoreBundle:User') | 54 | ->getRepository('WallabagCoreBundle:User') |
56 | ->findOneByUsername($username); | 55 | ->findOneByUsername($request->query->get('username')); |
57 | 56 | ||
58 | if (is_null($user)) { | 57 | if (is_null($user)) { |
59 | throw $this->createNotFoundException(); | 58 | throw $this->createNotFoundException(); |
@@ -98,7 +97,7 @@ class WallabagRestController extends Controller | |||
98 | 97 | ||
99 | $json = $this->get('serializer')->serialize($entries, 'json'); | 98 | $json = $this->get('serializer')->serialize($entries, 'json'); |
100 | 99 | ||
101 | return new Response($json, 200, array('application/json')); | 100 | return new JsonResponse($json, 200); |
102 | } | 101 | } |
103 | 102 | ||
104 | /** | 103 | /** |
@@ -119,7 +118,7 @@ class WallabagRestController extends Controller | |||
119 | 118 | ||
120 | $json = $this->get('serializer')->serialize($entry, 'json'); | 119 | $json = $this->get('serializer')->serialize($entry, 'json'); |
121 | 120 | ||
122 | return new Response($json, 200, array('application/json')); | 121 | return new JsonResponse($json, 200); |
123 | } | 122 | } |
124 | 123 | ||
125 | /** | 124 | /** |
@@ -144,7 +143,10 @@ class WallabagRestController extends Controller | |||
144 | $entry->setTitle($request->request->get('title') ?: $content->getTitle()); | 143 | $entry->setTitle($request->request->get('title') ?: $content->getTitle()); |
145 | $entry->setContent($content->getBody()); | 144 | $entry->setContent($content->getBody()); |
146 | 145 | ||
147 | $this->assignTagsToEntry($entry, $request->request->get('tags', array())); | 146 | $tags = $request->request->get('tags', ''); |
147 | if (!empty($tags)) { | ||
148 | $this->assignTagsToEntry($entry, $tags); | ||
149 | } | ||
148 | 150 | ||
149 | $em = $this->getDoctrine()->getManager(); | 151 | $em = $this->getDoctrine()->getManager(); |
150 | $em->persist($entry); | 152 | $em->persist($entry); |
@@ -152,7 +154,7 @@ class WallabagRestController extends Controller | |||
152 | 154 | ||
153 | $json = $this->get('serializer')->serialize($entry, 'json'); | 155 | $json = $this->get('serializer')->serialize($entry, 'json'); |
154 | 156 | ||
155 | return new Response($json, 200, array('application/json')); | 157 | return new JsonResponse($json, 200); |
156 | } | 158 | } |
157 | 159 | ||
158 | /** | 160 | /** |
@@ -193,12 +195,17 @@ class WallabagRestController extends Controller | |||
193 | $entry->setStarred($isStarred); | 195 | $entry->setStarred($isStarred); |
194 | } | 196 | } |
195 | 197 | ||
196 | $this->assignTagsToEntry($entry, $request->request->get('tags', array())); | 198 | $tags = $request->request->get('tags', ''); |
199 | if (!empty($tags)) { | ||
200 | $this->assignTagsToEntry($entry, $tags); | ||
201 | } | ||
197 | 202 | ||
198 | $em = $this->getDoctrine()->getManager(); | 203 | $em = $this->getDoctrine()->getManager(); |
199 | $em->flush(); | 204 | $em->flush(); |
200 | 205 | ||
201 | return $entry; | 206 | $json = $this->get('serializer')->serialize($entry, 'json'); |
207 | |||
208 | return new JsonResponse($json, 200); | ||
202 | } | 209 | } |
203 | 210 | ||
204 | /** | 211 | /** |
@@ -223,7 +230,7 @@ class WallabagRestController extends Controller | |||
223 | 230 | ||
224 | $json = $this->get('serializer')->serialize($entry, 'json'); | 231 | $json = $this->get('serializer')->serialize($entry, 'json'); |
225 | 232 | ||
226 | return new Response($json, 200, array('application/json')); | 233 | return new JsonResponse($json, 200); |
227 | } | 234 | } |
228 | 235 | ||
229 | /** | 236 | /** |
@@ -243,7 +250,7 @@ class WallabagRestController extends Controller | |||
243 | 250 | ||
244 | $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); | 251 | $json = $this->get('serializer')->serialize($entry->getTags(), 'json'); |
245 | 252 | ||
246 | return new Response($json, 200, array('application/json')); | 253 | return new JsonResponse($json, 200); |
247 | } | 254 | } |
248 | 255 | ||
249 | /** | 256 | /** |
@@ -264,7 +271,10 @@ class WallabagRestController extends Controller | |||
264 | throw $this->createAccessDeniedException(); | 271 | throw $this->createAccessDeniedException(); |
265 | } | 272 | } |
266 | 273 | ||
267 | $this->assignTagsToEntry($entry, $request->request->get('tags', array())); | 274 | $tags = $request->request->get('tags', ''); |
275 | if (!empty($tags)) { | ||
276 | $this->assignTagsToEntry($entry, $tags); | ||
277 | } | ||
268 | 278 | ||
269 | $em = $this->getDoctrine()->getManager(); | 279 | $em = $this->getDoctrine()->getManager(); |
270 | $em->persist($entry); | 280 | $em->persist($entry); |
@@ -272,7 +282,7 @@ class WallabagRestController extends Controller | |||
272 | 282 | ||
273 | $json = $this->get('serializer')->serialize($entry, 'json'); | 283 | $json = $this->get('serializer')->serialize($entry, 'json'); |
274 | 284 | ||
275 | return new Response($json, 200, array('application/json')); | 285 | return new JsonResponse($json, 200); |
276 | } | 286 | } |
277 | 287 | ||
278 | /** | 288 | /** |
@@ -298,7 +308,7 @@ class WallabagRestController extends Controller | |||
298 | 308 | ||
299 | $json = $this->get('serializer')->serialize($entry, 'json'); | 309 | $json = $this->get('serializer')->serialize($entry, 'json'); |
300 | 310 | ||
301 | return new Response($json, 200, array('application/json')); | 311 | return new JsonResponse($json, 200); |
302 | } | 312 | } |
303 | 313 | ||
304 | /** | 314 | /** |
@@ -310,7 +320,7 @@ class WallabagRestController extends Controller | |||
310 | { | 320 | { |
311 | $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json'); | 321 | $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json'); |
312 | 322 | ||
313 | return new Response($json, 200, array('application/json')); | 323 | return new JsonResponse($json, 200); |
314 | } | 324 | } |
315 | 325 | ||
316 | /** | 326 | /** |
@@ -334,6 +344,6 @@ class WallabagRestController extends Controller | |||
334 | 344 | ||
335 | $json = $this->get('serializer')->serialize($tag, 'json'); | 345 | $json = $this->get('serializer')->serialize($tag, 'json'); |
336 | 346 | ||
337 | return new Response($json, 200, array('application/json')); | 347 | return new JsonResponse($json, 200); |
338 | } | 348 | } |
339 | } | 349 | } |
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 | |||
128 | { | 128 | { |
129 | $qb = $this->createQueryBuilder('e') | 129 | $qb = $this->createQueryBuilder('e') |
130 | ->innerJoin('e.tags', 't') | 130 | ->innerJoin('e.tags', 't') |
131 | ->addSelect('t') | 131 | ->innerJoin('e.user', 'u') |
132 | ->where('t.user=:userId')->setParameter('userId', 1); | 132 | ->addSelect('t', 'u') |
133 | ->where('e.user=:userId')->setParameter('userId', $userId) | ||
134 | ; | ||
133 | 135 | ||
134 | return $qb->getQuery()->getOneOrNullResult(); | 136 | return $qb->getQuery()->getResult(); |
135 | } | 137 | } |
136 | } | 138 | } |
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; | |||
6 | 6 | ||
7 | class TagRepository extends EntityRepository | 7 | class TagRepository extends EntityRepository |
8 | { | 8 | { |
9 | public function findByEntries($entryId) | ||
10 | { | ||
11 | $qb = $this->createQueryBuilder('t') | ||
12 | ->select('t') | ||
13 | ->leftJoin('t.id', 'u') | ||
14 | ->where('e.isStarred = true') | ||
15 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) | ||
16 | ->orderBy('e.createdAt', 'desc') | ||
17 | ->getQuery(); | ||
18 | |||
19 | $paginator = new Paginator($qb); | ||
20 | |||
21 | return $paginator; | ||
22 | } | ||
23 | } | 9 | } |