mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Feed- and category-specific entry list routes
This commit is contained in:
parent
00ad1cc5b9
commit
a7d05a7717
2 changed files with 39 additions and 9 deletions
|
@ -1003,19 +1003,14 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getEntries(array $query): ResponseInterface {
|
protected function listEntries(array $query, Context $c): array {
|
||||||
$c = $this->computeContext($query);
|
$c = $this->computeContext($query, $c);
|
||||||
$order = $this->computeOrder($query);
|
$order = $this->computeOrder($query);
|
||||||
$tr = Arsse::$db->begin();
|
$tr = Arsse::$db->begin();
|
||||||
$meta = $this->userMeta(Arsse::$user->id);
|
$meta = $this->userMeta(Arsse::$user->id);
|
||||||
// compile the list of entries
|
// 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 = [];
|
$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']);
|
$out[] = $this->transformEntry($entry, $meta['num'], $meta['tz']);
|
||||||
}
|
}
|
||||||
// next compile a map of feeds to add to the entries
|
// 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)) {
|
if ($c->offset || ($c->limit && $count >= $c->limit)) {
|
||||||
$count = Arsse::$db->articleCount(Arsse::$user->id, (clone $c)->limit(0)->offset(0));
|
$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 {
|
public static function tokenGenerate(string $user, string $label): string {
|
||||||
|
|
|
@ -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=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?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")],
|
["/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)],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue