Add domain_name to entries api endpoint

This commit is contained in:
Yotam Nachum 2022-10-16 18:35:23 +03:00
parent e67e557721
commit f994ab8b5d
2 changed files with 10 additions and 2 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');
}