X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FApiBundle%2FController%2FWallabagRestController.php;h=f8a2745a47dce2696fa562f526166ffc34d54982;hb=619cc45359ead519b64129181a07e14160fbbfcb;hp=1fee56ad14693c812e8b0896a0693faf8dd41d14;hpb=772732531ea1d0f9831cc5f29e11b6b11fd088f3;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 1fee56ad..f8a2745a 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -3,13 +3,13 @@ namespace Wallabag\ApiBundle\Controller; use FOS\RestBundle\Controller\FOSRestController; +use Hateoas\Configuration\Route; +use Hateoas\Representation\Factory\PagerfantaFactory; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; -use Hateoas\Configuration\Route; -use Hateoas\Representation\Factory\PagerfantaFactory; class WallabagRestController extends FOSRestController { @@ -27,7 +27,7 @@ class WallabagRestController extends FOSRestController ->findOneByLabel($label); if (is_null($tagEntity)) { - $tagEntity = new Tag($this->getUser()); + $tagEntity = new Tag(); $tagEntity->setLabel($label); } @@ -40,7 +40,7 @@ class WallabagRestController extends FOSRestController private function validateAuthentication() { - if (false === $this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) { + if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { throw new AccessDeniedException(); } } @@ -60,7 +60,7 @@ class WallabagRestController extends FOSRestController * } * ) * - * @return Entry + * @return Response */ public function getEntriesAction(Request $request) { @@ -74,8 +74,7 @@ class WallabagRestController extends FOSRestController $perPage = (int) $request->query->get('perPage', 30); $tags = $request->query->get('tags', []); - $pager = $this - ->getDoctrine() + $pager = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Entry') ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order); @@ -102,7 +101,7 @@ class WallabagRestController extends FOSRestController * } * ) * - * @return Entry + * @return Response */ public function getEntryAction(Entry $entry) { @@ -125,7 +124,7 @@ class WallabagRestController extends FOSRestController * } * ) * - * @return Entry + * @return Response */ public function postEntriesAction(Request $request) { @@ -167,7 +166,7 @@ class WallabagRestController extends FOSRestController * } * ) * - * @return Entry + * @return Response */ public function patchEntriesAction(Entry $entry, Request $request) { @@ -175,8 +174,8 @@ class WallabagRestController extends FOSRestController $this->validateUserAccess($entry->getUser()->getId()); $title = $request->request->get('title'); - $isArchived = $request->request->get('is_archived'); - $isStarred = $request->request->get('is_starred'); + $isArchived = $request->request->get('archive'); + $isStarred = $request->request->get('star'); if (!is_null($title)) { $entry->setTitle($title); @@ -212,7 +211,7 @@ class WallabagRestController extends FOSRestController * } * ) * - * @return Entry + * @return Response */ public function deleteEntriesAction(Entry $entry) { @@ -236,6 +235,8 @@ class WallabagRestController extends FOSRestController * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) + * + * @return Response */ public function getEntriesTagsAction(Entry $entry) { @@ -258,6 +259,8 @@ class WallabagRestController extends FOSRestController * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, * } * ) + * + * @return Response */ public function postEntriesTagsAction(Request $request, Entry $entry) { @@ -287,6 +290,8 @@ class WallabagRestController extends FOSRestController * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) + * + * @return Response */ public function deleteEntriesTagsAction(Entry $entry, Tag $tag) { @@ -307,11 +312,18 @@ class WallabagRestController extends FOSRestController * Retrieve all tags. * * @ApiDoc() + * + * @return Response */ public function getTagsAction() { $this->validateAuthentication(); - $json = $this->get('serializer')->serialize($this->getUser()->getTags(), 'json'); + + $tags = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Tag') + ->findAllTags($this->getUser()->getId()); + + $json = $this->get('serializer')->serialize($tags, 'json'); return $this->renderJsonResponse($json); } @@ -324,15 +336,16 @@ class WallabagRestController extends FOSRestController * {"name"="tag", "dataType"="integer", "requirement"="\w+", "description"="The tag"} * } * ) + * + * @return Response */ public function deleteTagAction(Tag $tag) { $this->validateAuthentication(); - $this->validateUserAccess($tag->getUser()->getId()); - $em = $this->getDoctrine()->getManager(); - $em->remove($tag); - $em->flush(); + $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->removeTag($this->getUser()->getId(), $tag); $json = $this->get('serializer')->serialize($tag, 'json'); @@ -347,7 +360,7 @@ class WallabagRestController extends FOSRestController */ private function validateUserAccess($requestUserId) { - $user = $this->get('security.context')->getToken()->getUser(); + $user = $this->get('security.token_storage')->getToken()->getUser(); if ($requestUserId != $user->getId()) { throw $this->createAccessDeniedException('Access forbidden. Entry user id: '.$requestUserId.', logged user id: '.$user->getId()); }