Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
5 changed files with 37 additions and 7 deletions
Showing only changes of commit f7119a5b0f - Show all commits

View File

@ -1,4 +1,4 @@
<main> <main>
<h1>404</h1> <h1>404</h1>
<h2>Page Not Found</h2> <h2><?= $message ?></h2>
</main> </main>

View File

@ -196,8 +196,13 @@ class Model {
*/ */
public function getAnime(string $slug): array public function getAnime(string $slug): array
{ {
// @TODO catch non-existent anime
$baseData = $this->getRawMediaData('anime', $slug); $baseData = $this->getRawMediaData('anime', $slug);
if (empty($baseData))
{
return [];
}
$transformed = $this->animeTransformer->transform($baseData); $transformed = $this->animeTransformer->transform($baseData);
$transformed['included'] = $baseData['included']; $transformed['included'] = $baseData['included'];
return $transformed; return $transformed;
@ -657,6 +662,12 @@ class Model {
]; ];
$data = $this->getRequest($type, $options); $data = $this->getRequest($type, $options);
if (empty($data['data']))
{
return [];
}
$baseData = $data['data'][0]['attributes']; $baseData = $data['data'][0]['attributes'];
$baseData['included'] = $data['included']; $baseData['included'] = $data['included'];
return $baseData; return $baseData;

View File

@ -263,6 +263,16 @@ class Anime extends BaseController {
$data = $this->model->getAnime($animeId); $data = $this->model->getAnime($animeId);
$characters = []; $characters = [];
if (empty($data))
{
return $this->notFound(
$this->config->get('whose_list') .
"'s Anime List &middot; Anime &middot; " .
'Anime not found',
'Anime Not Found'
);
}
foreach($data['included'] as $included) foreach($data['included'] as $included)
{ {
if ($included['type'] === 'characters') if ($included['type'] === 'characters')

View File

@ -26,9 +26,14 @@ class Character extends BaseController {
$data = $model->getCharacter($slug); $data = $model->getCharacter($slug);
if ( ! array_key_exists('data', $data)) if (( ! array_key_exists('data', $data)) || empty($data['data']))
{ {
return $this->notFound(); return $this->notFound(
$this->config->get('whose_list') .
"'s Anime List &middot; Characters &middot; " .
'Character not found',
'Character Not Found'
);
} }
// $this->outputJSON($data); // $this->outputJSON($data);

View File

@ -234,10 +234,14 @@ trait ControllerTrait {
* *
* @return void * @return void
*/ */
public function notFound() public function notFound(
string $title = 'Sorry, page not found',
string $message = 'Page Not Found'
)
{ {
$this->outputHTML('404', [ $this->outputHTML('404', [
'title' => 'Sorry, page not found' 'title' => $title,
'message' => $message,
], NULL, 404); ], NULL, 404);
} }