aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php')
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php126
1 files changed, 124 insertions, 2 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index 9997913d..a73d44ca 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -3,15 +3,17 @@
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 Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
9use Symfony\Component\HttpFoundation\Request; 10use Symfony\Component\HttpFoundation\Request;
10use Symfony\Component\HttpFoundation\JsonResponse; 11use Symfony\Component\HttpFoundation\JsonResponse;
11use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 12use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
12use Symfony\Component\Security\Core\Exception\AccessDeniedException; 13use Symfony\Component\Security\Core\Exception\AccessDeniedException;
13use Wallabag\CoreBundle\Entity\Entry; 14use Wallabag\CoreBundle\Entity\Entry;
14use Wallabag\CoreBundle\Entity\Tag; 15use Wallabag\CoreBundle\Entity\Tag;
16use Wallabag\AnnotationBundle\Entity\Annotation;
15 17
16class WallabagRestController extends FOSRestController 18class WallabagRestController extends FOSRestController
17{ 19{
@@ -115,7 +117,7 @@ class WallabagRestController extends FOSRestController
115 $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); 117 $pagerfantaFactory = new PagerfantaFactory('page', 'perPage');
116 $paginatedCollection = $pagerfantaFactory->createRepresentation( 118 $paginatedCollection = $pagerfantaFactory->createRepresentation(
117 $pager, 119 $pager,
118 new Route( 120 new HateoasRoute(
119 'api_get_entries', 121 'api_get_entries',
120 [ 122 [
121 'archive' => $isArchived, 123 'archive' => $isArchived,
@@ -158,6 +160,28 @@ class WallabagRestController extends FOSRestController
158 } 160 }
159 161
160 /** 162 /**
163 * Retrieve a single entry as a predefined format.
164 *
165 * @ApiDoc(
166 * requirements={
167 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
168 * }
169 * )
170 *
171 * @return Response
172 */
173 public function getEntryExportAction(Entry $entry, Request $request)
174 {
175 $this->validateAuthentication();
176 $this->validateUserAccess($entry->getUser()->getId());
177
178 return $this->get('wallabag_core.helper.entries_export')
179 ->setEntries($entry)
180 ->updateTitle('entry')
181 ->exportAs($request->attributes->get('_format'));
182 }
183
184 /**
161 * Create an entry. 185 * Create an entry.
162 * 186 *
163 * @ApiDoc( 187 * @ApiDoc(
@@ -496,6 +520,104 @@ class WallabagRestController extends FOSRestController
496 } 520 }
497 521
498 /** 522 /**
523 * Retrieve annotations for an entry.
524 *
525 * @ApiDoc(
526 * requirements={
527 * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"}
528 * }
529 * )
530 *
531 * @param Entry $entry
532 *
533 * @return JsonResponse
534 */
535 public function getAnnotationsAction(Entry $entry)
536 {
537 $this->validateAuthentication();
538
539 return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:getAnnotations', [
540 'entry' => $entry,
541 ]);
542 }
543
544 /**
545 * Creates a new annotation.
546 *
547 * @ApiDoc(
548 * requirements={
549 * {"name"="ranges", "dataType"="array", "requirement"="\w+", "description"="The range array for the annotation"},
550 * {"name"="quote", "dataType"="string", "required"=false, "description"="Optional, quote for the annotation"},
551 * {"name"="text", "dataType"="string", "required"=true, "description"=""},
552 * }
553 * )
554 *
555 * @param Request $request
556 * @param Entry $entry
557 *
558 * @return JsonResponse
559 */
560 public function postAnnotationAction(Request $request, Entry $entry)
561 {
562 $this->validateAuthentication();
563
564 return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:postAnnotation', [
565 'request' => $request,
566 'entry' => $entry,
567 ]);
568 }
569
570 /**
571 * Updates an annotation.
572 *
573 * @ApiDoc(
574 * requirements={
575 * {"name"="annotation", "dataType"="string", "requirement"="\w+", "description"="The annotation ID"}
576 * }
577 * )
578 *
579 * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation")
580 *
581 * @param Annotation $annotation
582 * @param Request $request
583 *
584 * @return JsonResponse
585 */
586 public function putAnnotationAction(Annotation $annotation, Request $request)
587 {
588 $this->validateAuthentication();
589
590 return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:putAnnotation', [
591 'annotation' => $annotation,
592 'request' => $request,
593 ]);
594 }
595
596 /**
597 * Removes an annotation.
598 *
599 * @ApiDoc(
600 * requirements={
601 * {"name"="annotation", "dataType"="string", "requirement"="\w+", "description"="The annotation ID"}
602 * }
603 * )
604 *
605 * @ParamConverter("annotation", class="WallabagAnnotationBundle:Annotation")
606 *
607 * @param Annotation $annotation
608 *
609 * @return JsonResponse
610 */
611 public function deleteAnnotationAction(Annotation $annotation)
612 {
613 $this->validateAuthentication();
614
615 return $this->forward('WallabagAnnotationBundle:WallabagAnnotation:deleteAnnotation', [
616 'annotation' => $annotation,
617 ]);
618 }
619
620 /**
499 * Retrieve version number. 621 * Retrieve version number.
500 * 622 *
501 * @ApiDoc() 623 * @ApiDoc()