X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FApiBundle%2FController%2FWallabagRestController.php;h=d9035cac716440bc2d08111db6053a51c45e1070;hb=86719c63bf47686ca55020e6b0443344de36d45a;hp=74bfe4dcdb286a3337e00d889a80ffb3d1918b05;hpb=4529d0f4b6b20cbbd1ccb5339a753aff7d35552b;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 74bfe4dc..d9035cac 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -3,13 +3,14 @@ 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 Symfony\Component\Routing\Generator\UrlGeneratorInterface; 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 +28,7 @@ class WallabagRestController extends FOSRestController ->findOneByLabel($label); if (is_null($tagEntity)) { - $tagEntity = new Tag($this->getUser()); + $tagEntity = new Tag(); $tagEntity->setLabel($label); } @@ -60,7 +61,7 @@ class WallabagRestController extends FOSRestController * } * ) * - * @return Entry + * @return Response */ public function getEntriesAction(Request $request) { @@ -74,8 +75,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); @@ -85,7 +85,7 @@ class WallabagRestController extends FOSRestController $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); $paginatedCollection = $pagerfantaFactory->createRepresentation( $pager, - new Route('api_get_entries', [], $absolute = true) + new Route('api_get_entries', [], UrlGeneratorInterface::ABSOLUTE_URL) ); $json = $this->get('serializer')->serialize($paginatedCollection, 'json'); @@ -102,7 +102,7 @@ class WallabagRestController extends FOSRestController * } * ) * - * @return Entry + * @return Response */ public function getEntryAction(Entry $entry) { @@ -125,7 +125,7 @@ class WallabagRestController extends FOSRestController * } * ) * - * @return Entry + * @return Response */ public function postEntriesAction(Request $request) { @@ -167,7 +167,7 @@ class WallabagRestController extends FOSRestController * } * ) * - * @return Entry + * @return Response */ public function patchEntriesAction(Entry $entry, Request $request) { @@ -175,8 +175,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 +212,7 @@ class WallabagRestController extends FOSRestController * } * ) * - * @return Entry + * @return Response */ public function deleteEntriesAction(Entry $entry) { @@ -236,6 +236,8 @@ class WallabagRestController extends FOSRestController * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) + * + * @return Response */ public function getEntriesTagsAction(Entry $entry) { @@ -258,6 +260,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 +291,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 +313,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 +337,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');