From f994ab8b5db794259c23710eb8e1875465c1beb6 Mon Sep 17 00:00:00 2001 From: Yotam Nachum Date: Sun, 16 Oct 2022 18:35:23 +0300 Subject: [PATCH] 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'); }