diff options
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/EntryRestController.php')
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/EntryRestController.php | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 24fa7b3b..c5bf1df8 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -10,6 +10,8 @@ use Symfony\Component\HttpFoundation\JsonResponse; | |||
10 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 10 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
11 | use Wallabag\CoreBundle\Entity\Entry; | 11 | use Wallabag\CoreBundle\Entity\Entry; |
12 | use Wallabag\CoreBundle\Entity\Tag; | 12 | use Wallabag\CoreBundle\Entity\Tag; |
13 | use Wallabag\CoreBundle\Event\EntrySavedEvent; | ||
14 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; | ||
13 | 15 | ||
14 | class EntryRestController extends WallabagRestController | 16 | class EntryRestController extends WallabagRestController |
15 | { | 17 | { |
@@ -149,6 +151,28 @@ class EntryRestController extends WallabagRestController | |||
149 | } | 151 | } |
150 | 152 | ||
151 | /** | 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 | /** | ||
152 | * Create an entry. | 176 | * Create an entry. |
153 | * | 177 | * |
154 | * @ApiDoc( | 178 | * @ApiDoc( |
@@ -200,9 +224,11 @@ class EntryRestController extends WallabagRestController | |||
200 | 224 | ||
201 | $em = $this->getDoctrine()->getManager(); | 225 | $em = $this->getDoctrine()->getManager(); |
202 | $em->persist($entry); | 226 | $em->persist($entry); |
203 | |||
204 | $em->flush(); | 227 | $em->flush(); |
205 | 228 | ||
229 | // entry saved, dispatch event about it! | ||
230 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); | ||
231 | |||
206 | $json = $this->get('serializer')->serialize($entry, 'json'); | 232 | $json = $this->get('serializer')->serialize($entry, 'json'); |
207 | 233 | ||
208 | return (new JsonResponse())->setJson($json); | 234 | return (new JsonResponse())->setJson($json); |
@@ -279,6 +305,9 @@ class EntryRestController extends WallabagRestController | |||
279 | $em->remove($entry); | 305 | $em->remove($entry); |
280 | $em->flush(); | 306 | $em->flush(); |
281 | 307 | ||
308 | // entry deleted, dispatch event about it! | ||
309 | $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry)); | ||
310 | |||
282 | $json = $this->get('serializer')->serialize($entry, 'json'); | 311 | $json = $this->get('serializer')->serialize($entry, 'json'); |
283 | 312 | ||
284 | return (new JsonResponse())->setJson($json); | 313 | return (new JsonResponse())->setJson($json); |