mirror of
https://github.com/wallabag/wallabag.git
synced 2025-10-20 19:52:09 +00:00
Merge pull request #3960 from wallabag/api-entries-2817
api/entries: add parameter detail to exclude or include content in response
This commit is contained in:
commit
a2b5d67560
3 changed files with 42 additions and 2 deletions
|
@ -139,15 +139,30 @@ class EntryRepository extends EntityRepository
|
|||
* @param string $order
|
||||
* @param int $since
|
||||
* @param string $tags
|
||||
* @param string $detail 'metadata' or 'full'. Include content field if 'full'
|
||||
*
|
||||
* @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 = '')
|
||||
public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'asc', $since = 0, $tags = '', $detail = 'full')
|
||||
{
|
||||
if (!\in_array(strtolower($detail), ['full', 'metadata'], true)) {
|
||||
throw new \Exception('Detail "' . $detail . '" parameter is wrong, allowed: full or metadata');
|
||||
}
|
||||
|
||||
$qb = $this->createQueryBuilder('e')
|
||||
->leftJoin('e.tags', 't')
|
||||
->where('e.user = :userId')->setParameter('userId', $userId);
|
||||
|
||||
if ('metadata' === $detail) {
|
||||
$fieldNames = $this->getClassMetadata()->getFieldNames();
|
||||
$fields = array_filter($fieldNames, function ($k) {
|
||||
return 'content' !== $k;
|
||||
});
|
||||
$qb->select(sprintf('partial e.{%s}', implode(',', $fields)));
|
||||
}
|
||||
|
||||
if (null !== $isArchived) {
|
||||
$qb->andWhere('e.isArchived = :isArchived')->setParameter('isArchived', (bool) $isArchived);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue