mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
Slim Controller boiiii 🎉
This commit is contained in:
parent
7db40c5a4a
commit
87b2c438fa
@ -2,19 +2,15 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
|
||||
use Exception;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Jikan\Exception\ParserException;
|
||||
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\Debug\Exception\FlattenException;
|
||||
use Symfony\Component\Console\Application as ConsoleApplication;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
|
||||
use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
@ -53,6 +49,10 @@ class Handler extends ExceptionHandler
|
||||
public function render($request, Exception $e)
|
||||
{
|
||||
|
||||
if ($e instanceof ParserException) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
// Bugsnag::notifyException($e);
|
||||
// if ($e instanceof HttpResponseException) {
|
||||
// } elseif ($e instanceof ModelNotFoundException) {
|
||||
|
@ -2,52 +2,13 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Jikan\Exception\ParserException;
|
||||
use Jikan\MyAnimeList\MalClient as Jikan;
|
||||
use Jikan\Request\Anime\AnimeRequest;
|
||||
use JMS\Serializer\Serializer;
|
||||
|
||||
class AnimeController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var Serializer
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
/**
|
||||
* @var Jikan
|
||||
*/
|
||||
private $jikan;
|
||||
|
||||
/**
|
||||
* AnimeController constructor.
|
||||
*
|
||||
* @param Serializer $serializer
|
||||
* @param Jikan $jikan
|
||||
*/
|
||||
public function __construct(Serializer $serializer, Jikan $jikan)
|
||||
{
|
||||
$this->serializer = $serializer;
|
||||
$this->jikan = $jikan;
|
||||
}
|
||||
|
||||
public function request(int $id, $request = null, $requestArg = null)
|
||||
{
|
||||
try {
|
||||
$anime = $this->jikan->getAnime(
|
||||
new AnimeRequest($id)
|
||||
);
|
||||
|
||||
return response(
|
||||
$this->serializer->serialize($anime, 'json')
|
||||
);
|
||||
|
||||
} catch (ParserException $e) {
|
||||
return response()->json(
|
||||
[
|
||||
'error' => $e->getMessage(),
|
||||
]
|
||||
);
|
||||
}
|
||||
$anime = $this->jikan->getAnime(new AnimeRequest($id));
|
||||
return response($this->serializer->serialize($anime, 'json'));
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,32 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Jikan\Jikan;
|
||||
use Jikan\MyAnimeList\MalClient;
|
||||
use JMS\Serializer\Serializer;
|
||||
use Laravel\Lumen\Routing\Controller as BaseController;
|
||||
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
protected $guzzle;
|
||||
protected $response;
|
||||
/**
|
||||
* @var Serializer
|
||||
*/
|
||||
protected $serializer;
|
||||
|
||||
/**
|
||||
* @var MalClient
|
||||
*/
|
||||
protected $jikan;
|
||||
|
||||
/**
|
||||
* AnimeController constructor.
|
||||
*
|
||||
* @param Serializer $serializer
|
||||
* @param MalClient $jikan
|
||||
*/
|
||||
public function __construct(Serializer $serializer, MalClient $jikan)
|
||||
{
|
||||
$this->serializer = $serializer;
|
||||
$this->jikan = $jikan;
|
||||
}
|
||||
}
|
||||
|
@ -166,9 +166,9 @@ $app->singleton(
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
'Jikan/Jikan',
|
||||
\Jikan\MyAnimeList\MalClient::class,
|
||||
function () {
|
||||
return new \Jikan\Jikan();
|
||||
return new \Jikan\MyAnimeList\MalClient();
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user