1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-07-17 17:08:37 +00:00

Merge pull request #2325 from wallabag/api-entries-exists

Add an exists endpoint in API
This commit is contained in:
Nicolas Lœuillet 2016-10-02 13:17:23 +02:00 committed by GitHub
commit 18b8dc0e99
2 changed files with 54 additions and 0 deletions

View file

@ -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.
*