mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
remove backwards compatibility
This commit is contained in:
parent
fb3197cddf
commit
16120f1528
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,8 +1,9 @@
|
||||
/vendor
|
||||
/vendor.v4
|
||||
/.idea
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
.env
|
||||
.env.v4
|
||||
composer.phar
|
||||
composer.lock
|
||||
.php_cs.cache
|
@ -1,215 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
use Jikan\Request\Anime\AnimeCharactersAndStaffRequest;
|
||||
use Jikan\Request\Anime\AnimeEpisodesRequest;
|
||||
use Jikan\Request\Anime\AnimeForumRequest;
|
||||
use Jikan\Request\Anime\AnimeMoreInfoRequest;
|
||||
use Jikan\Request\Anime\AnimeNewsRequest;
|
||||
use Jikan\Request\Anime\AnimePicturesRequest;
|
||||
use Jikan\Request\Anime\AnimeRequest;
|
||||
use Jikan\Request\Anime\AnimeStatsRequest;
|
||||
use Jikan\Request\Anime\AnimeVideosRequest;
|
||||
|
||||
class AnimeController extends Controller
|
||||
{
|
||||
public function _main($id)
|
||||
{
|
||||
$anime = $this->jikan->getAnime(new AnimeRequest($id));
|
||||
|
||||
// backwards compatibility
|
||||
$anime = json_decode(
|
||||
$this->serializer->serialize($anime, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
$anime['aired_string'] = $anime['aired']['string'];
|
||||
unset($anime['aired']['string']);
|
||||
$anime['title_synonyms'] = empty($anime['title_synonyms']) ? null : implode(",", $anime['title_synonyms']);
|
||||
;
|
||||
|
||||
return $anime;
|
||||
}
|
||||
|
||||
public function main(int $id)
|
||||
{
|
||||
$anime = $this->_main($id);
|
||||
|
||||
return response(
|
||||
json_encode($anime)
|
||||
);
|
||||
}
|
||||
|
||||
public function characters_staff(int $id)
|
||||
{
|
||||
$anime = $this->_main($id);
|
||||
$charactersStaff = $this->jikan->getAnimeCharactersAndStaff(new AnimeCharactersAndStaffRequest($id));
|
||||
$charactersStaff = json_decode(
|
||||
$this->serializer->serialize($charactersStaff, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($charactersStaff['staff'] as &$staff) {
|
||||
$staff['positions'] = empty($staff['positions']) ? null : implode(",", $staff['positions']);
|
||||
$staff['role'] = $staff['positions'];
|
||||
unset($staff['positions']);
|
||||
}
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$anime,
|
||||
$charactersStaff
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function episodes(int $id, int $page = 1)
|
||||
{
|
||||
$anime = $this->_main($id);
|
||||
$episodes = $this->jikan->getAnimeEpisodes(new AnimeEpisodesRequest($id, $page));
|
||||
$episodes = json_decode(
|
||||
$this->serializer->serialize($episodes, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($episodes['episode'] as &$episode) {
|
||||
$episode['aired'] = $episode['aired']['string'];
|
||||
}
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$anime,
|
||||
$episodes
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function news(int $id)
|
||||
{
|
||||
$anime = $this->_main($id);
|
||||
$news = ['news' => $this->jikan->getNewsList(new AnimeNewsRequest($id))];
|
||||
$news = json_decode(
|
||||
$this->serializer->serialize($news, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$anime,
|
||||
$news
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function forum(int $id)
|
||||
{
|
||||
$anime = $this->_main($id);
|
||||
$forum = ['topic' => $this->jikan->getAnimeForum(new AnimeForumRequest($id))];
|
||||
$forum = json_decode(
|
||||
$this->serializer->serialize($forum, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$anime,
|
||||
$forum
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function videos(int $id)
|
||||
{
|
||||
$anime = $this->_main($id);
|
||||
$videos = $this->jikan->getAnimeVideos(new AnimeVideosRequest($id));
|
||||
$videos = json_decode(
|
||||
$this->serializer->serialize($videos, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$anime,
|
||||
$videos
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function pictures(int $id)
|
||||
{
|
||||
$anime = $this->_main($id);
|
||||
$pictures = ['image' =>$this->jikan->getAnimePictures(new AnimePicturesRequest($id))];
|
||||
$pictures = json_decode(
|
||||
$this->serializer->serialize($pictures, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($pictures['image'] as $key => $value) {
|
||||
$pictures['image'][$key] = $value['small'];
|
||||
}
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$anime,
|
||||
$pictures
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function stats(int $id)
|
||||
{
|
||||
$anime = $this->_main($id);
|
||||
$stats = $this->jikan->getAnimeStats(new AnimeStatsRequest($id));
|
||||
$stats = json_decode(
|
||||
$this->serializer->serialize($stats, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$anime,
|
||||
$stats
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function moreInfo(int $id)
|
||||
{
|
||||
$anime = $this->_main($id);
|
||||
$moreinfo = ['moreinfo' => $this->jikan->getAnimeMoreInfo(new AnimeMoreInfoRequest($id))];
|
||||
$moreinfo = json_decode(
|
||||
$this->serializer->serialize($moreinfo, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$anime,
|
||||
$moreinfo
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
use Jikan\Request\Character\CharacterRequest;
|
||||
use Jikan\Request\Character\CharacterPicturesRequest;
|
||||
|
||||
class CharacterController extends Controller
|
||||
{
|
||||
public function _main($id)
|
||||
{
|
||||
$character = $this->jikan->getCharacter(new CharacterRequest($id));
|
||||
|
||||
// backwards compatibility
|
||||
$character = json_decode(
|
||||
$this->serializer->serialize($character, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
$character['nicknames'] = empty($character['nicknames']) ? null : implode(",", $character['nicknames']);
|
||||
;
|
||||
|
||||
return $character;
|
||||
}
|
||||
|
||||
public function main(int $id)
|
||||
{
|
||||
$character = $this->_main($id);
|
||||
|
||||
return response(
|
||||
json_encode($character)
|
||||
);
|
||||
}
|
||||
|
||||
public function pictures(int $id)
|
||||
{
|
||||
$character = $this->_main($id);
|
||||
$pictures = ['image' =>$this->jikan->getCharacterPictures(new CharacterPicturesRequest($id))];
|
||||
$pictures = json_decode(
|
||||
$this->serializer->serialize($pictures, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($pictures['image'] as $key => $value) {
|
||||
$pictures['image'][$key] = $value['small'];
|
||||
}
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$character,
|
||||
$pictures
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
;
|
||||
|
||||
use App\Providers\SerializerFactory;
|
||||
use App\Providers\SerializerServiceProdivder;
|
||||
use App\Providers\SerializerServiceProviderV3;
|
||||
use Jikan\Jikan;
|
||||
use Jikan\MyAnimeList\MalClient;
|
||||
use JMS\Serializer\Serializer;
|
||||
use Laravel\Lumen\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
/**
|
||||
* @var Serializer
|
||||
*/
|
||||
protected $serializer;
|
||||
|
||||
/**
|
||||
* @var MalClient
|
||||
*/
|
||||
protected $jikan;
|
||||
|
||||
/**
|
||||
* AnimeController constructor.
|
||||
*
|
||||
* @param Serializer $serializer
|
||||
* @param MalClient $jikan
|
||||
*/
|
||||
public function __construct(MalClient $jikan)
|
||||
{
|
||||
$this->serializer = SerializerFactory::createV2();
|
||||
$this->jikan = $jikan;
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
class ExampleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
}
|
@ -1,162 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
use Jikan\Request\Manga\MangaCharactersRequest;
|
||||
use Jikan\Request\Manga\MangaForumRequest;
|
||||
use Jikan\Request\Manga\MangaMoreInfoRequest;
|
||||
use Jikan\Request\Manga\MangaNewsRequest;
|
||||
use Jikan\Request\Manga\MangaPicturesRequest;
|
||||
use Jikan\Request\Manga\MangaRequest;
|
||||
use Jikan\Request\Manga\MangaStatsRequest;
|
||||
|
||||
class MangaController extends Controller
|
||||
{
|
||||
public function _main($id)
|
||||
{
|
||||
$manga = $this->jikan->getManga(new MangaRequest($id));
|
||||
|
||||
// backwards compatibility
|
||||
$manga = json_decode(
|
||||
$this->serializer->serialize($manga, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
$manga['published_string'] = $manga['published']['string'];
|
||||
unset($manga['published']['string']);
|
||||
$manga['title_synonyms'] = empty($manga['title_synonyms']) ? null : implode(",", $manga['title_synonyms']);
|
||||
;
|
||||
|
||||
return $manga;
|
||||
}
|
||||
|
||||
public function main(int $id)
|
||||
{
|
||||
$manga = $this->_main($id);
|
||||
|
||||
return response(
|
||||
json_encode($manga)
|
||||
);
|
||||
}
|
||||
|
||||
public function characters(int $id)
|
||||
{
|
||||
$manga = $this->_main($id);
|
||||
$characters = ['character' => $this->jikan->getMangaCharacters(new MangaCharactersRequest($id))];
|
||||
$characters = json_decode(
|
||||
$this->serializer->serialize($characters, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$manga,
|
||||
$characters
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function news(int $id)
|
||||
{
|
||||
$manga = $this->_main($id);
|
||||
$news = ['news' => $this->jikan->getNewsList(new MangaNewsRequest($id))];
|
||||
$news = json_decode(
|
||||
$this->serializer->serialize($news, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$manga,
|
||||
$news
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function forum(int $id)
|
||||
{
|
||||
$manga = $this->_main($id);
|
||||
$forum = ['topic' => $this->jikan->getMangaForum(new MangaForumRequest($id))];
|
||||
$forum = json_decode(
|
||||
$this->serializer->serialize($forum, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$manga,
|
||||
$forum
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function pictures(int $id)
|
||||
{
|
||||
$manga = $this->_main($id);
|
||||
$pictures = ['image' =>$this->jikan->getMangaPictures(new MangaPicturesRequest($id))];
|
||||
$pictures = json_decode(
|
||||
$this->serializer->serialize($pictures, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($pictures['image'] as $key => $value) {
|
||||
$pictures['image'][$key] = $value['small'];
|
||||
}
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$manga,
|
||||
$pictures
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function stats(int $id)
|
||||
{
|
||||
$manga = $this->_main($id);
|
||||
$stats = $this->jikan->getMangaStats(new MangaStatsRequest($id));
|
||||
$stats = json_decode(
|
||||
$this->serializer->serialize($stats, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$manga,
|
||||
$stats
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function moreInfo(int $id)
|
||||
{
|
||||
$manga = $this->_main($id);
|
||||
$moreinfo = ['moreinfo' => $this->jikan->getMangaMoreInfo(new MangaMoreInfoRequest($id))];
|
||||
$moreinfo = json_decode(
|
||||
$this->serializer->serialize($moreinfo, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$manga,
|
||||
$moreinfo
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
class MetaController extends Controller
|
||||
{
|
||||
public function status()
|
||||
{
|
||||
$info = app('redis')->info();
|
||||
|
||||
return response()->json([
|
||||
'cached_requests' => count(app('redis')->keys('request:*')),
|
||||
'requests_today' => count(app('redis')->keys('requests:today:*')),
|
||||
'requests_this_week' => count(app('redis')->keys('requests:weekly:*')),
|
||||
'requests_this_month' => count(app('redis')->keys('requests:monthly:*')),
|
||||
'connected_clients' => $info['Clients']['connected_clients'],
|
||||
'total_connections_received' => $info['Stats']['total_connections_received'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function requests($type, $period, $offset = 0)
|
||||
{
|
||||
if (!\in_array($type, [
|
||||
'anime', 'manga', 'character', 'person', 'people', 'search', 'top', 'season', 'schedule', 'user', 'producer', 'magazine', 'genre'
|
||||
])) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (!\in_array($period, ['today', 'weekly', 'monthly'])) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$requests = [];
|
||||
$data = app('redis')->keys("requests:{$period}:*{$type}*");
|
||||
|
||||
foreach ($data as $key) {
|
||||
$requests[explode(":", $key)[2]] = (int) app('redis')->get($key);
|
||||
}
|
||||
|
||||
arsort($requests);
|
||||
|
||||
return response()->json(
|
||||
\array_slice($requests, $offset, 1000)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
use Jikan\Request\Person\PersonRequest;
|
||||
use Jikan\Request\Person\PersonPicturesRequest;
|
||||
|
||||
class PersonController extends Controller
|
||||
{
|
||||
public function _main($id)
|
||||
{
|
||||
$person = $this->jikan->getPerson(new PersonRequest($id));
|
||||
|
||||
// backwards compatibility
|
||||
$person = json_decode(
|
||||
$this->serializer->serialize($person, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
public function main(int $id)
|
||||
{
|
||||
$person = $this->_main($id);
|
||||
|
||||
return response(
|
||||
json_encode($person)
|
||||
);
|
||||
}
|
||||
|
||||
public function pictures(int $id)
|
||||
{
|
||||
$person = $this->_main($id);
|
||||
$pictures = ['image' =>$this->jikan->getPersonPictures(new PersonPicturesRequest($id))];
|
||||
$pictures = json_decode(
|
||||
$this->serializer->serialize($pictures, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($pictures['image'] as $key => $value) {
|
||||
$pictures['image'][$key] = $value['small'];
|
||||
}
|
||||
|
||||
|
||||
return response(
|
||||
json_encode(
|
||||
array_merge(
|
||||
$person,
|
||||
$pictures
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
use Jikan\Request\Schedule\ScheduleRequest;
|
||||
use Jikan\Request\Seasonal\SeasonalRequest;
|
||||
|
||||
class ScheduleController extends Controller
|
||||
{
|
||||
private const VALID_DAYS = [
|
||||
'monday',
|
||||
'tuesday',
|
||||
'wednesday',
|
||||
'thursday',
|
||||
'friday',
|
||||
'saturday',
|
||||
'sunday',
|
||||
'other',
|
||||
'unknown'
|
||||
];
|
||||
|
||||
public function main(?string $day = null)
|
||||
{
|
||||
if (!is_null($day) && !\in_array(strtolower($day), self::VALID_DAYS)) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
$schedule = $this->jikan->getSchedule(new ScheduleRequest());
|
||||
|
||||
if (!is_null($day)) {
|
||||
$day = strtolower($day);
|
||||
$schedule = [$day => $schedule->{'get' . ucfirst($day)}()];
|
||||
}
|
||||
|
||||
|
||||
return response($this->serializer->serialize($schedule, 'json'));
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
use Jikan\Jikan;
|
||||
use Jikan\MyAnimeList\MalClient;
|
||||
use Jikan\Request\Search\AnimeSearchRequest;
|
||||
use Jikan\Request\Search\MangaSearchRequest;
|
||||
use Jikan\Request\Search\CharacterSearchRequest;
|
||||
use Jikan\Request\Search\PersonSearchRequest;
|
||||
use Jikan\Helper\Constants as JikanConstants;
|
||||
use App\Providers\SearchQueryBuilder;
|
||||
use JMS\Serializer\Serializer;
|
||||
|
||||
class SearchController extends Controller
|
||||
{
|
||||
public function anime(string $query = null, int $page = 1)
|
||||
{
|
||||
$search = $this->jikan->getAnimeSearch(
|
||||
SearchQueryBuilder::create(
|
||||
(new AnimeSearchRequest())
|
||||
->setPage($page)
|
||||
->setQuery($query)
|
||||
)
|
||||
);
|
||||
|
||||
return response($this->serializer->serialize($search, 'json'));
|
||||
}
|
||||
|
||||
public function manga(string $query = null, int $page = 1)
|
||||
{
|
||||
$search = $this->jikan->getMangaSearch(
|
||||
SearchQueryBuilder::create(
|
||||
(new MangaSearchRequest())
|
||||
->setPage($page)
|
||||
->setQuery($query)
|
||||
)
|
||||
);
|
||||
|
||||
return response($this->serializer->serialize($search, 'json'));
|
||||
}
|
||||
|
||||
public function people(string $query = null, int $page = 1)
|
||||
{
|
||||
$search = $this->jikan->getPersonSearch(
|
||||
SearchQueryBuilder::create(
|
||||
(new PersonSearchRequest())
|
||||
->setPage($page)
|
||||
->setQuery($query)
|
||||
)
|
||||
);
|
||||
|
||||
// backwards compatibility
|
||||
$search = json_decode(
|
||||
$this->serializer->serialize($search, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($search['result'] as &$item) {
|
||||
$item['nicknames'] = empty($item['nicknames']) ? null : implode(",", $item['nicknames']);
|
||||
}
|
||||
|
||||
return response(
|
||||
json_encode($search)
|
||||
);
|
||||
}
|
||||
|
||||
public function character(string $query = null, int $page = 1)
|
||||
{
|
||||
$search = $this->jikan->getCharacterSearch(
|
||||
SearchQueryBuilder::create(
|
||||
(new CharacterSearchRequest())
|
||||
->setPage($page)
|
||||
->setQuery($query)
|
||||
)
|
||||
);
|
||||
|
||||
// backwards compatibility
|
||||
$search = json_decode(
|
||||
$this->serializer->serialize($search, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($search['result'] as &$item) {
|
||||
$item['nicknames'] = empty($item['nicknames']) ? null : implode(",", $item['nicknames']);
|
||||
}
|
||||
|
||||
return response(
|
||||
json_encode($search)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
use Jikan\Request\Seasonal\SeasonalRequest;
|
||||
|
||||
class SeasonController extends Controller
|
||||
{
|
||||
private const VALID_SEASONS = [
|
||||
'summer',
|
||||
'spring',
|
||||
'winter',
|
||||
'fall'
|
||||
];
|
||||
|
||||
public function main(?int $year = null, ?string $season = null)
|
||||
{
|
||||
if (!is_null($season) && !\in_array(strtolower($season), self::VALID_SEASONS)) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
// backwards compatibility
|
||||
$season = $this->jikan->getSeasonal(new SeasonalRequest($year, $season));
|
||||
$season = json_decode(
|
||||
$this->serializer->serialize($season, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
foreach ($season['season'] as &$item) {
|
||||
$item['continued'] = $item['continuing'];
|
||||
unset($item['continuing']);
|
||||
}
|
||||
|
||||
return response(
|
||||
json_encode($season)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2;
|
||||
|
||||
use Jikan\Request\Top\TopAnimeRequest;
|
||||
use Jikan\Request\Top\TopMangaRequest;
|
||||
use Jikan\Request\Top\TopCharactersRequest;
|
||||
use Jikan\Request\Top\TopPeopleRequest;
|
||||
use Jikan\Helper\Constants as JikanConstants;
|
||||
|
||||
class TopController extends Controller
|
||||
{
|
||||
public function anime(int $page = 1, string $type = null)
|
||||
{
|
||||
if (!is_null($type) && !\in_array(strtolower($type), [
|
||||
JikanConstants::TOP_AIRING,
|
||||
JikanConstants::TOP_UPCOMING,
|
||||
JikanConstants::TOP_TV,
|
||||
JikanConstants::TOP_MOVIE,
|
||||
JikanConstants::TOP_OVA,
|
||||
JikanConstants::TOP_SPECIAL,
|
||||
JikanConstants::TOP_BY_POPULARITY,
|
||||
JikanConstants::TOP_BY_FAVORITES,
|
||||
])) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
$top = ['top' => $this->jikan->getTopAnime(new TopAnimeRequest($page, $type))];
|
||||
|
||||
return response($this->serializer->serialize($top, 'json'));
|
||||
}
|
||||
|
||||
public function manga(int $page = 1, string $type = null)
|
||||
{
|
||||
if (!is_null($type) && !\in_array(
|
||||
strtolower($type),
|
||||
[
|
||||
JikanConstants::TOP_MANGA,
|
||||
JikanConstants::TOP_NOVEL,
|
||||
JikanConstants::TOP_ONE_SHOT,
|
||||
JikanConstants::TOP_DOUJINSHI,
|
||||
JikanConstants::TOP_MANHWA,
|
||||
JikanConstants::TOP_MANHUA,
|
||||
JikanConstants::TOP_BY_POPULARITY,
|
||||
JikanConstants::TOP_BY_FAVORITES,
|
||||
]
|
||||
)) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
$top = ['top' => $this->jikan->getTopManga(new TopMangaRequest($page, $type))];
|
||||
|
||||
return response($this->serializer->serialize($top, 'json'));
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use App\Http\HttpHelper;
|
||||
use Jikan\Request\Anime\AnimeCharactersAndStaffRequest;
|
||||
use Jikan\Request\Anime\AnimeEpisodesRequest;
|
||||
use Jikan\Request\Anime\AnimeForumRequest;
|
||||
use Jikan\Request\Anime\AnimeMoreInfoRequest;
|
||||
use Jikan\Request\Anime\AnimeNewsRequest;
|
||||
use Jikan\Request\Anime\AnimePicturesRequest;
|
||||
use Jikan\Request\Anime\AnimeRecentlyUpdatedByUsersRequest;
|
||||
use Jikan\Request\Anime\AnimeRecommendationsRequest;
|
||||
use Jikan\Request\Anime\AnimeRequest;
|
||||
use Jikan\Request\Anime\AnimeReviewsRequest;
|
||||
use Jikan\Request\Anime\AnimeStatsRequest;
|
||||
use Jikan\Request\Anime\AnimeVideosRequest;
|
||||
|
||||
class AnimeController extends Controller
|
||||
{
|
||||
public function main(int $id)
|
||||
{
|
||||
$anime = $this->jikan->getAnime(new AnimeRequest($id));
|
||||
|
||||
$animeSerialized = $this->serializer->serialize($anime, 'json');
|
||||
$animeSerialized = HttpHelper::serializeEmptyObjectsControllerLevel(
|
||||
json_decode($animeSerialized, true)
|
||||
);
|
||||
$animeSerialized = json_encode($animeSerialized);
|
||||
|
||||
return response($animeSerialized);
|
||||
}
|
||||
|
||||
public function characters_staff(int $id)
|
||||
{
|
||||
$anime = $this->jikan->getAnimeCharactersAndStaff(new AnimeCharactersAndStaffRequest($id));
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
|
||||
public function episodes(int $id, int $page = 1)
|
||||
{
|
||||
$anime = $this->jikan->getAnimeEpisodes(new AnimeEpisodesRequest($id, $page));
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
|
||||
public function news(int $id)
|
||||
{
|
||||
$anime = ['articles' => $this->jikan->getNewsList(new AnimeNewsRequest($id))];
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
|
||||
public function forum(int $id)
|
||||
{
|
||||
$anime = ['topics' => $this->jikan->getAnimeForum(new AnimeForumRequest($id))];
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
|
||||
public function videos(int $id)
|
||||
{
|
||||
$anime = $this->jikan->getAnimeVideos(new AnimeVideosRequest($id));
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
|
||||
public function pictures(int $id)
|
||||
{
|
||||
$anime = ['pictures' => $this->jikan->getAnimePictures(new AnimePicturesRequest($id))];
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
|
||||
public function stats(int $id)
|
||||
{
|
||||
$anime = $this->jikan->getAnimeStats(new AnimeStatsRequest($id));
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
|
||||
public function moreInfo(int $id)
|
||||
{
|
||||
$anime = ['moreinfo' => $this->jikan->getAnimeMoreInfo(new AnimeMoreInfoRequest($id))];
|
||||
return response(json_encode($anime));
|
||||
}
|
||||
|
||||
public function recommendations(int $id)
|
||||
{
|
||||
$anime = ['recommendations' => $this->jikan->getAnimeRecommendations(new AnimeRecommendationsRequest($id))];
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
|
||||
public function userupdates(int $id, int $page = 1)
|
||||
{
|
||||
$anime = ['users' => $this->jikan->getAnimeRecentlyUpdatedByUsers(new AnimeRecentlyUpdatedByUsersRequest($id, $page))];
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
|
||||
public function reviews(int $id, int $page = 1)
|
||||
{
|
||||
$anime = ['reviews' => $this->jikan->getAnimeReviews(new AnimeReviewsRequest($id, $page))];
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\Character\CharacterRequest;
|
||||
use Jikan\Request\Character\CharacterPicturesRequest;
|
||||
|
||||
class CharacterController extends Controller
|
||||
{
|
||||
public function main(int $id)
|
||||
{
|
||||
$character = $this->jikan->getCharacter(new CharacterRequest($id));
|
||||
return response($this->serializer->serialize($character, 'json'));
|
||||
}
|
||||
|
||||
public function pictures(int $id)
|
||||
{
|
||||
$character = ['pictures' => $this->jikan->getCharacterPictures(new CharacterPicturesRequest($id))];
|
||||
return response($this->serializer->serialize($character, 'json'));
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\Club\ClubRequest;
|
||||
use Jikan\Request\Club\UserListRequest;
|
||||
|
||||
class ClubController extends Controller
|
||||
{
|
||||
public function main(int $id)
|
||||
{
|
||||
$club = $this->jikan->getClub(new ClubRequest($id));
|
||||
return response($this->serializer->serialize($club, 'json'));
|
||||
}
|
||||
|
||||
public function members(int $id, int $page = 1)
|
||||
{
|
||||
$club = ['members' => $this->jikan->getClubUsers(new UserListRequest($id, $page))];
|
||||
return response($this->serializer->serialize($club, 'json'));
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use App\Providers\SerializerFactory;
|
||||
use App\Providers\SerializerServiceProdivder;
|
||||
use App\Providers\SerializerServiceProviderV3;
|
||||
use Jikan\Jikan;
|
||||
use Jikan\MyAnimeList\MalClient;
|
||||
use JMS\Serializer\Context;
|
||||
use JMS\Serializer\Serializer;
|
||||
use Laravel\Lumen\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
/**
|
||||
* @var Serializer
|
||||
*/
|
||||
protected $serializer;
|
||||
|
||||
/**
|
||||
* @var MalClient
|
||||
*/
|
||||
protected $jikan;
|
||||
|
||||
/**
|
||||
* AnimeController constructor.
|
||||
*
|
||||
* @param Serializer $serializer
|
||||
* @param MalClient $jikan
|
||||
*/
|
||||
public function __construct(MalClient $jikan)
|
||||
{
|
||||
$this->serializer = SerializerFactory::createV3();
|
||||
$this->jikan = $jikan;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\Genre\AnimeGenreRequest;
|
||||
use Jikan\Request\Genre\MangaGenreRequest;
|
||||
|
||||
class GenreController extends Controller
|
||||
{
|
||||
public function anime(int $id, int $page = 1)
|
||||
{
|
||||
$person = $this->jikan->getAnimeGenre(new AnimeGenreRequest($id, $page));
|
||||
return response($this->serializer->serialize($person, 'json'));
|
||||
}
|
||||
|
||||
public function manga(int $id, int $page = 1)
|
||||
{
|
||||
$person = $this->jikan->getMangaGenre(new MangaGenreRequest($id, $page));
|
||||
return response($this->serializer->serialize($person, 'json'));
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\Magazine\MagazineRequest;
|
||||
|
||||
class MagazineController extends Controller
|
||||
{
|
||||
public function main(int $id, int $page = 1)
|
||||
{
|
||||
$magazine = $this->jikan->getMagazine(new MagazineRequest($id, $page));
|
||||
return response($this->serializer->serialize($magazine, 'json'));
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\Manga\MangaCharactersRequest;
|
||||
use Jikan\Request\Manga\MangaForumRequest;
|
||||
use Jikan\Request\Manga\MangaMoreInfoRequest;
|
||||
use Jikan\Request\Manga\MangaNewsRequest;
|
||||
use Jikan\Request\Manga\MangaPicturesRequest;
|
||||
use Jikan\Request\Manga\MangaRecentlyUpdatedByUsersRequest;
|
||||
use Jikan\Request\Manga\MangaRecommendationsRequest;
|
||||
use Jikan\Request\Manga\MangaRequest;
|
||||
use Jikan\Request\Manga\MangaReviewsRequest;
|
||||
use Jikan\Request\Manga\MangaStatsRequest;
|
||||
|
||||
class MangaController extends Controller
|
||||
{
|
||||
public function main(int $id)
|
||||
{
|
||||
$manga = $this->jikan->getManga(new MangaRequest($id));
|
||||
|
||||
$mangaSerialized = $this->serializer->serialize($manga, 'json');
|
||||
$mangaSerialized = HttpHelper::serializeEmptyObjectsControllerLevel(
|
||||
json_decode($mangaSerialized, true)
|
||||
);
|
||||
$mangaSerialized = json_encode($mangaSerialized);
|
||||
|
||||
return response($this->serializer->serialize($manga, 'json'));
|
||||
}
|
||||
|
||||
public function characters(int $id)
|
||||
{
|
||||
$manga = ['characters' => $this->jikan->getMangaCharacters(new MangaCharactersRequest($id))];
|
||||
return response($this->serializer->serialize($manga, 'json'));
|
||||
}
|
||||
|
||||
public function news(int $id)
|
||||
{
|
||||
$manga = ['articles' => $this->jikan->getNewsList(new MangaNewsRequest($id))];
|
||||
return response($this->serializer->serialize($manga, 'json'));
|
||||
}
|
||||
|
||||
public function forum(int $id)
|
||||
{
|
||||
$manga = ['topics' => $this->jikan->getMangaForum(new MangaForumRequest($id))];
|
||||
return response($this->serializer->serialize($manga, 'json'));
|
||||
}
|
||||
|
||||
public function pictures(int $id)
|
||||
{
|
||||
$manga = ['pictures' => $this->jikan->getMangaPictures(new MangaPicturesRequest($id))];
|
||||
return response($this->serializer->serialize($manga, 'json'));
|
||||
}
|
||||
|
||||
public function stats(int $id)
|
||||
{
|
||||
$manga = $this->jikan->getMangaStats(new MangaStatsRequest($id));
|
||||
return response($this->serializer->serialize($manga, 'json'));
|
||||
}
|
||||
|
||||
public function moreInfo(int $id)
|
||||
{
|
||||
$manga = ['moreinfo' => $this->jikan->getMangaMoreInfo(new MangaMoreInfoRequest($id))];
|
||||
return response(json_encode($manga));
|
||||
}
|
||||
|
||||
public function recommendations(int $id)
|
||||
{
|
||||
$manga = ['recommendations' => $this->jikan->getMangaRecommendations(new MangaRecommendationsRequest($id))];
|
||||
return response($this->serializer->serialize($manga, 'json'));
|
||||
}
|
||||
|
||||
public function userupdates(int $id, int $page = 1)
|
||||
{
|
||||
$manga = ['users' => $this->jikan->getMangaRecentlyUpdatedByUsers(new MangaRecentlyUpdatedByUsersRequest($id, $page))];
|
||||
return response($this->serializer->serialize($manga, 'json'));
|
||||
}
|
||||
|
||||
public function reviews(int $id, int $page = 1)
|
||||
{
|
||||
$manga = ['reviews' => $this->jikan->getMangaReviews(new MangaReviewsRequest($id, $page))];
|
||||
return response($this->serializer->serialize($manga, 'json'));
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
class MetaController extends Controller
|
||||
{
|
||||
public function status()
|
||||
{
|
||||
$info = app('redis')->info();
|
||||
|
||||
return response()->json([
|
||||
'cached_requests' => count(app('redis')->keys('request:*')),
|
||||
'requests_today' => count(app('redis')->keys('requests:today:*')),
|
||||
'requests_this_week' => count(app('redis')->keys('requests:weekly:*')),
|
||||
'requests_this_month' => count(app('redis')->keys('requests:monthly:*')),
|
||||
'connected_clients' => $info['Clients']['connected_clients'],
|
||||
'total_connections_received' => $info['Stats']['total_connections_received'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function requests($type, $period, $offset = 0)
|
||||
{
|
||||
if (!\in_array($type, [
|
||||
'anime', 'manga', 'character', 'person', 'people', 'search', 'top', 'season', 'schedule', 'user', 'producer', 'magazine', 'genre'
|
||||
])) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (!\in_array($period, ['today', 'weekly', 'monthly'])) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$requests = [];
|
||||
$data = app('redis')->keys("requests:{$period}:*{$type}*");
|
||||
|
||||
foreach ($data as $key) {
|
||||
$requests[explode(":", $key)[2]] = (int) app('redis')->get($key);
|
||||
}
|
||||
|
||||
arsort($requests);
|
||||
|
||||
return response()->json(
|
||||
\array_slice($requests, $offset, 1000)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\Person\PersonRequest;
|
||||
use Jikan\Request\Person\PersonPicturesRequest;
|
||||
|
||||
class PersonController extends Controller
|
||||
{
|
||||
public function main(int $id)
|
||||
{
|
||||
$person = $this->jikan->getPerson(new PersonRequest($id));
|
||||
return response($this->serializer->serialize($person, 'json'));
|
||||
}
|
||||
|
||||
public function pictures(int $id)
|
||||
{
|
||||
$person = ['pictures' => $this->jikan->getPersonPictures(new PersonPicturesRequest($id))];
|
||||
return response($this->serializer->serialize($person, 'json'));
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\Producer\ProducerRequest;
|
||||
|
||||
class ProducerController extends Controller
|
||||
{
|
||||
public function main(int $id, int $page = 1)
|
||||
{
|
||||
$producer = $this->jikan->getProducer(new ProducerRequest($id, $page));
|
||||
return response($this->serializer->serialize($producer, 'json'));
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\Schedule\ScheduleRequest;
|
||||
|
||||
class ScheduleController extends Controller
|
||||
{
|
||||
private const VALID_DAYS = [
|
||||
'monday',
|
||||
'tuesday',
|
||||
'wednesday',
|
||||
'thursday',
|
||||
'friday',
|
||||
'saturday',
|
||||
'sunday',
|
||||
'other',
|
||||
'unknown',
|
||||
];
|
||||
|
||||
public function main(?string $day = null)
|
||||
{
|
||||
if (null !== $day && !\in_array(strtolower($day), self::VALID_DAYS, true)) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request',
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
$schedule = $this->jikan->getSchedule(new ScheduleRequest());
|
||||
|
||||
if (null !== $day) {
|
||||
$schedule = [
|
||||
strtolower($day) => $schedule->{'get'.ucfirst(strtolower($day))}(),
|
||||
];
|
||||
}
|
||||
|
||||
return response($this->serializer->serialize($schedule, 'json'));
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Jikan;
|
||||
use Jikan\MyAnimeList\MalClient;
|
||||
use Jikan\Request\Search\AnimeSearchRequest;
|
||||
use Jikan\Request\Search\MangaSearchRequest;
|
||||
use Jikan\Request\Search\CharacterSearchRequest;
|
||||
use Jikan\Request\Search\PersonSearchRequest;
|
||||
use Jikan\Helper\Constants as JikanConstants;
|
||||
use App\Providers\SearchQueryBuilder;
|
||||
use JMS\Serializer\Serializer;
|
||||
use phpDocumentor\Reflection\Types\Object_;
|
||||
|
||||
class SearchController extends Controller
|
||||
{
|
||||
public function anime(int $page = 1)
|
||||
{
|
||||
$search = $this->jikan->getAnimeSearch(
|
||||
SearchQueryBuilder::create(
|
||||
(new AnimeSearchRequest())->setPage($page)
|
||||
)
|
||||
);
|
||||
|
||||
return response($this->filter($search));
|
||||
}
|
||||
|
||||
public function manga(int $page = 1)
|
||||
{
|
||||
$search = $this->jikan->getMangaSearch(
|
||||
SearchQueryBuilder::create(
|
||||
(new MangaSearchRequest())->setPage($page)
|
||||
)
|
||||
);
|
||||
return response($this->filter($search));
|
||||
}
|
||||
|
||||
public function people(int $page = 1)
|
||||
{
|
||||
$search = $this->jikan->getPersonSearch(
|
||||
SearchQueryBuilder::create(
|
||||
(new PersonSearchRequest())->setPage($page)
|
||||
)
|
||||
);
|
||||
|
||||
return response($this->filter($search));
|
||||
}
|
||||
|
||||
public function character(int $page = 1)
|
||||
{
|
||||
$search = $this->jikan->getCharacterSearch(
|
||||
SearchQueryBuilder::create(
|
||||
(new CharacterSearchRequest())->setPage($page)
|
||||
)
|
||||
);
|
||||
|
||||
return response($this->filter($search));
|
||||
}
|
||||
|
||||
|
||||
private function filter($object)
|
||||
{
|
||||
$limit = $_GET['limit'] ?? null;
|
||||
|
||||
$data = json_decode(
|
||||
$this->serializer->serialize($object, 'json'),
|
||||
true
|
||||
);
|
||||
|
||||
if (!is_null($limit)) {
|
||||
$data['results'] = array_slice($data['results'], 0, $limit);
|
||||
}
|
||||
|
||||
return json_encode(
|
||||
$data
|
||||
);
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\Seasonal\SeasonalRequest;
|
||||
use Jikan\Request\SeasonList\SeasonListRequest;
|
||||
|
||||
class SeasonController extends Controller
|
||||
{
|
||||
private const VALID_SEASONS = [
|
||||
'summer',
|
||||
'spring',
|
||||
'winter',
|
||||
'fall'
|
||||
];
|
||||
|
||||
public function main(?int $year = null, ?string $season = null)
|
||||
{
|
||||
if (!is_null($season) && !\in_array(strtolower($season), self::VALID_SEASONS)) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
$season = $this->jikan->getSeasonal(new SeasonalRequest($year, $season));
|
||||
|
||||
return response($this->serializer->serialize($season, 'json'));
|
||||
}
|
||||
|
||||
public function archive()
|
||||
{
|
||||
return response(
|
||||
$this->serializer->serialize(
|
||||
['archive' => $this->jikan->getSeasonList(new SeasonListRequest())],
|
||||
'json'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function later()
|
||||
{
|
||||
$season = $this->jikan->getSeasonal(new SeasonalRequest(null, null, true));
|
||||
return response($this->serializer->serialize($season, 'json'));
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\Top\TopAnimeRequest;
|
||||
use Jikan\Request\Top\TopMangaRequest;
|
||||
use Jikan\Request\Top\TopCharactersRequest;
|
||||
use Jikan\Request\Top\TopPeopleRequest;
|
||||
use Jikan\Helper\Constants as JikanConstants;
|
||||
|
||||
class TopController extends Controller
|
||||
{
|
||||
public function anime(int $page = 1, string $type = null)
|
||||
{
|
||||
if (!is_null($type) && !\in_array(strtolower($type), [
|
||||
JikanConstants::TOP_AIRING,
|
||||
JikanConstants::TOP_UPCOMING,
|
||||
JikanConstants::TOP_TV,
|
||||
JikanConstants::TOP_MOVIE,
|
||||
JikanConstants::TOP_OVA,
|
||||
JikanConstants::TOP_SPECIAL,
|
||||
JikanConstants::TOP_BY_POPULARITY,
|
||||
JikanConstants::TOP_BY_FAVORITES,
|
||||
])) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
$anime = $this->jikan->getTopAnime(new TopAnimeRequest($page, $type));
|
||||
|
||||
$top = ['top' => $this->jikan->getTopAnime(new TopAnimeRequest($page, $type))];
|
||||
|
||||
return response($this->serializer->serialize($top, 'json'));
|
||||
}
|
||||
|
||||
public function manga(int $page = 1, string $type = null)
|
||||
{
|
||||
if (!is_null($type) && !\in_array(
|
||||
strtolower($type),
|
||||
[
|
||||
JikanConstants::TOP_MANGA,
|
||||
JikanConstants::TOP_NOVEL,
|
||||
JikanConstants::TOP_ONE_SHOT,
|
||||
JikanConstants::TOP_DOUJINSHI,
|
||||
JikanConstants::TOP_MANHWA,
|
||||
JikanConstants::TOP_MANHUA,
|
||||
JikanConstants::TOP_BY_POPULARITY,
|
||||
JikanConstants::TOP_BY_FAVORITES,
|
||||
]
|
||||
)) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
$top = ['top' => $this->jikan->getTopManga(new TopMangaRequest($page, $type))];
|
||||
|
||||
return response($this->serializer->serialize($top, 'json'));
|
||||
}
|
||||
|
||||
public function people(int $page = 1)
|
||||
{
|
||||
$top = ['top' => $this->jikan->getTopPeople(new TopPeopleRequest($page))];
|
||||
|
||||
return response($this->serializer->serialize($top, 'json'));
|
||||
}
|
||||
|
||||
public function characters(int $page = 1)
|
||||
{
|
||||
$top = ['top' => $this->jikan->getTopCharacters(new TopCharactersRequest($page))];
|
||||
|
||||
return response($this->serializer->serialize($top, 'json'));
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V4;
|
||||
|
||||
use Jikan\Request\User\UserAnimeListRequest;
|
||||
use Jikan\Request\User\UserMangaListRequest;
|
||||
use Jikan\Request\User\UserProfileRequest;
|
||||
use Jikan\Request\User\UserFriendsRequest;
|
||||
use Jikan\Request\User\UserHistoryRequest;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function profile(string $username)
|
||||
{
|
||||
$person = $this->jikan->getUserProfile(new UserProfileRequest($username));
|
||||
return response($this->serializer->serialize($person, 'json'));
|
||||
}
|
||||
|
||||
public function history(string $username, ?string $type = null)
|
||||
{
|
||||
if (!is_null($type) && !\in_array(strtolower($type), ['anime', 'manga'])) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
|
||||
$person = ['history' => $this->jikan->getUserHistory(new UserHistoryRequest($username, $type))];
|
||||
|
||||
return response($this->serializer->serialize($person, 'json'));
|
||||
}
|
||||
|
||||
public function friends(string $username, int $page = 1)
|
||||
{
|
||||
$person = ['friends' => $this->jikan->getUserFriends(new UserFriendsRequest($username, $page))];
|
||||
return response($this->serializer->serialize($person, 'json'));
|
||||
}
|
||||
|
||||
public function animelist(string $username, ?string $status = null, int $page = 1)
|
||||
{
|
||||
if (!is_null($status)) {
|
||||
$status = strtolower($status);
|
||||
|
||||
if (!\in_array($status, ['all', 'watching', 'completed', 'onhold', 'dropped', 'plantowatch', 'ptw'])) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
}
|
||||
$status = $this->listStatusToId($status);
|
||||
|
||||
return response(
|
||||
$this->serializer->serialize(
|
||||
[
|
||||
'anime' => $this->jikan->getUserAnimeList(
|
||||
new UserAnimeListRequest($username, $page, $status)
|
||||
)
|
||||
],
|
||||
'json'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function mangalist(string $username, ?string $status = null, int $page = 1)
|
||||
{
|
||||
if (!is_null($status)) {
|
||||
$status = strtolower($status);
|
||||
|
||||
if (!\in_array($status, ['all', 'reading', 'completed', 'onhold', 'dropped', 'plantoread', 'ptr'])) {
|
||||
return response()->json([
|
||||
'error' => 'Bad Request'
|
||||
])->setStatusCode(400);
|
||||
}
|
||||
}
|
||||
$status = $this->listStatusToId($status);
|
||||
|
||||
return response(
|
||||
$this->serializer->serialize(
|
||||
[
|
||||
'manga' => $this->jikan->getUserMangaList(
|
||||
new UserMangaListRequest($username, $page, $status)
|
||||
)
|
||||
],
|
||||
'json'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function listStatusToId(?string $status) : int
|
||||
{
|
||||
if (is_null($status)) {
|
||||
return 7;
|
||||
}
|
||||
|
||||
switch ($status) {
|
||||
case 'all':
|
||||
return 7;
|
||||
case 'watching':
|
||||
case 'reading':
|
||||
return 1;
|
||||
case 'completed':
|
||||
return 2;
|
||||
case 'onhold':
|
||||
return 3;
|
||||
case 'dropped':
|
||||
return 4;
|
||||
case 'plantowatch':
|
||||
case 'ptw':
|
||||
case 'plantoread':
|
||||
case 'ptr':
|
||||
return 6;
|
||||
default:
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user