mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 19:11:07 +00:00
Add an exists endpoint in API
It should allow third party to check if an url was already saved by a user
This commit is contained in:
parent
c4bf7af96f
commit
6273fefd5d
2 changed files with 43 additions and 0 deletions
|
@ -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.
|
* Retrieve all entries. It could be filtered by many options.
|
||||||
*
|
*
|
||||||
|
|
|
@ -684,4 +684,15 @@ class WallabagRestControllerTest extends WallabagApiTestCase
|
||||||
|
|
||||||
$this->assertEquals(true, $content['is_starred']);
|
$this->assertEquals(true, $content['is_starred']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetEntriesExists()
|
||||||
|
{
|
||||||
|
$this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
|
||||||
|
|
||||||
|
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
||||||
|
|
||||||
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
||||||
|
|
||||||
|
$this->assertEquals(true, $content['exists']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue