develop #37

Merged
timw4mail merged 15 commits from develop into master 2021-02-03 10:07:11 -05:00
9 changed files with 258 additions and 7 deletions
Showing only changes of commit 2b01871e5b - Show all commits

View File

@ -51,6 +51,10 @@ $routes = [
'action' => 'add', 'action' => 'add',
'verb' => 'post', 'verb' => 'post',
], ],
'anime.random' => [
'path' => '/anime/details/random',
'action' => 'random',
],
'anime.details' => [ 'anime.details' => [
'path' => '/anime/details/{id}', 'path' => '/anime/details/{id}',
'action' => 'details', 'action' => 'details',
@ -84,6 +88,10 @@ $routes = [
'action' => 'delete', 'action' => 'delete',
'verb' => 'post', 'verb' => 'post',
], ],
'manga.random' => [
'path' => '/manga/details/random',
'action' => 'random',
],
'manga.details' => [ 'manga.details' => [
'path' => '/manga/details/{id}', 'path' => '/manga/details/{id}',
'action' => 'details', 'action' => 'details',

View File

@ -256,6 +256,15 @@ final class Model {
return $this->animeTransformer->transform($baseData); return $this->animeTransformer->transform($baseData);
} }
public function getRandomAnime(): Anime
{
$baseData = $this->requestBuilder->runQuery('RandomMedia', [
'type' => 'ANIME'
]);
return $this->animeTransformer->transform($baseData);
}
/** /**
* Get information about a particular anime * Get information about a particular anime
* *
@ -392,6 +401,15 @@ final class Model {
return $this->mangaTransformer->transform($baseData); return $this->mangaTransformer->transform($baseData);
} }
public function getRandomManga(): MangaPage
{
$baseData = $this->requestBuilder->runQuery('RandomMedia', [
'type' => 'MANGA'
]);
return $this->mangaTransformer->transform($baseData);
}
/** /**
* Get information about a particular manga * Get information about a particular manga
* *

View File

@ -0,0 +1,134 @@
query ($type: MediaTypeEnum!) {
randomMedia(mediaType: $type, ageRatings: [G,PG,R]) {
id
ageRating
ageRatingGuide
posterImage {
original {
height
name
url
width
}
views {
height
name
url
width
}
}
categories(first: 100) {
nodes {
title
}
}
characters(first: 100) {
nodes {
character {
id
names {
alternatives
canonical
localized
}
image {
original {
height
name
url
width
}
}
slug
}
role
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
description
startDate
endDate
sfw
slug
mappings(first: 10) {
nodes {
externalId
externalSite
}
}
staff(first: 100) {
nodes {
person {
id
birthday
image {
original {
height
name
url
width
}
views {
height
name
url
width
}
}
names {
alternatives
canonical
localized
}
slug
}
role
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
status
titles {
alternatives
canonical
canonicalLocale
localized
}
...on Anime {
episodeCount
episodeLength
totalLength
season
streamingLinks(first: 10) {
nodes {
dubs
subs
regions
streamer {
id
siteName
}
url
}
}
subtype
totalLength
youtubeTrailerVideoId
}
...on Manga {
chapterCount
volumeCount
subtype
}
}
}

View File

@ -34,9 +34,7 @@ final class AnimeTransformer extends AbstractTransformer {
*/ */
public function transform($item): AnimePage public function transform($item): AnimePage
{ {
$base = array_key_exists('findAnimeBySlug', $item['data']) $base = $item['data']['findAnimeBySlug'] ?? $item['data']['findAnimeById'] ?? $item['data']['randomMedia'];
? $item['data']['findAnimeBySlug']
: $item['data']['findAnimeById'];
$characters = []; $characters = [];
$links = []; $links = [];
$staff = []; $staff = [];

View File

@ -34,10 +34,7 @@ final class MangaTransformer extends AbstractTransformer {
*/ */
public function transform($item): MangaPage public function transform($item): MangaPage
{ {
$base = array_key_exists('findMangaBySlug', $item['data']) $base = $item['data']['findMangaBySlug'] ?? $item['data']['findMangaById'] ?? $item['data']['randomMedia'];
? $item['data']['findMangaBySlug']
: $item['data']['findMangaById'];
$characters = []; $characters = [];
$links = []; $links = [];
$staff = []; $staff = [];

View File

@ -348,5 +348,43 @@ final class Anime extends BaseController {
); );
} }
} }
public function random()
{
try
{
$data = $this->model->getRandomAnime();
if ($data->isEmpty())
{
$this->notFound(
$this->config->get('whose_list') .
"'s Anime List · Anime · " .
'Anime not found',
'Anime Not Found'
);
return;
}
$this->outputHTML('anime/details', [
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Anime',
$data->title
),
'data' => $data,
]);
}
catch (TypeError $e)
{
$this->notFound(
$this->config->get('whose_list') .
"'s Anime List · Anime · " .
'Anime not found',
'Anime Not Found'
);
}
}
} }
// End of AnimeController.php // End of AnimeController.php

View File

@ -338,5 +338,43 @@ final class Manga extends Controller {
'staff' => $staff, 'staff' => $staff,
]); ]);
} }
/**
* View details of a random manga
*
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @throws Throwable
* @return void
*/
public function random(): void
{
$data = $this->model->getRandomManga();
$staff = [];
$characters = [];
if ($data->isEmpty())
{
$this->notFound(
$this->config->get('whose_list') .
"'s Manga List · Manga · " .
'Manga not found',
'Manga Not Found'
);
return;
}
$this->outputHTML('manga/details', [
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Manga List",
'Manga',
$data['title']
),
'characters' => $characters,
'data' => $data,
'staff' => $staff,
]);
}
} }
// End of MangaController.php // End of MangaController.php

View File

@ -83,6 +83,16 @@ class Anime extends API {
return $this->kitsuModel->getAnime($slug); return $this->kitsuModel->getAnime($slug);
} }
/**
* Get information about a random anime
*
* @return AnimeType
*/
public function getRandomAnime(): AnimeType
{
return $this->kitsuModel->getRandomAnime();
}
/** /**
* Get anime by its kitsu id * Get anime by its kitsu id
* *

View File

@ -68,6 +68,16 @@ class Manga extends API {
return $this->kitsuModel->getManga($manga_id); return $this->kitsuModel->getManga($manga_id);
} }
/**
* Get the details of a random manga
*
* @return MangaPage
*/
public function getRandomManga(): MangaPage
{
return $this->kitsuModel->getRandomManga();
}
/** /**
* Get anime by its kitsu id * Get anime by its kitsu id
* *