Fix 'All' section on Manga page

This commit is contained in:
Timothy Warren 2017-03-07 18:41:51 -05:00
parent 5d2dac5b99
commit 8b2cd7dd1e
3 changed files with 26 additions and 5 deletions

View File

@ -21,10 +21,14 @@ use function Amp\{all, wait};
use Amp\Artax\{Client, Request}; use Amp\Artax\{Client, Request};
use Aviat\AnimeClient\API\{ use Aviat\AnimeClient\API\{
CacheTrait, CacheTrait,
Enum\AnimeWatchingStatus\Title,
JsonAPI, JsonAPI,
Kitsu as K, Kitsu as K,
Mapping\AnimeWatchingStatus Mapping\AnimeWatchingStatus,
Mapping\MangaReadingStatus
};
use Aviat\AnimeClient\API\Enum\{
AnimeWatchingStatus\Title,
MangaReadingStatus\Kitsu as KitsuReadingStatus
}; };
use Aviat\AnimeClient\API\Kitsu\Transformer\{ use Aviat\AnimeClient\API\Kitsu\Transformer\{
AnimeTransformer, AnimeTransformer,
@ -334,7 +338,6 @@ class Model {
public function getFullOrganizedAnimeList(): array public function getFullOrganizedAnimeList(): array
{ {
$cacheItem = $this->cache->getItem(self::FULL_TRANSFORMED_LIST_CACHE_KEY); $cacheItem = $this->cache->getItem(self::FULL_TRANSFORMED_LIST_CACHE_KEY);
if ( ! $cacheItem->isHit()) if ( ! $cacheItem->isHit())
@ -402,6 +405,19 @@ class Model {
return $cacheItem->get(); return $cacheItem->get();
} }
public function getFullOrganizedMangaList(): array
{
$statuses = KitsuReadingStatus::getConstList();
$output = [];
foreach ($statuses as $status)
{
$mappedStatus = MangaReadingStatus::KITSU_TO_TITLE[$status];
$output[$mappedStatus] = $this->getMangaList($status);
}
return $output;
}
/** /**
* Get the manga list for the configured user * Get the manga list for the configured user
* *

View File

@ -84,7 +84,7 @@ class SyncKitsuWithMal extends BaseCommand {
for ($i = 0; $i < $count; $i++) for ($i = 0; $i < $count; $i++)
{ {
$offset = $i * $size; $offset = $i * $size;
$requests[] = $this->kitsuModel->getFullAnimeList($size, $offset); $requests[] = $this->kitsuModel->getPagedAnimeList($size, $offset);
} }
$promiseArray = (new Client())->requestMulti($requests); $promiseArray = (new Client())->requestMulti($requests);
@ -151,7 +151,7 @@ class SyncKitsuWithMal extends BaseCommand {
public function filterKitsuList() public function filterKitsuList()
{ {
$data = $this->getKitsuList(); $data = $this->kitsuModel->getFullAnimeList();
$includes = JsonAPI::organizeIncludes($data['included']); $includes = JsonAPI::organizeIncludes($data['included']);
$includes['mappings'] = $this->filterMappings($includes['mappings']); $includes['mappings'] = $this->filterMappings($includes['mappings']);

View File

@ -56,6 +56,11 @@ class Manga extends API
*/ */
public function getList($status) public function getList($status)
{ {
if ($status === 'All')
{
return $this->kitsuModel->getFullOrganizedMangaList();
}
$APIstatus = MangaReadingStatus::TITLE_TO_KITSU[$status]; $APIstatus = MangaReadingStatus::TITLE_TO_KITSU[$status];
$data = $this->kitsuModel->getMangaList($APIstatus); $data = $this->kitsuModel->getMangaList($APIstatus);
return $this->mapByStatus($data)[$status]; return $this->mapByStatus($data)[$status];