aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-10-08 13:31:31 +0200
committerGitHub <noreply@github.com>2016-10-08 13:31:31 +0200
commit4ad6f5878a7e7ab6359151b049fb49b9dd2c78ec (patch)
treefec55d3ed2c34c71ba6dbe6bc01f47773ef095f8 /src/Wallabag/ApiBundle/Controller/WallabagRestController.php
parente07c25a1adb2f89c5f57656e24a054ddd3a45df7 (diff)
parentf0abc22d09d2e38d3dd408425821a89da3d21377 (diff)
downloadwallabag-4ad6f5878a7e7ab6359151b049fb49b9dd2c78ec.tar.gz
wallabag-4ad6f5878a7e7ab6359151b049fb49b9dd2c78ec.tar.zst
wallabag-4ad6f5878a7e7ab6359151b049fb49b9dd2c78ec.zip
Merge pull request #2393 from wallabag/api-urls-exist
Ability to check multiple urls in API
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/WallabagRestController.php')
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index cc6923a0..ed31c536 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -27,7 +27,8 @@ class WallabagRestController extends FOSRestController
27 * 27 *
28 * @ApiDoc( 28 * @ApiDoc(
29 * parameters={ 29 * parameters={
30 * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"} 30 * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"},
31 * {"name"="urls", "dataType"="string", "required"=false, "format"="An array of urls (?urls[]=http...&urls[]=http...)", "description"="Urls (as an array) to check if it exists"}
31 * } 32 * }
32 * ) 33 * )
33 * 34 *
@@ -37,6 +38,25 @@ class WallabagRestController extends FOSRestController
37 { 38 {
38 $this->validateAuthentication(); 39 $this->validateAuthentication();
39 40
41 $urls = $request->query->get('urls', []);
42
43 // handle multiple urls first
44 if (!empty($urls)) {
45 $results = [];
46 foreach ($urls as $url) {
47 $res = $this->getDoctrine()
48 ->getRepository('WallabagCoreBundle:Entry')
49 ->findByUrlAndUserId($url, $this->getUser()->getId());
50
51 $results[$url] = false === $res ? false : true;
52 }
53
54 $json = $this->get('serializer')->serialize($results, 'json');
55
56 return (new JsonResponse())->setJson($json);
57 }
58
59 // let's see if it is a simple url?
40 $url = $request->query->get('url', ''); 60 $url = $request->query->get('url', '');
41 61
42 if (empty($url)) { 62 if (empty($url)) {