diff --git a/src/Controller/Api/EntryRestController.php b/src/Controller/Api/EntryRestController.php index b9fcffcd7..ca2ae0177 100644 --- a/src/Controller/Api/EntryRestController.php +++ b/src/Controller/Api/EntryRestController.php @@ -280,6 +280,18 @@ class EntryRestController extends WallabagRestController * example="example.com", * ) * ), + * @OA\Parameter( + * name="http_status", + * in="query", + * description="filter entries with matching http status code", + * required=false, + * @OA\Schema( + * type="integer", + * minimum=100, + * maximum=527, + * example="200", + * ) + * ), * @OA\Response( * response="200", * description="Returned when successful" @@ -306,6 +318,7 @@ class EntryRestController extends WallabagRestController $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'); + $httpStatus = (!\array_key_exists((int) $request->query->get('http_status'), Response::$statusTexts)) ? null : (int) $request->query->get('http_status'); try { /** @var Pagerfanta $pager */ @@ -320,7 +333,8 @@ class EntryRestController extends WallabagRestController $tags, $detail, $domainName, - $isNotParsed + $isNotParsed, + $httpStatus ); } catch (\Exception $e) { throw new BadRequestHttpException($e->getMessage()); diff --git a/src/Repository/EntryRepository.php b/src/Repository/EntryRepository.php index 521038e56..bd1a3837a 100644 --- a/src/Repository/EntryRepository.php +++ b/src/Repository/EntryRepository.php @@ -285,13 +285,14 @@ class EntryRepository extends ServiceEntityRepository * @param string $tags * @param string $detail 'metadata' or 'full'. Include content field if 'full' * @param string $domainName + * @param int $httpStatus * @param bool $isNotParsed * * @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', $domainName = '', $isNotParsed = null) + public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'asc', $since = 0, $tags = '', $detail = 'full', $domainName = '', $isNotParsed = null, $httpStatus = null) { if (!\in_array(strtolower($detail), ['full', 'metadata'], true)) { throw new \Exception('Detail "' . $detail . '" parameter is wrong, allowed: full or metadata'); @@ -350,6 +351,10 @@ class EntryRepository extends ServiceEntityRepository } } + if (\is_int($httpStatus)) { + $qb->andWhere('e.httpStatus = :httpStatus')->setParameter('httpStatus', $httpStatus); + } + if (\is_string($domainName) && '' !== $domainName) { $qb->andWhere('e.domainName = :domainName')->setParameter('domainName', $domainName); }