diff options
Diffstat (limited to 'src/Wallabag/ApiBundle')
8 files changed, 162 insertions, 25 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/DeveloperController.php b/src/Wallabag/ApiBundle/Controller/DeveloperController.php index c7178017..ae7e83da 100644 --- a/src/Wallabag/ApiBundle/Controller/DeveloperController.php +++ b/src/Wallabag/ApiBundle/Controller/DeveloperController.php | |||
@@ -2,9 +2,9 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\ApiBundle\Controller; | 3 | namespace Wallabag\ApiBundle\Controller; |
4 | 4 | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\Request; | 6 | use Symfony\Component\HttpFoundation\Request; |
7 | use Symfony\Component\Routing\Annotation\Route; | ||
8 | use Wallabag\ApiBundle\Entity\Client; | 8 | use Wallabag\ApiBundle\Entity\Client; |
9 | use Wallabag\ApiBundle\Form\Type\ClientType; | 9 | use Wallabag\ApiBundle\Form\Type\ClientType; |
10 | 10 | ||
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index b2bad406..16d8a40b 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -4,14 +4,12 @@ namespace Wallabag\ApiBundle\Controller; | |||
4 | 4 | ||
5 | use Hateoas\Configuration\Route; | 5 | use Hateoas\Configuration\Route; |
6 | use Hateoas\Representation\Factory\PagerfantaFactory; | 6 | use Hateoas\Representation\Factory\PagerfantaFactory; |
7 | use JMS\Serializer\SerializationContext; | ||
8 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | 7 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
9 | use Symfony\Component\HttpFoundation\JsonResponse; | 8 | use Symfony\Component\HttpFoundation\JsonResponse; |
10 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
11 | use Symfony\Component\HttpFoundation\Response; | 10 | use Symfony\Component\HttpFoundation\Response; |
12 | use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | 11 | use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
13 | use Symfony\Component\HttpKernel\Exception\HttpException; | 12 | use Symfony\Component\HttpKernel\Exception\HttpException; |
14 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
15 | use Wallabag\CoreBundle\Entity\Entry; | 13 | use Wallabag\CoreBundle\Entity\Entry; |
16 | use Wallabag\CoreBundle\Entity\Tag; | 14 | use Wallabag\CoreBundle\Entity\Tag; |
17 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; | 15 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; |
@@ -80,7 +78,7 @@ class EntryRestController extends WallabagRestController | |||
80 | * parameters={ | 78 | * parameters={ |
81 | * {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by archived status."}, | 79 | * {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by archived status."}, |
82 | * {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by starred status."}, | 80 | * {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by starred status."}, |
83 | * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."}, | 81 | * {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated' or 'archived', default 'created'", "description"="sort entries by date."}, |
84 | * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."}, | 82 | * {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."}, |
85 | * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, | 83 | * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, |
86 | * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, | 84 | * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."}, |
@@ -141,7 +139,7 @@ class EntryRestController extends WallabagRestController | |||
141 | 'tags' => $tags, | 139 | 'tags' => $tags, |
142 | 'since' => $since, | 140 | 'since' => $since, |
143 | ], | 141 | ], |
144 | UrlGeneratorInterface::ABSOLUTE_URL | 142 | true |
145 | ) | 143 | ) |
146 | ); | 144 | ); |
147 | 145 | ||
@@ -363,7 +361,7 @@ class EntryRestController extends WallabagRestController | |||
363 | } | 361 | } |
364 | 362 | ||
365 | if (null !== $data['isArchived']) { | 363 | if (null !== $data['isArchived']) { |
366 | $entry->setArchived((bool) $data['isArchived']); | 364 | $entry->updateArchived((bool) $data['isArchived']); |
367 | } | 365 | } |
368 | 366 | ||
369 | if (null !== $data['isStarred']) { | 367 | if (null !== $data['isStarred']) { |
@@ -479,7 +477,7 @@ class EntryRestController extends WallabagRestController | |||
479 | } | 477 | } |
480 | 478 | ||
481 | if (null !== $data['isArchived']) { | 479 | if (null !== $data['isArchived']) { |
482 | $entry->setArchived((bool) $data['isArchived']); | 480 | $entry->updateArchived((bool) $data['isArchived']); |
483 | } | 481 | } |
484 | 482 | ||
485 | if (null !== $data['isStarred']) { | 483 | if (null !== $data['isStarred']) { |
@@ -774,24 +772,6 @@ class EntryRestController extends WallabagRestController | |||
774 | } | 772 | } |
775 | 773 | ||
776 | /** | 774 | /** |
777 | * Shortcut to send data serialized in json. | ||
778 | * | ||
779 | * @param mixed $data | ||
780 | * | ||
781 | * @return JsonResponse | ||
782 | */ | ||
783 | private function sendResponse($data) | ||
784 | { | ||
785 | // https://github.com/schmittjoh/JMSSerializerBundle/issues/293 | ||
786 | $context = new SerializationContext(); | ||
787 | $context->setSerializeNull(true); | ||
788 | |||
789 | $json = $this->get('jms_serializer')->serialize($data, 'json', $context); | ||
790 | |||
791 | return (new JsonResponse())->setJson($json); | ||
792 | } | ||
793 | |||
794 | /** | ||
795 | * Retrieve value from the request. | 775 | * Retrieve value from the request. |
796 | * Used for POST & PATCH on a an entry. | 776 | * Used for POST & PATCH on a an entry. |
797 | * | 777 | * |
diff --git a/src/Wallabag/ApiBundle/Controller/SearchRestController.php b/src/Wallabag/ApiBundle/Controller/SearchRestController.php new file mode 100644 index 00000000..d9f99844 --- /dev/null +++ b/src/Wallabag/ApiBundle/Controller/SearchRestController.php | |||
@@ -0,0 +1,65 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ApiBundle\Controller; | ||
4 | |||
5 | use Hateoas\Configuration\Route; | ||
6 | use Hateoas\Representation\Factory\PagerfantaFactory; | ||
7 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | ||
8 | use Pagerfanta\Adapter\DoctrineORMAdapter; | ||
9 | use Pagerfanta\Pagerfanta; | ||
10 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
11 | use Symfony\Component\HttpFoundation\Request; | ||
12 | |||
13 | class SearchRestController extends WallabagRestController | ||
14 | { | ||
15 | /** | ||
16 | * Search all entries by term. | ||
17 | * | ||
18 | * @ApiDoc( | ||
19 | * parameters={ | ||
20 | * {"name"="term", "dataType"="string", "required"=false, "format"="any", "description"="Any query term"}, | ||
21 | * {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."}, | ||
22 | * {"name"="perPage", "dataType"="integer", "required"=false, "format"="default'30'", "description"="results per page."} | ||
23 | * } | ||
24 | * ) | ||
25 | * | ||
26 | * @return JsonResponse | ||
27 | */ | ||
28 | public function getSearchAction(Request $request) | ||
29 | { | ||
30 | $this->validateAuthentication(); | ||
31 | |||
32 | $term = $request->query->get('term'); | ||
33 | $page = (int) $request->query->get('page', 1); | ||
34 | $perPage = (int) $request->query->get('perPage', 30); | ||
35 | |||
36 | $qb = $this->get('wallabag_core.entry_repository') | ||
37 | ->getBuilderForSearchByUser( | ||
38 | $this->getUser()->getId(), | ||
39 | $term, | ||
40 | null | ||
41 | ); | ||
42 | |||
43 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); | ||
44 | $pager = new Pagerfanta($pagerAdapter); | ||
45 | |||
46 | $pager->setMaxPerPage($perPage); | ||
47 | $pager->setCurrentPage($page); | ||
48 | |||
49 | $pagerfantaFactory = new PagerfantaFactory('page', 'perPage'); | ||
50 | $paginatedCollection = $pagerfantaFactory->createRepresentation( | ||
51 | $pager, | ||
52 | new Route( | ||
53 | 'api_get_search', | ||
54 | [ | ||
55 | 'term' => $term, | ||
56 | 'page' => $page, | ||
57 | 'perPage' => $perPage, | ||
58 | ], | ||
59 | true | ||
60 | ) | ||
61 | ); | ||
62 | |||
63 | return $this->sendResponse($paginatedCollection); | ||
64 | } | ||
65 | } | ||
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index 7d8cfbba..f18b0910 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Wallabag\ApiBundle\Controller; | 3 | namespace Wallabag\ApiBundle\Controller; |
4 | 4 | ||
5 | use FOS\RestBundle\Controller\FOSRestController; | 5 | use FOS\RestBundle\Controller\FOSRestController; |
6 | use JMS\Serializer\SerializationContext; | ||
6 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | 7 | use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
7 | use Symfony\Component\HttpFoundation\JsonResponse; | 8 | use Symfony\Component\HttpFoundation\JsonResponse; |
8 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; | 9 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
@@ -14,6 +15,8 @@ class WallabagRestController extends FOSRestController | |||
14 | * | 15 | * |
15 | * @ApiDoc() | 16 | * @ApiDoc() |
16 | * | 17 | * |
18 | * @deprecated Should use info endpoint instead | ||
19 | * | ||
17 | * @return JsonResponse | 20 | * @return JsonResponse |
18 | */ | 21 | */ |
19 | public function getVersionAction() | 22 | public function getVersionAction() |
@@ -24,6 +27,24 @@ class WallabagRestController extends FOSRestController | |||
24 | return (new JsonResponse())->setJson($json); | 27 | return (new JsonResponse())->setJson($json); |
25 | } | 28 | } |
26 | 29 | ||
30 | /** | ||
31 | * Retrieve information about the wallabag instance. | ||
32 | * | ||
33 | * @ApiDoc() | ||
34 | * | ||
35 | * @return JsonResponse | ||
36 | */ | ||
37 | public function getInfoAction() | ||
38 | { | ||
39 | $info = [ | ||
40 | 'appname' => 'wallabag', | ||
41 | 'version' => $this->container->getParameter('wallabag_core.version'), | ||
42 | 'allowed_registration' => $this->container->getParameter('wallabag_user.registration_enabled'), | ||
43 | ]; | ||
44 | |||
45 | return (new JsonResponse())->setJson($this->get('jms_serializer')->serialize($info, 'json')); | ||
46 | } | ||
47 | |||
27 | protected function validateAuthentication() | 48 | protected function validateAuthentication() |
28 | { | 49 | { |
29 | if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { | 50 | if (false === $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { |
@@ -44,4 +65,22 @@ class WallabagRestController extends FOSRestController | |||
44 | throw $this->createAccessDeniedException('Access forbidden. Entry user id: ' . $requestUserId . ', logged user id: ' . $user->getId()); | 65 | throw $this->createAccessDeniedException('Access forbidden. Entry user id: ' . $requestUserId . ', logged user id: ' . $user->getId()); |
45 | } | 66 | } |
46 | } | 67 | } |
68 | |||
69 | /** | ||
70 | * Shortcut to send data serialized in json. | ||
71 | * | ||
72 | * @param mixed $data | ||
73 | * | ||
74 | * @return JsonResponse | ||
75 | */ | ||
76 | protected function sendResponse($data) | ||
77 | { | ||
78 | // https://github.com/schmittjoh/JMSSerializerBundle/issues/293 | ||
79 | $context = new SerializationContext(); | ||
80 | $context->setSerializeNull(true); | ||
81 | |||
82 | $json = $this->get('jms_serializer')->serialize($data, 'json', $context); | ||
83 | |||
84 | return (new JsonResponse())->setJson($json); | ||
85 | } | ||
47 | } | 86 | } |
diff --git a/src/Wallabag/ApiBundle/Entity/AccessToken.php b/src/Wallabag/ApiBundle/Entity/AccessToken.php index c09a0c80..5e4099dd 100644 --- a/src/Wallabag/ApiBundle/Entity/AccessToken.php +++ b/src/Wallabag/ApiBundle/Entity/AccessToken.php | |||
@@ -8,6 +8,22 @@ use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken; | |||
8 | /** | 8 | /** |
9 | * @ORM\Table("oauth2_access_tokens") | 9 | * @ORM\Table("oauth2_access_tokens") |
10 | * @ORM\Entity | 10 | * @ORM\Entity |
11 | * @ORM\AttributeOverrides({ | ||
12 | * @ORM\AttributeOverride(name="token", | ||
13 | * column=@ORM\Column( | ||
14 | * name = "token", | ||
15 | * type = "string", | ||
16 | * length = 191 | ||
17 | * ) | ||
18 | * ), | ||
19 | * @ORM\AttributeOverride(name="scope", | ||
20 | * column=@ORM\Column( | ||
21 | * name = "scope", | ||
22 | * type = "string", | ||
23 | * length = 191 | ||
24 | * ) | ||
25 | * ) | ||
26 | * }) | ||
11 | */ | 27 | */ |
12 | class AccessToken extends BaseAccessToken | 28 | class AccessToken extends BaseAccessToken |
13 | { | 29 | { |
diff --git a/src/Wallabag/ApiBundle/Entity/AuthCode.php b/src/Wallabag/ApiBundle/Entity/AuthCode.php index 4d4b09fe..5fa205ac 100644 --- a/src/Wallabag/ApiBundle/Entity/AuthCode.php +++ b/src/Wallabag/ApiBundle/Entity/AuthCode.php | |||
@@ -8,6 +8,22 @@ use FOS\OAuthServerBundle\Entity\AuthCode as BaseAuthCode; | |||
8 | /** | 8 | /** |
9 | * @ORM\Table("oauth2_auth_codes") | 9 | * @ORM\Table("oauth2_auth_codes") |
10 | * @ORM\Entity | 10 | * @ORM\Entity |
11 | * @ORM\AttributeOverrides({ | ||
12 | * @ORM\AttributeOverride(name="token", | ||
13 | * column=@ORM\Column( | ||
14 | * name = "token", | ||
15 | * type = "string", | ||
16 | * length = 191 | ||
17 | * ) | ||
18 | * ), | ||
19 | * @ORM\AttributeOverride(name="scope", | ||
20 | * column=@ORM\Column( | ||
21 | * name = "scope", | ||
22 | * type = "string", | ||
23 | * length = 191 | ||
24 | * ) | ||
25 | * ) | ||
26 | * }) | ||
11 | */ | 27 | */ |
12 | class AuthCode extends BaseAuthCode | 28 | class AuthCode extends BaseAuthCode |
13 | { | 29 | { |
diff --git a/src/Wallabag/ApiBundle/Entity/RefreshToken.php b/src/Wallabag/ApiBundle/Entity/RefreshToken.php index 822a02d8..dd8e9c63 100644 --- a/src/Wallabag/ApiBundle/Entity/RefreshToken.php +++ b/src/Wallabag/ApiBundle/Entity/RefreshToken.php | |||
@@ -8,6 +8,22 @@ use FOS\OAuthServerBundle\Entity\RefreshToken as BaseRefreshToken; | |||
8 | /** | 8 | /** |
9 | * @ORM\Table("oauth2_refresh_tokens") | 9 | * @ORM\Table("oauth2_refresh_tokens") |
10 | * @ORM\Entity | 10 | * @ORM\Entity |
11 | * @ORM\AttributeOverrides({ | ||
12 | * @ORM\AttributeOverride(name="token", | ||
13 | * column=@ORM\Column( | ||
14 | * name = "token", | ||
15 | * type = "string", | ||
16 | * length = 191 | ||
17 | * ) | ||
18 | * ), | ||
19 | * @ORM\AttributeOverride(name="scope", | ||
20 | * column=@ORM\Column( | ||
21 | * name = "scope", | ||
22 | * type = "string", | ||
23 | * length = 191 | ||
24 | * ) | ||
25 | * ) | ||
26 | * }) | ||
11 | */ | 27 | */ |
12 | class RefreshToken extends BaseRefreshToken | 28 | class RefreshToken extends BaseRefreshToken |
13 | { | 29 | { |
diff --git a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml index c0283e71..06e62c37 100644 --- a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml +++ b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml | |||
@@ -3,6 +3,11 @@ entry: | |||
3 | resource: "WallabagApiBundle:EntryRest" | 3 | resource: "WallabagApiBundle:EntryRest" |
4 | name_prefix: api_ | 4 | name_prefix: api_ |
5 | 5 | ||
6 | search: | ||
7 | type: rest | ||
8 | resource: "WallabagApiBundle:SearchRest" | ||
9 | name_prefix: api_ | ||
10 | |||
6 | tag: | 11 | tag: |
7 | type: rest | 12 | type: rest |
8 | resource: "WallabagApiBundle:TagRest" | 13 | resource: "WallabagApiBundle:TagRest" |