]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ApiBundle/Controller/WallabagRestController.php
Ability to check multiple urls in API
[github/wallabag/wallabag.git] / src / Wallabag / ApiBundle / Controller / WallabagRestController.php
index a0d9d4f3a144336735468ad3fd4f04b67eda8087..6dd03c1b6495564371cb96673b3efd3e311d71e5 100644 (file)
@@ -27,7 +27,8 @@ class WallabagRestController extends FOSRestController
      *
      * @ApiDoc(
      *       parameters={
-     *          {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}
+     *          {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"},
+     *          {"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"}
      *       }
      * )
      *
@@ -37,6 +38,25 @@ class WallabagRestController extends FOSRestController
     {
         $this->validateAuthentication();
 
+        $urls = $request->query->get('urls', []);
+
+        // handle multiple urls first
+        if (!empty($urls)) {
+            $results = [];
+            foreach ($urls as $url) {
+                $res = $this->getDoctrine()
+                    ->getRepository('WallabagCoreBundle:Entry')
+                    ->findByUrlAndUserId($url, $this->getUser()->getId());
+
+                $results[$url] = false === $res ? false : true;
+            }
+
+            $json = $this->get('serializer')->serialize($results, 'json');
+
+            return (new JsonResponse())->setJson($json);
+        }
+
+        // let's see if it is a simple url?
         $url = $request->query->get('url', '');
 
         if (empty($url)) {