aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-10-08 12:59:17 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-08 12:59:19 +0200
commit3f3a60879e168f4a8040c441e295fa63e024961d (patch)
treea4b51dabab6bdaa6f7e7679b8bc424b2324b78dc /src/Wallabag/ApiBundle
parent24de86653440de3f84d585f089caab3734dcb573 (diff)
downloadwallabag-3f3a60879e168f4a8040c441e295fa63e024961d.tar.gz
wallabag-3f3a60879e168f4a8040c441e295fa63e024961d.tar.zst
wallabag-3f3a60879e168f4a8040c441e295fa63e024961d.zip
Add entry export in API
Export isn't available for json & xml because user can use the default entry endpoint instead.
Diffstat (limited to 'src/Wallabag/ApiBundle')
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php38
-rw-r--r--src/Wallabag/ApiBundle/Resources/config/routing_rest.yml10
2 files changed, 32 insertions, 16 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index 072e5f85..85875589 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -3,7 +3,7 @@
3namespace Wallabag\ApiBundle\Controller; 3namespace Wallabag\ApiBundle\Controller;
4 4
5use FOS\RestBundle\Controller\FOSRestController; 5use FOS\RestBundle\Controller\FOSRestController;
6use Hateoas\Configuration\Route; 6use Hateoas\Configuration\Route as HateoasRoute;
7use Hateoas\Representation\Factory\PagerfantaFactory; 7use Hateoas\Representation\Factory\PagerfantaFactory;
8use Nelmio\ApiDocBundle\Annotation\ApiDoc; 8use Nelmio\ApiDocBundle\Annotation\ApiDoc;
9use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
@@ -12,6 +12,7 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
12use Symfony\Component\Security\Core\Exception\AccessDeniedException; 12use Symfony\Component\Security\Core\Exception\AccessDeniedException;
13use Wallabag\CoreBundle\Entity\Entry; 13use Wallabag\CoreBundle\Entity\Entry;
14use Wallabag\CoreBundle\Entity\Tag; 14use Wallabag\CoreBundle\Entity\Tag;
15use FOS\RestBundle\Controller\Annotations\Route;
15 16
16class WallabagRestController extends FOSRestController 17class WallabagRestController extends FOSRestController
17{ 18{
@@ -95,7 +96,7 @@ class WallabagRestController extends FOSRestController
95 $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); 96 $pagerfantaFactory = new PagerfantaFactory('page', 'perPage');
96 $paginatedCollection = $pagerfantaFactory->createRepresentation( 97 $paginatedCollection = $pagerfantaFactory->createRepresentation(
97 $pager, 98 $pager,
98 new Route( 99 new HateoasRoute(
99 'api_get_entries', 100 'api_get_entries',
100 [ 101 [
101 'archive' => $isArchived, 102 'archive' => $isArchived,
@@ -127,24 +128,41 @@ class WallabagRestController extends FOSRestController
127 * 128 *
128 * @return JsonResponse 129 * @return JsonResponse
129 */ 130 */
130 public function getEntryAction(Entry $entry, $_format) 131 public function getEntryAction(Entry $entry)
131 { 132 {
132 $this->validateAuthentication(); 133 $this->validateAuthentication();
133 $this->validateUserAccess($entry->getUser()->getId()); 134 $this->validateUserAccess($entry->getUser()->getId());
134 135
135 if ($_format === 'epub') {
136 return $this->get('wallabag_core.helper.entries_export')
137 ->setEntries($entry)
138 ->updateTitle('entry')
139 ->exportAs($_format);
140 }
141
142 $json = $this->get('serializer')->serialize($entry, 'json'); 136 $json = $this->get('serializer')->serialize($entry, 'json');
143 137
144 return (new JsonResponse())->setJson($json); 138 return (new JsonResponse())->setJson($json);
145 } 139 }
146 140
147 /** 141 /**
142 * Retrieve a single entry as a predefined format.
143 *
144 * @ApiDoc(
145 * requirements={
146 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
147 * }
148 * )
149 *
150 * @Route(requirements={"_format"="epub|mobi|pdf|txt|csv"})
151 *
152 * @return Response
153 */
154 public function getEntryExportAction(Entry $entry, Request $request)
155 {
156 $this->validateAuthentication();
157 $this->validateUserAccess($entry->getUser()->getId());
158
159 return $this->get('wallabag_core.helper.entries_export')
160 ->setEntries($entry)
161 ->updateTitle('entry')
162 ->exportAs($request->attributes->get('_format'));
163 }
164
165 /**
148 * Create an entry. 166 * Create an entry.
149 * 167 *
150 * @ApiDoc( 168 * @ApiDoc(
diff --git a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml
index 9aef7e8e..35f8b2c1 100644
--- a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml
+++ b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml
@@ -1,6 +1,4 @@
1entries: 1api:
2 type: rest 2 type: rest
3 resource: "WallabagApiBundle:WallabagRest" 3 resource: "WallabagApiBundle:WallabagRest"
4 name_prefix: api_ 4 name_prefix: api_
5 requirements:
6 _format: xml|json|html|epub