X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FApiBundle%2FController%2FWallabagRestController.php;h=3265ba3876037292eac04123b2b92e8e4b212046;hb=0d3043a29c4aba541d6a18c2d5cc7ebffc6ddc78;hp=d9035cac716440bc2d08111db6053a51c45e1070;hpb=1930c19d8214c05ceefac5ac011a6b6e7e4a983d;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index d9035cac..3265ba38 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -9,36 +9,12 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; class WallabagRestController extends FOSRestController { - /** - * @param Entry $entry - * @param string $tags - */ - private function assignTagsToEntry(Entry $entry, $tags) - { - foreach (explode(',', $tags) as $label) { - $label = trim($label); - $tagEntity = $this - ->getDoctrine() - ->getRepository('WallabagCoreBundle:Tag') - ->findOneByLabel($label); - - if (is_null($tagEntity)) { - $tagEntity = new Tag(); - $tagEntity->setLabel($label); - } - - // only add the tag on the entry if the relation doesn't exist - if (!$entry->getTags()->contains($tagEntity)) { - $entry->addTag($tagEntity); - } - } - } - private function validateAuthentication() { if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { @@ -73,7 +49,6 @@ class WallabagRestController extends FOSRestController $order = $request->query->get('order', 'desc'); $page = (int) $request->query->get('page', 1); $perPage = (int) $request->query->get('perPage', 30); - $tags = $request->query->get('tags', []); $pager = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Entry') @@ -122,6 +97,8 @@ class WallabagRestController extends FOSRestController * {"name"="url", "dataType"="string", "required"=true, "format"="http://www.test.com/article.html", "description"="Url for the entry."}, * {"name"="title", "dataType"="string", "required"=false, "description"="Optional, we'll get the title from the page."}, * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, + * {"name"="starred", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already starred"}, + * {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="entry already archived"}, * } * ) * @@ -132,19 +109,34 @@ class WallabagRestController extends FOSRestController $this->validateAuthentication(); $url = $request->request->get('url'); + $isArchived = $request->request->get('archive'); + $isStarred = $request->request->get('starred'); - $entry = $this->get('wallabag_core.content_proxy')->updateEntry( - new Entry($this->getUser()), - $url - ); + $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId()); + + if (false === $entry) { + $entry = $this->get('wallabag_core.content_proxy')->updateEntry( + new Entry($this->getUser()), + $url + ); + } $tags = $request->request->get('tags', ''); if (!empty($tags)) { - $this->assignTagsToEntry($entry, $tags); + $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); + } + + if ($isStarred === 'true') { + $entry->setStarred(true); + } + + if ($isArchived === 'true') { + $entry->setArchived(true); } $em = $this->getDoctrine()->getManager(); $em->persist($entry); + $em->flush(); $json = $this->get('serializer')->serialize($entry, 'json'); @@ -192,7 +184,7 @@ class WallabagRestController extends FOSRestController $tags = $request->request->get('tags', ''); if (!empty($tags)) { - $this->assignTagsToEntry($entry, $tags); + $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); } $em = $this->getDoctrine()->getManager(); @@ -270,7 +262,7 @@ class WallabagRestController extends FOSRestController $tags = $request->request->get('tags', ''); if (!empty($tags)) { - $this->assignTagsToEntry($entry, $tags); + $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); } $em = $this->getDoctrine()->getManager(); @@ -352,6 +344,21 @@ class WallabagRestController extends FOSRestController return $this->renderJsonResponse($json); } + /** + * Retrieve version number. + * + * @ApiDoc() + * + * @return Response + */ + public function getVersionAction() + { + $version = $this->container->getParameter('wallabag_core.version'); + + $json = $this->get('serializer')->serialize($version, 'json'); + + return $this->renderJsonResponse($json); + } /** * Validate that the first id is equal to the second one.