diff options
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/WallabagRestController.php | 22 | ||||
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | 16 |
2 files changed, 37 insertions, 1 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index a0d9d4f3..6dd03c1b 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)) { |
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index 65b65290..4f16e70f 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | |||
@@ -794,6 +794,22 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
794 | $this->assertEquals(true, $content['exists']); | 794 | $this->assertEquals(true, $content['exists']); |
795 | } | 795 | } |
796 | 796 | ||
797 | public function testGetEntriesExistsWithManyUrls() | ||
798 | { | ||
799 | $url1 = 'http://0.0.0.0/entry2'; | ||
800 | $url2 = 'http://0.0.0.0/entry10'; | ||
801 | $this->client->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2); | ||
802 | |||
803 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
804 | |||
805 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
806 | |||
807 | $this->assertArrayHasKey($url1, $content); | ||
808 | $this->assertArrayHasKey($url2, $content); | ||
809 | $this->assertEquals(true, $content[$url1]); | ||
810 | $this->assertEquals(false, $content[$url2]); | ||
811 | } | ||
812 | |||
797 | public function testGetEntriesExistsWhichDoesNotExists() | 813 | public function testGetEntriesExistsWhichDoesNotExists() |
798 | { | 814 | { |
799 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); | 815 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); |