diff options
4 files changed, 141 insertions, 0 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/AnnotationRestController.php b/src/Wallabag/ApiBundle/Controller/AnnotationRestController.php new file mode 100644 index 00000000..2dd26c07 --- /dev/null +++ b/src/Wallabag/ApiBundle/Controller/AnnotationRestController.php | |||
@@ -0,0 +1,111 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ApiBundle\Controller; | ||
4 | |||
5 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | ||
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | ||
7 | use Symfony\Component\HttpFoundation\Request; | ||
8 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
9 | use Wallabag\CoreBundle\Entity\Entry; | ||
10 | use Wallabag\AnnotationBundle\Entity\Annotation; | ||
11 | |||
12 | class AnnotationRestController extends WallabagRestController | ||
13 | { | ||
14 | /** | ||
15 | * Retrieve annotations for an entry. | ||
16 | * | ||
17 | * @ApiDoc( | ||
18 | * requirements={ | ||
19 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | ||
20 | * } | ||
21 | * ) | ||
22 | * | ||
23 | * @param Entry $entry | ||
24 | * | ||
25 | * @return JsonResponse | ||
26 | */ | ||
27 | public function getAnnotationsAction(Entry $entry) | ||
28 | { | ||
29 | $this->validateAuthentication(); | ||
30 | |||
31 | return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:getAnnotations', [ | ||
32 | 'entry' => $entry, | ||
33 | ]); | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * Creates a new annotation. | ||
38 | * | ||
39 | * @ApiDoc( | ||
40 | * requirements={ | ||
41 | * {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"}, | ||
42 | * {"name"="quote", "dataType"="string", "required"=false, "description"="Optional, quote for the annotation"}, | ||
43 | * {"name"="text", "dataType"="string", "required"=true, "description"=""}, | ||
44 | * } | ||
45 | * ) | ||
46 | * | ||
47 | * @param Request $request | ||
48 | * @param Entry $entry | ||
49 | * | ||
50 | * @return JsonResponse | ||
51 | */ | ||
52 | public function postAnnotationAction(Request $request, Entry $entry) | ||
53 | { | ||
54 | $this->validateAuthentication(); | ||
55 | |||
56 | return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:postAnnotation', [ | ||
57 | 'request' => $request, | ||
58 | 'entry' => $entry, | ||
59 | ]); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Updates an annotation. | ||
64 | * | ||
65 | * @ApiDoc( | ||
66 | * requirements={ | ||
67 | * {"name"="annotation", "dataType"="string", "requirement"="\w+", "description"="The annotation ID"} | ||
68 | * } | ||
69 | * ) | ||
70 | * | ||
71 | * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") | ||
72 | * | ||
73 | * @param Annotation $annotation | ||
74 | * @param Request $request | ||
75 | * | ||
76 | * @return JsonResponse | ||
77 | */ | ||
78 | public function putAnnotationAction(Annotation $annotation, Request $request) | ||
79 | { | ||
80 | $this->validateAuthentication(); | ||
81 | |||
82 | return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:putAnnotation', [ | ||
83 | 'annotation' => $annotation, | ||
84 | 'request' => $request, | ||
85 | ]); | ||
86 | } | ||
87 | |||
88 | /** | ||
89 | * Removes an annotation. | ||
90 | * | ||
91 | * @ApiDoc( | ||
92 | * requirements={ | ||
93 | * {"name"="annotation", "dataType"="string", "requirement"="\w+", "description"="The annotation ID"} | ||
94 | * } | ||
95 | * ) | ||
96 | * | ||
97 | * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation") | ||
98 | * | ||
99 | * @param Annotation $annotation | ||
100 | * | ||
101 | * @return JsonResponse | ||
102 | */ | ||
103 | public function deleteAnnotationAction(Annotation $annotation) | ||
104 | { | ||
105 | $this->validateAuthentication(); | ||
106 | |||
107 | return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:deleteAnnotation', [ | ||
108 | 'annotation' => $annotation, | ||
109 | ]); | ||
110 | } | ||
111 | } | ||
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index b3622c62..c5bf1df8 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -151,6 +151,28 @@ class EntryRestController extends WallabagRestController | |||
151 | } | 151 | } |
152 | 152 | ||
153 | /** | 153 | /** |
154 | * Retrieve a single entry as a predefined format. | ||
155 | * | ||
156 | * @ApiDoc( | ||
157 | * requirements={ | ||
158 | * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} | ||
159 | * } | ||
160 | * ) | ||
161 | * | ||
162 | * @return Response | ||
163 | */ | ||
164 | public function getEntryExportAction(Entry $entry, Request $request) | ||
165 | { | ||
166 | $this->validateAuthentication(); | ||
167 | $this->validateUserAccess($entry->getUser()->getId()); | ||
168 | |||
169 | return $this->get('wallabag_core.helper.entries_export') | ||
170 | ->setEntries($entry) | ||
171 | ->updateTitle('entry') | ||
172 | ->exportAs($request->attributes->get('_format')); | ||
173 | } | ||
174 | |||
175 | /** | ||
154 | * Create an entry. | 176 | * Create an entry. |
155 | * | 177 | * |
156 | * @ApiDoc( | 178 | * @ApiDoc( |
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 544c1ea9..1ff593f5 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -5,6 +5,8 @@ namespace Wallabag\ApiBundle\Controller; | |||
5 | use FOS\RestBundle\Controller\FOSRestController; | 5 | use FOS\RestBundle\Controller\FOSRestController; |
6 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; | 6 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
7 | use Wallabag\CoreBundle\Entity\Entry; | 7 | use Wallabag\CoreBundle\Entity\Entry; |
8 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | ||
9 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
8 | 10 | ||
9 | class WallabagRestController extends FOSRestController | 11 | class WallabagRestController extends FOSRestController |
10 | { | 12 | { |
@@ -19,6 +21,7 @@ class WallabagRestController extends FOSRestController | |||
19 | { | 21 | { |
20 | $version = $this->container->getParameter('wallabag_core.version'); | 22 | $version = $this->container->getParameter('wallabag_core.version'); |
21 | $json = $this->get('serializer')->serialize($version, 'json'); | 23 | $json = $this->get('serializer')->serialize($version, 'json'); |
24 | |||
22 | return (new JsonResponse())->setJson($json); | 25 | return (new JsonResponse())->setJson($json); |
23 | } | 26 | } |
24 | 27 | ||
diff --git a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml index 8e1886ac..57d37f4b 100644 --- a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml +++ b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml | |||
@@ -8,6 +8,11 @@ tag: | |||
8 | resource: "WallabagApiBundle:TagRest" | 8 | resource: "WallabagApiBundle:TagRest" |
9 | name_prefix: api_ | 9 | name_prefix: api_ |
10 | 10 | ||
11 | annotation: | ||
12 | type: rest | ||
13 | resource: "WallabagApiBundle:AnnotationRest" | ||
14 | name_prefix: api_ | ||
15 | |||
11 | misc: | 16 | misc: |
12 | type: rest | 17 | type: rest |
13 | resource: "WallabagApiBundle:WallabagRest" | 18 | resource: "WallabagApiBundle:WallabagRest" |