From 6273fefd5d945de1d871815a652f5a716e12e820 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Oct 2016 17:15:28 +0200 Subject: Add an exists endpoint in API It should allow third party to check if an url was already saved by a user --- .../Controller/WallabagRestController.php | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/Wallabag/ApiBundle') diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index dd17ef97..b83e4266 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -22,6 +22,38 @@ class WallabagRestController extends FOSRestController } } + /** + * Check if an entry exist by url + * + * @ApiDoc( + * parameters={ + * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"} + * } + * ) + * + * @return JsonResponse + */ + public function getEntriesExistsAction(Request $request) + { + $this->validateAuthentication(); + + $url = $request->query->get('url', ''); + + if (empty($url)) { + throw $this->createAccessDeniedException('URL is empty?, logged user id: '.$user->getId()); + } + + $res = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($url, $this->getUser()->getId()); + + $exists = false === $res ? false : true; + + $json = $this->get('serializer')->serialize(['exists' => $exists], 'json'); + + return (new JsonResponse())->setJson($json); + } + /** * Retrieve all entries. It could be filtered by many options. * -- cgit v1.2.3