Merge pull request #6019 from yotamN/feature/domain-name-filter

Add `domain_name` to entries api endpoint
This commit is contained in:
Jérémy Benoist 2022-10-17 21:54:05 +02:00 committed by GitHub
commit 3340262707
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 8 deletions

View file

@ -113,6 +113,7 @@ class EntryRestController extends WallabagRestController
* {"name"="since", "dataType"="integer", "required"=false, "format"="default '0'", "description"="The timestamp since when you want entries updated."},
* {"name"="public", "dataType"="integer", "required"=false, "format"="1 or 0, all entries by default", "description"="filter by entries with a public link"},
* {"name"="detail", "dataType"="string", "required"=false, "format"="metadata or full, metadata by default", "description"="include content field if 'full'. 'full' by default for backward compatibility."},
* {"name"="domain_name", "dataType"="string", "required"=false, "format"="example.com", "description"="filter entries with the given domain name"},
* }
* )
*
@ -132,6 +133,7 @@ class EntryRestController extends WallabagRestController
$tags = \is_array($request->query->get('tags')) ? '' : (string) $request->query->get('tags', '');
$since = $request->query->get('since', 0);
$detail = strtolower($request->query->get('detail', 'full'));
$domainName = (null === $request->query->get('domain_name')) ? '' : (string) $request->query->get('domain_name');
try {
/** @var \Pagerfanta\Pagerfanta $pager */
@ -144,7 +146,8 @@ class EntryRestController extends WallabagRestController
$order,
$since,
$tags,
$detail
$detail,
$domainName
);
} catch (\Exception $e) {
throw new BadRequestHttpException($e->getMessage());

View file

@ -198,12 +198,13 @@ class EntryRepository extends EntityRepository
* @param int $since
* @param string $tags
* @param string $detail 'metadata' or 'full'. Include content field if 'full'
* @param string $domainName
*
* @todo Breaking change: replace default detail=full by detail=metadata in a future version
*
* @return Pagerfanta
*/
public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'asc', $since = 0, $tags = '', $detail = 'full')
public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'asc', $since = 0, $tags = '', $detail = 'full', $domainName = '')
{
if (!\in_array(strtolower($detail), ['full', 'metadata'], true)) {
throw new \Exception('Detail "' . $detail . '" parameter is wrong, allowed: full or metadata');
@ -258,6 +259,10 @@ class EntryRepository extends EntityRepository
}
}
if (\is_string($domainName) && '' !== $domainName) {
$qb->andWhere('e.domainName = :domainName')->setParameter('domainName', $domainName);
}
if (!\in_array(strtolower($order), ['asc', 'desc'], true)) {
throw new \Exception('Order "' . $order . '" parameter is wrong, allowed: asc or desc');
}

View file

@ -157,6 +157,25 @@ class EntryRestControllerTest extends WallabagApiTestCase
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
}
public function testGetEntriesByDomainName()
{
$this->client->request('GET', '/api/entries?domain_name=domain.io');
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertGreaterThanOrEqual(1, \count($content));
$this->assertNotEmpty($content['_embedded']['items']);
$this->assertGreaterThanOrEqual(1, $content['total']);
$this->assertSame(1, $content['page']);
$this->assertGreaterThanOrEqual(1, $content['pages']);
$this->assertSame('test title entry6', $content['_embedded']['items'][0]['title']);
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
}
public function testGetEntriesWithFullOptions()
{
$this->client->request('GET', '/api/entries', [

View file

@ -114,14 +114,14 @@ class FirefoxControllerTest extends WallabagCoreTestCase
->get('doctrine.orm.entity_manager')
->getRepository('WallabagCoreBundle:Entry')
->findByUrlAndUserId(
'https://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html',
'https://www.20minutes.fr/sport/4002755-20220928-tarn-lapins-ravagent-terrain-match-rugby-doit-etre-annule',
$this->getLoggedInUserId()
);
$this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
$this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://lexpansion.lexpress.fr is ok');
$this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://lexpansion.lexpress.fr is ok');
$this->assertNotEmpty($content->getLanguage(), 'Language for http://lexpansion.lexpress.fr is ok');
$this->assertNotEmpty($content->getMimetype(), 'Mimetype for https://www.20minutes.fr is ok');
$this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.20minutes.fr is ok');
$this->assertNotEmpty($content->getLanguage(), 'Language for https://www.20minutes.fr is ok');
$this->assertCount(3, $content->getTags());
$content = $client->getContainer()

View file

@ -28,14 +28,14 @@
"children": [
{
"guid": "tard77lzbC5H",
"title": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion",
"title": "Tarn : Des lapins ravagent le terrain, le match de rugby doit être annulé",
"index": 1,
"dateAdded": 1388166091644000,
"lastModified": 1388166091644000,
"tags": "test,tag",
"id": 4,
"type": "text/x-moz-place",
"uri": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html"
"uri": "https://www.20minutes.fr/sport/4002755-20220928-tarn-lapins-ravagent-terrain-match-rugby-doit-etre-annule"
},
{
"guid": "E385l9vZ_LVn",