Fix some edge cases

This commit is contained in:
Timothy Warren 2019-04-01 16:17:40 -04:00
parent dfdc6b7356
commit 6ee198c742
3 changed files with 27 additions and 3 deletions

View File

@ -422,8 +422,14 @@ final class Model {
$item['included'] = $included; $item['included'] = $included;
} }
$transformed = $this->animeListTransformer->transformCollection($data['data']); $transformed = $this->animeListTransformer->transformCollection($data['data']);
$keyed = [];
$cacheItem->set($transformed); foreach($transformed as $item)
{
$keyed[$item['id']] = $item;
}
$cacheItem->set($keyed);
$cacheItem->save(); $cacheItem->save();
} }

View File

@ -66,7 +66,7 @@ final class Manga extends Controller {
*/ */
public function index($status = 'all', $view = ''): void public function index($status = 'all', $view = ''): void
{ {
if ( ! in_array($type, [ if ( ! in_array($status, [
'all', 'all',
'reading', 'reading',
'plan_to_read', 'plan_to_read',
@ -337,4 +337,4 @@ final class Manga extends Controller {
// @TODO: implement // @TODO: implement
} }
} }
// End of MangaController.php // End of MangaController.php

View File

@ -29,6 +29,11 @@ class API {
*/ */
protected function sortByName(array &$array, string $sortKey): void protected function sortByName(array &$array, string $sortKey): void
{ {
if (empty($array))
{
return;
}
$sort = []; $sort = [];
foreach ($array as $key => $item) foreach ($array as $key => $item)
@ -37,5 +42,18 @@ class API {
} }
array_multisort($sort, SORT_ASC, $array); array_multisort($sort, SORT_ASC, $array);
// Re-key array items by their ids
if (array_key_exists('id', $array[0]))
{
$keyed = [];
foreach($array as $item)
{
$keyed[$item['id']] = $item;
}
$array = $keyed;
}
} }
} }