mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
add v4 Recent Reviews & Recommendations
This commit is contained in:
parent
4fbc5d8f65
commit
0f156a6386
@ -2,33 +2,128 @@
|
||||
|
||||
namespace App\Http\Controllers\V4DB;
|
||||
|
||||
use App\Http\HttpHelper;
|
||||
use App\Http\HttpResponse;
|
||||
use App\Http\Resources\V4\ResultsResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Jikan\Helper\Constants;
|
||||
use Jikan\Request\Recommendations\RecentRecommendationsRequest;
|
||||
use Jikan\Request\Reviews\RecentReviewsRequest;
|
||||
use MongoDB\BSON\UTCDateTime;
|
||||
|
||||
class RecommendationsController extends Controller
|
||||
{
|
||||
|
||||
public function anime()
|
||||
public function anime(Request $request)
|
||||
{
|
||||
$page = $_GET['page'] ?? 1;
|
||||
$results = [
|
||||
'recommendations' => $this->jikan->getRecentRecommendations(
|
||||
new RecentRecommendationsRequest(Constants::RECENT_RECOMMENDATION_ANIME, $page)
|
||||
)
|
||||
];
|
||||
$results = DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->get();
|
||||
|
||||
return response($this->serializer->serialize($results, 'json'));
|
||||
if (
|
||||
$results->isEmpty()
|
||||
|| $this->isExpired($request, $results)
|
||||
) {
|
||||
$page = $request->get('page') ?? 1;
|
||||
$anime = $this->jikan->getRecentRecommendations(new RecentRecommendationsRequest(Constants::RECENT_RECOMMENDATION_ANIME, $page));
|
||||
$response = \json_decode($this->serializer->serialize($anime, 'json'), true);
|
||||
|
||||
if (HttpHelper::hasError($response)) {
|
||||
return HttpResponse::notFound($request);
|
||||
}
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
$meta = [
|
||||
'createdAt' => new UTCDateTime(),
|
||||
'modifiedAt' => new UTCDateTime(),
|
||||
'request_hash' => $this->fingerprint
|
||||
];
|
||||
}
|
||||
$meta['modifiedAt'] = new UTCDateTime();
|
||||
|
||||
$response = $meta + $response;
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
DB::table($this->getRouteTable($request))
|
||||
->insert($response);
|
||||
}
|
||||
|
||||
if ($this->isExpired($request, $results)) {
|
||||
DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->update($response);
|
||||
}
|
||||
|
||||
$results = DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->get();
|
||||
}
|
||||
|
||||
$response = (new ResultsResource(
|
||||
$results->first()
|
||||
))->response();
|
||||
|
||||
return $this->prepareResponse(
|
||||
$response,
|
||||
$results,
|
||||
$request
|
||||
);
|
||||
}
|
||||
|
||||
public function manga()
|
||||
public function manga(Request $request)
|
||||
{
|
||||
$page = $_GET['page'] ?? 1;
|
||||
$results = [
|
||||
'recommendations' => $this->jikan->getRecentRecommendations(
|
||||
new RecentRecommendationsRequest(Constants::RECENT_RECOMMENDATION_MANGA, $page)
|
||||
)
|
||||
];
|
||||
$results = DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->get();
|
||||
|
||||
return response($this->serializer->serialize($results, 'json'));
|
||||
if (
|
||||
$results->isEmpty()
|
||||
|| $this->isExpired($request, $results)
|
||||
) {
|
||||
$page = $request->get('page') ?? 1;
|
||||
$anime = $this->jikan->getRecentRecommendations(new RecentRecommendationsRequest(Constants::RECENT_RECOMMENDATION_MANGA, $page));
|
||||
$response = \json_decode($this->serializer->serialize($anime, 'json'), true);
|
||||
|
||||
if (HttpHelper::hasError($response)) {
|
||||
return HttpResponse::notFound($request);
|
||||
}
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
$meta = [
|
||||
'createdAt' => new UTCDateTime(),
|
||||
'modifiedAt' => new UTCDateTime(),
|
||||
'request_hash' => $this->fingerprint
|
||||
];
|
||||
}
|
||||
$meta['modifiedAt'] = new UTCDateTime();
|
||||
|
||||
$response = $meta + $response;
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
DB::table($this->getRouteTable($request))
|
||||
->insert($response);
|
||||
}
|
||||
|
||||
if ($this->isExpired($request, $results)) {
|
||||
DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->update($response);
|
||||
}
|
||||
|
||||
$results = DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->get();
|
||||
}
|
||||
|
||||
$response = (new ResultsResource(
|
||||
$results->first()
|
||||
))->response();
|
||||
|
||||
return $this->prepareResponse(
|
||||
$response,
|
||||
$results,
|
||||
$request
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,14 @@
|
||||
|
||||
namespace App\Http\Controllers\V4DB;
|
||||
|
||||
use App\Http\HttpHelper;
|
||||
use App\Http\HttpResponse;
|
||||
use App\Http\Resources\V4\ResultsResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Jikan\Helper\Constants;
|
||||
use Jikan\Request\Reviews\RecentReviewsRequest;
|
||||
use Laravel\Lumen\Http\Request;
|
||||
use MongoDB\BSON\UTCDateTime;
|
||||
|
||||
class ReviewsController extends Controller
|
||||
{
|
||||
@ -22,23 +27,113 @@ class ReviewsController extends Controller
|
||||
|
||||
public function anime(Request $request)
|
||||
{
|
||||
$page = $request->get('page') ?? 1;
|
||||
$results = DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->get();
|
||||
|
||||
$results = $this->jikan->getRecentReviews(
|
||||
new RecentReviewsRequest(Constants::RECENT_REVIEW_ANIME, $page)
|
||||
if (
|
||||
$results->isEmpty()
|
||||
|| $this->isExpired($request, $results)
|
||||
) {
|
||||
$page = $request->get('page') ?? 1;
|
||||
$anime = $this->jikan->getRecentReviews(new RecentReviewsRequest(Constants::RECENT_REVIEW_ANIME, $page));
|
||||
$response = \json_decode($this->serializer->serialize($anime, 'json'), true);
|
||||
|
||||
if (HttpHelper::hasError($response)) {
|
||||
return HttpResponse::notFound($request);
|
||||
}
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
$meta = [
|
||||
'createdAt' => new UTCDateTime(),
|
||||
'modifiedAt' => new UTCDateTime(),
|
||||
'request_hash' => $this->fingerprint
|
||||
];
|
||||
}
|
||||
$meta['modifiedAt'] = new UTCDateTime();
|
||||
|
||||
$response = $meta + $response;
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
DB::table($this->getRouteTable($request))
|
||||
->insert($response);
|
||||
}
|
||||
|
||||
if ($this->isExpired($request, $results)) {
|
||||
DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->update($response);
|
||||
}
|
||||
|
||||
$results = DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->get();
|
||||
}
|
||||
|
||||
$response = (new ResultsResource(
|
||||
$results->first()
|
||||
))->response();
|
||||
|
||||
return $this->prepareResponse(
|
||||
$response,
|
||||
$results,
|
||||
$request
|
||||
);
|
||||
|
||||
return response($this->serializer->serialize($results, 'json'));
|
||||
}
|
||||
|
||||
public function manga(Request $request)
|
||||
{
|
||||
$page = $request->get('page') ?? 1;
|
||||
$results = DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->get();
|
||||
|
||||
$results = $this->jikan->getRecentReviews(
|
||||
new RecentReviewsRequest(Constants::RECENT_REVIEW_MANGA, $page)
|
||||
if (
|
||||
$results->isEmpty()
|
||||
|| $this->isExpired($request, $results)
|
||||
) {
|
||||
$page = $request->get('page') ?? 1;
|
||||
$anime = $this->jikan->getRecentReviews(new RecentReviewsRequest(Constants::RECENT_REVIEW_MANGA, $page));
|
||||
$response = \json_decode($this->serializer->serialize($anime, 'json'), true);
|
||||
|
||||
if (HttpHelper::hasError($response)) {
|
||||
return HttpResponse::notFound($request);
|
||||
}
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
$meta = [
|
||||
'createdAt' => new UTCDateTime(),
|
||||
'modifiedAt' => new UTCDateTime(),
|
||||
'request_hash' => $this->fingerprint
|
||||
];
|
||||
}
|
||||
$meta['modifiedAt'] = new UTCDateTime();
|
||||
|
||||
$response = $meta + $response;
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
DB::table($this->getRouteTable($request))
|
||||
->insert($response);
|
||||
}
|
||||
|
||||
if ($this->isExpired($request, $results)) {
|
||||
DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->update($response);
|
||||
}
|
||||
|
||||
$results = DB::table($this->getRouteTable($request))
|
||||
->where('request_hash', $this->fingerprint)
|
||||
->get();
|
||||
}
|
||||
|
||||
$response = (new ResultsResource(
|
||||
$results->first()
|
||||
))->response();
|
||||
|
||||
return $this->prepareResponse(
|
||||
$response,
|
||||
$results,
|
||||
$request
|
||||
);
|
||||
|
||||
return response($this->serializer->serialize($results, 'json'));
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
"flipbox/lumen-generator": "^6",
|
||||
"illuminate/redis": "^7",
|
||||
"jenssegers/mongodb": "^4.0",
|
||||
"jikan-me/jikan": "v3.0.0-alpha.14",
|
||||
"jikan-me/jikan": "v3.0.0-alpha.15",
|
||||
"jms/serializer": "^1.13",
|
||||
"laravel/lumen-framework": "^7.0",
|
||||
"league/flysystem": "^1.0",
|
||||
|
12
composer.lock
generated
12
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "5f7d6fc3f6c57220812fb43497734a99",
|
||||
"content-hash": "2d853b1c159b5aa408af30b54c37c51f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
@ -2210,16 +2210,16 @@
|
||||
},
|
||||
{
|
||||
"name": "jikan-me/jikan",
|
||||
"version": "v3.0.0-alpha.14",
|
||||
"version": "v3.0.0-alpha.15",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jikan-me/jikan.git",
|
||||
"reference": "8dae508cf3b640ae9f97090071ac9b6fc72ab0dc"
|
||||
"reference": "d285b878e316d72f0b9f7d22c648da22c00860da"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/jikan-me/jikan/zipball/8dae508cf3b640ae9f97090071ac9b6fc72ab0dc",
|
||||
"reference": "8dae508cf3b640ae9f97090071ac9b6fc72ab0dc",
|
||||
"url": "https://api.github.com/repos/jikan-me/jikan/zipball/d285b878e316d72f0b9f7d22c648da22c00860da",
|
||||
"reference": "d285b878e316d72f0b9f7d22c648da22c00860da",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2257,7 +2257,7 @@
|
||||
}
|
||||
],
|
||||
"description": "Jikan is an unofficial MyAnimeList API",
|
||||
"time": "2020-07-12T09:00:29+00:00"
|
||||
"time": "2020-07-12T14:54:21+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jms/metadata",
|
||||
|
@ -176,18 +176,51 @@ return [
|
||||
'GenreController@anime' => 'genres_anime',
|
||||
'GenreController@manga' => 'genres_manga',
|
||||
|
||||
'TopController@anime' => 'top_anime',
|
||||
'TopController@manga' => 'top_manga',
|
||||
'TopController@characters' => 'top_characters',
|
||||
'TopController@people' => 'top_people',
|
||||
'ReviewsController@bestVoted' => 'top_reviews',
|
||||
'TopController@anime' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_DEFAULT_EXPIRE')
|
||||
],
|
||||
'TopController@manga' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_DEFAULT_EXPIRE')
|
||||
],
|
||||
'TopController@characters' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_DEFAULT_EXPIRE')
|
||||
],
|
||||
'TopController@people' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_DEFAULT_EXPIRE')
|
||||
],
|
||||
'ReviewsController@bestVoted' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_DEFAULT_EXPIRE')
|
||||
],
|
||||
|
||||
'SearchController@anime' => 'search_anime',
|
||||
'SearchController@manga' => 'search_manga',
|
||||
'SearchController@character' => 'search_characters',
|
||||
'SearchController@people' => 'search_people',
|
||||
'SearchController@users' => 'search_users',
|
||||
'SearchController@userById' => 'search_users_by_id',
|
||||
'SearchController@anime' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_SEARCH_EXPIRE')
|
||||
],
|
||||
'SearchController@manga' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_SEARCH_EXPIRE')
|
||||
],
|
||||
'SearchController@character' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_SEARCH_EXPIRE')
|
||||
],
|
||||
'SearchController@people' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_SEARCH_EXPIRE')
|
||||
],
|
||||
'SearchController@users' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_SEARCH_EXPIRE')
|
||||
],
|
||||
'SearchController@userById' => [
|
||||
'table_name' => 'common',
|
||||
'ttl' => env('CACHE_SEARCH_EXPIRE')
|
||||
],
|
||||
|
||||
'ClubController@main' => [
|
||||
'table_name' => 'clubs',
|
||||
@ -198,11 +231,23 @@ return [
|
||||
'ttl' => env('CACHE_DEFAULT_EXPIRE')
|
||||
],
|
||||
|
||||
'ReviewsController@anime' => 'reviews',
|
||||
'ReviewsController@manga' => 'reviews',
|
||||
'ReviewsController@anime' => [
|
||||
'table_name' => 'reviews',
|
||||
'ttl' => env('CACHE_DEFAULT_EXPIRE')
|
||||
],
|
||||
'ReviewsController@manga' => [
|
||||
'table_name' => 'reviews',
|
||||
'ttl' => env('CACHE_DEFAULT_EXPIRE')
|
||||
],
|
||||
|
||||
'RecommendationsController@anime' => 'recommendations',
|
||||
'RecommendationsController@manga' => 'recommendations',
|
||||
'RecommendationsController@anime' => [
|
||||
'table_name' => 'recommendations',
|
||||
'ttl' => env('CACHE_DEFAULT_EXPIRE')
|
||||
],
|
||||
'RecommendationsController@manga' => [
|
||||
'table_name' => 'recommendations',
|
||||
'ttl' => env('CACHE_DEFAULT_EXPIRE')
|
||||
],
|
||||
|
||||
'WatchController@recentEpisodes' => [
|
||||
'table_name' => 'watch',
|
||||
|
Loading…
x
Reference in New Issue
Block a user