From f994ab8b5db794259c23710eb8e1875465c1beb6 Mon Sep 17 00:00:00 2001 From: Yotam Nachum Date: Sun, 16 Oct 2022 18:35:23 +0300 Subject: [PATCH 1/3] Add domain_name to entries api endpoint --- src/Wallabag/ApiBundle/Controller/EntryRestController.php | 5 ++++- src/Wallabag/CoreBundle/Repository/EntryRepository.php | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 08e6d6483..9b6aa1b9d 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php @@ -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()); diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 819579bf4..8bb48a889 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -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'); } From 7b150dcd266dbe9e2732737d7a60d3500e4044ef Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 17 Oct 2022 21:37:08 +0200 Subject: [PATCH 2/3] Add tests --- .../Controller/EntryRestControllerTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index c058c52f7..c18ea30ab 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -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', [ From d4b0b62bb597a0788ead4febc30ebd1e7d3f8ba5 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 17 Oct 2022 21:49:03 +0200 Subject: [PATCH 3/3] Fix unrelated failing test LExpansion is down ATM. Use a website which isn't down randomly. --- .../ImportBundle/Controller/FirefoxControllerTest.php | 8 ++++---- .../Wallabag/ImportBundle/fixtures/firefox-bookmarks.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 353618103..b8d201e41 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -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() diff --git a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json index 9bc922a6d..2491ea978 100644 --- a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json +++ b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json @@ -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",