diff --git a/lib/REST/Miniflux/V1.php b/lib/REST/Miniflux/V1.php index 2d427680..be093d48 100644 --- a/lib/REST/Miniflux/V1.php +++ b/lib/REST/Miniflux/V1.php @@ -1003,19 +1003,14 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { ]; } - protected function getEntries(array $query): ResponseInterface { - $c = $this->computeContext($query); + protected function listEntries(array $query, Context $c): array { + $c = $this->computeContext($query, $c); $order = $this->computeOrder($query); $tr = Arsse::$db->begin(); $meta = $this->userMeta(Arsse::$user->id); // compile the list of entries - try { - $entries = Arsse::$db->articleList(Arsse::$user->id, $c, self::ARTICLE_COLUMNS, $order); - } catch (ExceptionInput $e) { - return new ErrorResponse("MissingCategory", 400); - } $out = []; - foreach ($entries as $entry) { + foreach (Arsse::$db->articleList(Arsse::$user->id, $c, self::ARTICLE_COLUMNS, $order) as $entry) { $out[] = $this->transformEntry($entry, $meta['num'], $meta['tz']); } // next compile a map of feeds to add to the entries @@ -1035,7 +1030,34 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler { if ($c->offset || ($c->limit && $count >= $c->limit)) { $count = Arsse::$db->articleCount(Arsse::$user->id, (clone $c)->limit(0)->offset(0)); } - return new Response(['total' => $count, 'entries' => $out]); + return ['total' => $count, 'entries' => $out]; + } + + protected function getEntries(array $query): ResponseInterface { + try { + return new Response($this->listEntries($query, new Context)); + } catch (ExceptionInput $e) { + return new ErrorResponse("MissingCategory", 400); + } + } + + protected function getFeedEntries(array $path, array $query): ResponseInterface { + $c = (new Context)->subscription((int) $path[1]); + try { + return new Response($this->listEntries($query, $c)); + } catch (ExceptionInput $e) { + // FIXME: this should differentiate between a missing feed and a missing category, but doesn't + return new ErrorResponse("404", 404); + } + } + + protected function getCategoryEntries(array $path, array $query): ResponseInterface { + $query['category_id'] = (int) $path[1]; + try { + return new Response($this->listEntries($query, new Context)); + } catch (ExceptionInput $e) { + return new ErrorResponse("404", 404); + } } public static function tokenGenerate(string $user, string $label): string { diff --git a/tests/cases/REST/Miniflux/TestV1.php b/tests/cases/REST/Miniflux/TestV1.php index 392a2781..02387dc1 100644 --- a/tests/cases/REST/Miniflux/TestV1.php +++ b/tests/cases/REST/Miniflux/TestV1.php @@ -798,6 +798,14 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest { ["/entries?order=category_title&direction=desc", $c, ["top_folder_name desc"], self::ENTRIES, false, new Response(['total' => sizeof(self::ENTRIES_OUT), 'entries' => self::ENTRIES_OUT])], ["/entries?order=status&direction=desc", $c, ["hidden desc", "unread"], self::ENTRIES, false, new Response(['total' => sizeof(self::ENTRIES_OUT), 'entries' => self::ENTRIES_OUT])], ["/entries?category_id=2112", (clone $c)->folder(2111), $o, new ExceptionInput("idMissing"), false, new ErrorResponse("MissingCategory")], + ["/feeds/42/entries", (clone $c)->subscription(42), $o, self::ENTRIES, false, new Response(['total' => sizeof(self::ENTRIES_OUT), 'entries' => self::ENTRIES_OUT])], + ["/feeds/42/entries?category_id=47", (clone $c)->subscription(42)->folder(46), $o, self::ENTRIES, false, new Response(['total' => sizeof(self::ENTRIES_OUT), 'entries' => self::ENTRIES_OUT])], + ["/feeds/2112/entries", (clone $c)->subscription(2112), $o, new ExceptionInput("idMissing"), false, new ErrorResponse("404", 404)], + ["/categories/42/entries", (clone $c)->folder(41), $o, self::ENTRIES, false, new Response(['total' => sizeof(self::ENTRIES_OUT), 'entries' => self::ENTRIES_OUT])], + ["/categories/42/entries?category_id=47", (clone $c)->folder(41), $o, self::ENTRIES, false, new Response(['total' => sizeof(self::ENTRIES_OUT), 'entries' => self::ENTRIES_OUT])], + ["/categories/42/entries?starred", (clone $c)->folder(41)->starred(true), $o, self::ENTRIES, false, new Response(['total' => sizeof(self::ENTRIES_OUT), 'entries' => self::ENTRIES_OUT])], + ["/categories/1/entries", (clone $c)->folderShallow(0), $o, self::ENTRIES, false, new Response(['total' => sizeof(self::ENTRIES_OUT), 'entries' => self::ENTRIES_OUT])], + ["/categories/2112/entries", (clone $c)->folder(2111), $o, new ExceptionInput("idMissing"), false, new ErrorResponse("404", 404)], ]; } }