anime, manga, user: adds new data #444 #426 #407

This commit is contained in:
Irfan 2022-07-07 01:10:04 +05:00
parent 91ced83394
commit b46c9c7f06
9 changed files with 492 additions and 157 deletions

View File

@ -23,6 +23,7 @@ use App\Http\Resources\V4\ResultsResource;
use App\Http\Resources\V4\ReviewsResource;
use App\Http\Resources\V4\AnimeStaffResource;
use App\Http\Resources\V4\AnimeStatisticsResource;
use App\Http\Resources\V4\StreamingLinksResource;
use App\Http\Resources\V4\UserUpdatesResource;
use App\Http\Resources\V4\AnimeVideosResource;
use App\Http\Resources\V4\CommonResource;
@ -229,7 +230,7 @@ class AnimeController extends Controller
* path="/anime/{id}/characters",
* operationId="getAnimeCharacters",
* tags={"anime"},
*
*
* @OA\Parameter(
* name="id",
* in="path",
@ -289,7 +290,7 @@ class AnimeController extends Controller
* required=true,
* @OA\Schema(type="integer")
* ),
*
*
* @OA\Response(
* response="200",
* description="Returns anime staff resource",
@ -465,14 +466,14 @@ class AnimeController extends Controller
* path="/anime/{id}/episodes/{episode}",
* operationId="getAnimeEpisodeById",
* tags={"anime"},
*
*
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* @OA\Schema(type="integer")
* ),
*
*
* @OA\Parameter(
* name="episode",
* in="path",
@ -529,7 +530,7 @@ class AnimeController extends Controller
* path="/anime/{id}/news",
* operationId="getAnimeNews",
* tags={"anime"},
*
*
* @OA\Parameter(
* name="id",
* in="path",
@ -597,14 +598,14 @@ class AnimeController extends Controller
* path="/anime/{id}/forum",
* operationId="getAnimeForum",
* tags={"anime"},
*
*
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* @OA\Schema(type="integer")
* ),
*
*
* @OA\Parameter(
* name="filter",
* in="query",
@ -664,7 +665,7 @@ class AnimeController extends Controller
* path="/anime/{id}/videos",
* operationId="getAnimeVideos",
* tags={"anime"},
*
*
* @OA\Parameter(
* name="id",
* in="path",
@ -717,7 +718,7 @@ class AnimeController extends Controller
* path="/anime/{id}/pictures",
* operationId="getAnimePictures",
* tags={"anime"},
*
*
* @OA\Parameter(
* name="id",
* in="path",
@ -738,7 +739,7 @@ class AnimeController extends Controller
* description="Error: Bad request. When required parameters were not supplied.",
* ),
* )
*
*
*/
public function pictures(Request $request, int $id)
{
@ -772,7 +773,7 @@ class AnimeController extends Controller
* path="/anime/{id}/statistics",
* operationId="getAnimeStatistics",
* tags={"anime"},
*
*
* @OA\Parameter(
* name="id",
* in="path",
@ -825,7 +826,7 @@ class AnimeController extends Controller
* path="/anime/{id}/moreinfo",
* operationId="getAnimeMoreInfo",
* tags={"anime"},
*
*
* @OA\Parameter(
* name="id",
* in="path",
@ -878,7 +879,7 @@ class AnimeController extends Controller
* path="/anime/{id}/recommendations",
* operationId="getAnimeRecommendations",
* tags={"anime"},
*
*
* @OA\Parameter(
* name="id",
* in="path",
@ -931,7 +932,7 @@ class AnimeController extends Controller
* path="/anime/{id}/userupdates",
* operationId="getAnimeUserUpdates",
* tags={"anime"},
*
*
* @OA\Parameter(
* name="id",
* in="path",
@ -1288,4 +1289,85 @@ class AnimeController extends Controller
$request
);
}
/**
* @OA\Get(
* path="/anime/{id}/streaming",
* operationId="getAnimeStreaming",
* tags={"anime"},
*
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* @OA\Schema(type="integer")
* ),
*
* @OA\Response(
* response="200",
* description="Returns anime streaming links",
* @OA\JsonContent(
* ref="#/components/schemas/external_links"
* )
* ),
* @OA\Response(
* response="400",
* description="Error: Bad request. When required parameters were not supplied.",
* ),
* )
*/
public function streaming(Request $request, int $id)
{
$results = Anime::query()
->where('mal_id', $id)
->get();
if (
$results->isEmpty()
|| $this->isExpired($request, $results)
) {
$response = Anime::scrape($id);
if ($results->isEmpty()) {
$meta = [
'createdAt' => new UTCDateTime(),
'modifiedAt' => new UTCDateTime(),
'request_hash' => $this->fingerprint
];
}
$meta['modifiedAt'] = new UTCDateTime();
$response = $meta + $response;
if ($results->isEmpty()) {
Anime::query()
->insert($response);
}
if ($this->isExpired($request, $results)) {
Anime::query()
->where('mal_id', $id)
->update($response);
}
$results = Anime::query()
->where('mal_id', $id)
->get();
}
if ($results->isEmpty()) {
return HttpResponse::notFound($request);
}
$response = (new StreamingLinksResource(
$results->first()
))->response();
return $this->prepareResponse(
$response,
$results,
$request
);
}
}

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\V4DB;
use App\Http\HttpResponse;
use App\Http\QueryBuilder\UserListQueryBuilder;
use App\Http\Resources\V4\ExternalLinksResource;
use App\Http\Resources\V4\ProfileHistoryResource;
use App\Http\Resources\V4\ResultsResource;
use App\Http\Resources\V4\UserProfileAnimeListCollection;
@ -23,6 +24,9 @@ use Jikan\Request\User\UserRecommendationsRequest;
use Jikan\Request\User\UserReviewsRequest;
use MongoDB\BSON\UTCDateTime;
/**
*
*/
class UserController extends Controller
{
@ -1119,6 +1123,96 @@ class UserController extends Controller
);
}
/**
* @OA\Get(
* path="/users/{username}/external",
* operationId="getUserExternal",
* tags={"users"},
*
* @OA\Parameter(
* name="username",
* in="path",
* required=true,
* @OA\Schema(type="string")
* ),
*
* @OA\Response(
* response="200",
* description="Returns user's external links",
* @OA\JsonContent(
* ref="#/components/schemas/external_links"
* )
* ),
*
* @OA\Response(
* response="400",
* description="Error: Bad request. When required parameters were not supplied.",
* ),
* ),
*/
public function external(Request $request, string $username)
{
$username = strtolower($username);
$results = Profile::query()
->where('internal_username', $username)
->get();
if (
$results->isEmpty()
|| $this->isExpired($request, $results)
) {
$response = Profile::scrape($username);
if ($results->isEmpty()) {
$meta = [
'createdAt' => new UTCDateTime(),
'modifiedAt' => new UTCDateTime(),
'request_hash' => $this->fingerprint,
'internal_username' => $username
];
}
$meta['modifiedAt'] = new UTCDateTime();
$response = $meta + $response;
if ($results->isEmpty()) {
Profile::query()
->insert($response);
}
if ($this->isExpired($request, $results)) {
Profile::query()
->where('internal_username', $username)
->update($response);
}
$results = Profile::query()
->where('internal_username', $username)
->get();
}
if ($results->isEmpty()) {
return HttpResponse::notFound($request);
}
$response = (new ExternalLinksResource(
$results->first()
))->response();
return $this->prepareResponse(
$response,
$results,
$request
);
}
/**
* @param Request $request
* @return mixed
* @throws \Jikan\Exception\BadResponseException
* @throws \Jikan\Exception\ParserException
*/
public function recentlyOnline(Request $request)
{
$results = DB::table($this->getRouteTable($request))
@ -1146,6 +1240,10 @@ class UserController extends Controller
);
}
/**
* @param string|null $status
* @return int
*/
private function listStatusToId(?string $status) : int
{
if (is_null($status)) {

View File

@ -30,21 +30,37 @@ class AnimeFullResource extends JsonResource
* ref="#/components/schemas/trailer_base"
* ),
* @OA\Property(
* property="approved",
* type="boolean",
* description="Whether the entry is pending approval on MAL or not"
* ),
* @OA\Property(
* property="titles",
* type="array",
* description="All titles",
* @OA\Items(
* type="string"
* )
* ),
* @OA\Property(
* property="title",
* type="string",
* description="Title"
* description="Title",
* deprecated=true
* ),
* @OA\Property(
* property="title_english",
* type="string",
* description="English Title",
* nullable=true
* nullable=true,
* deprecated=true
* ),
* @OA\Property(
* property="title_japanese",
* type="string",
* description="Japanese Title",
* nullable=true
* nullable=true,
* deprecated=true
* ),
* @OA\Property(
* property="title_synonyms",
@ -52,7 +68,8 @@ class AnimeFullResource extends JsonResource
* description="Other Titles",
* @OA\Items(
* type="string"
* )
* ),
* deprecated=true
* ),
* @OA\Property(
* property="type",
@ -283,6 +300,24 @@ class AnimeFullResource extends JsonResource
* ),
* ),
* ),
*
* @OA\Property(
* property="streaming",
* type="array",
*
* @OA\Items(
* type="object",
*
* @OA\Property(
* property="name",
* type="string",
* ),
* @OA\Property(
* property="url",
* type="string",
* ),
* ),
* ),
* )
*/
@ -299,6 +334,8 @@ class AnimeFullResource extends JsonResource
'url' => $this->url,
'images' => $this->images,
'trailer' => $this->trailer,
'approved' => $this->approved ?? true,
'titles' => $this->titles ?? [],
'title' => $this->title,
'title_english' => $this->title_english,
'title_japanese' => $this->title_japanese,
@ -335,6 +372,7 @@ class AnimeFullResource extends JsonResource
'endings' => $this->ending_themes
],
'external' => $this->external_links,
'streaming' => $this->streaming_links,
];
}
}

View File

@ -30,21 +30,37 @@ class AnimeResource extends JsonResource
* ref="#/components/schemas/trailer_base"
* ),
* @OA\Property(
* property="approved",
* type="boolean",
* description="Whether the entry is pending approval on MAL or not"
* ),
* @OA\Property(
* property="titles",
* type="array",
* description="All titles",
* @OA\Items(
* type="string"
* )
* ),
* @OA\Property(
* property="title",
* type="string",
* description="Title"
* description="Title",
* deprecated=true
* ),
* @OA\Property(
* property="title_english",
* type="string",
* description="English Title",
* nullable=true
* nullable=true,
* deprecated=true
* ),
* @OA\Property(
* property="title_japanese",
* type="string",
* description="Japanese Title",
* nullable=true
* nullable=true,
* deprecated=true
* ),
* @OA\Property(
* property="title_synonyms",
@ -52,7 +68,8 @@ class AnimeResource extends JsonResource
* description="Other Titles",
* @OA\Items(
* type="string"
* )
* ),
* deprecated=true
* ),
* @OA\Property(
* property="type",
@ -240,6 +257,8 @@ class AnimeResource extends JsonResource
'url' => $this->url,
'images' => $this->images,
'trailer' => $this->trailer,
'approved' => $this->approved ?? true,
'titles' => $this->titles ?? [],
'title' => $this->title,
'title_english' => $this->title_english,
'title_japanese' => $this->title_japanese,

View File

@ -26,21 +26,37 @@ class MangaFullResource extends JsonResource
* ref="#/components/schemas/manga_images"
* ),
* @OA\Property(
* property="approved",
* type="boolean",
* description="Whether the entry is pending approval on MAL or not"
* ),
* @OA\Property(
* property="titles",
* type="array",
* description="All Titles",
* @OA\Items(
* type="string"
* )
* ),
* @OA\Property(
* property="title",
* type="string",
* description="Title"
* description="Title",
* deprecated=true
* ),
* @OA\Property(
* property="title_english",
* type="string",
* description="English Title",
* nullable=true
* nullable=true,
* deprecated=true
* ),
* @OA\Property(
* property="title_japanese",
* type="string",
* description="Japanese Title",
* nullable=true
* nullable=true,
* deprecated=true
* ),
* @OA\Property(
* property="title_synonyms",
@ -48,7 +64,8 @@ class MangaFullResource extends JsonResource
* description="Other Titles",
* @OA\Items(
* type="string"
* )
* ),
* deprecated=true
* ),
* @OA\Property(
* property="type",
@ -234,6 +251,8 @@ class MangaFullResource extends JsonResource
'mal_id' => $this->mal_id,
'url' => $this->url,
'images' => $this->images,
'approved' => $this->approved ?? true,
'titles' => $this->titles ?? [],
'title' => $this->title,
'title_english' => $this->title_english,
'title_japanese' => $this->title_japanese,
@ -263,4 +282,4 @@ class MangaFullResource extends JsonResource
'external' => $this->external_links,
];
}
}
}

View File

@ -26,29 +26,37 @@ class MangaResource extends JsonResource
* ref="#/components/schemas/manga_images"
* ),
* @OA\Property(
* property="approved",
* type="boolean",
* description="Whether the entry is pending approval on MAL or not"
* ),
* @OA\Property(
* property="titles",
* type="array",
* description="All Titles",
* @OA\Items(
* type="string"
* )
* ),
* @OA\Property(
* property="title",
* type="string",
* description="Title"
* description="Title",
* deprecated=true
* ),
* @OA\Property(
* property="title_english",
* type="string",
* description="English Title",
* nullable=true
* nullable=true,
* deprecated=true
* ),
* @OA\Property(
* property="title_japanese",
* type="string",
* description="Japanese Title",
* nullable=true
* ),
* @OA\Property(
* property="title_synonyms",
* type="array",
* description="Other Titles",
* @OA\Items(
* type="string"
* )
* nullable=true,
* deprecated=true
* ),
* @OA\Property(
* property="type",
@ -194,6 +202,8 @@ class MangaResource extends JsonResource
'mal_id' => $this->mal_id,
'url' => $this->url,
'images' => $this->images,
'approved' => $this->approved ?? true,
'titles' => $this->titles ?? [],
'title' => $this->title,
'title_english' => $this->title_english,
'title_japanese' => $this->title_japanese,
@ -221,4 +231,4 @@ class MangaResource extends JsonResource
'demographics' => $this->demographics,
];
}
}
}

View File

@ -68,128 +68,143 @@ class ProfileFullResource extends JsonResource
* description="Joined Date ISO8601",
* nullable=true
* ),
*
* @OA\Property(
* property="statistics",
* type="object",
* @OA\Property(
* property="anime",
* type="object",
* description="Anime Statistics",
* @OA\Property(
* property="anime",
* type="object",
* description="Anime Statistics",
* @OA\Property(
* property="days_watched",
* type="number",
* format="float",
* description="Number of days spent watching Anime"
* ),
* @OA\Property(
* property="mean_score",
* type="number",
* format="float",
* description="Mean Score"
* ),
* @OA\Property(
* property="watching",
* type="integer",
* description="Anime Watching"
* ),
* @OA\Property(
* property="completed",
* type="integer",
* description="Anime Completed"
* ),
* @OA\Property(
* property="on_hold",
* type="integer",
* description="Anime On-Hold"
* ),
* @OA\Property(
* property="dropped",
* type="integer",
* description="Anime Dropped"
* ),
* @OA\Property(
* property="plan_to_watch",
* type="integer",
* description="Anime Planned to Watch"
* ),
* @OA\Property(
* property="total_entries",
* type="integer",
* description="Total Anime entries on User list"
* ),
* @OA\Property(
* property="rewatched",
* type="integer",
* description="Anime re-watched"
* ),
* @OA\Property(
* property="episodes_watched",
* type="integer",
* description="Number of Anime Episodes Watched"
* ),
* property="days_watched",
* type="number",
* format="float",
* description="Number of days spent watching Anime"
* ),
* @OA\Property(
* property="manga",
* type="object",
* description="Manga Statistics",
* @OA\Property(
* property="days_read",
* type="number",
* format="float",
* description="Number of days spent reading Manga"
* ),
* @OA\Property(
* property="mean_score",
* type="number",
* format="float",
* description="Mean Score"
* ),
* @OA\Property(
* property="reading",
* type="integer",
* description="Manga Reading"
* ),
* @OA\Property(
* property="completed",
* type="integer",
* description="Manga Completed"
* ),
* @OA\Property(
* property="on_hold",
* type="integer",
* description="Manga On-Hold"
* ),
* @OA\Property(
* property="dropped",
* type="integer",
* description="Manga Dropped"
* ),
* @OA\Property(
* property="plan_to_read",
* type="integer",
* description="Manga Planned to Read"
* ),
* @OA\Property(
* property="total_entries",
* type="integer",
* description="Total Manga entries on User list"
* ),
* @OA\Property(
* property="reread",
* type="integer",
* description="Manga re-read"
* ),
* @OA\Property(
* property="chapters_read",
* type="integer",
* description="Number of Manga Chapters Read"
* ),
* @OA\Property(
* property="volumes_read",
* type="integer",
* description="Number of Manga Volumes Read"
* ),
* property="mean_score",
* type="number",
* format="float",
* description="Mean Score"
* ),
* @OA\Property(
* property="watching",
* type="integer",
* description="Anime Watching"
* ),
* @OA\Property(
* property="completed",
* type="integer",
* description="Anime Completed"
* ),
* @OA\Property(
* property="on_hold",
* type="integer",
* description="Anime On-Hold"
* ),
* @OA\Property(
* property="dropped",
* type="integer",
* description="Anime Dropped"
* ),
* @OA\Property(
* property="plan_to_watch",
* type="integer",
* description="Anime Planned to Watch"
* ),
* @OA\Property(
* property="total_entries",
* type="integer",
* description="Total Anime entries on User list"
* ),
* @OA\Property(
* property="rewatched",
* type="integer",
* description="Anime re-watched"
* ),
* @OA\Property(
* property="episodes_watched",
* type="integer",
* description="Number of Anime Episodes Watched"
* ),
* ),
* @OA\Property(
* property="manga",
* type="object",
* description="Manga Statistics",
* @OA\Property(
* property="days_read",
* type="number",
* format="float",
* description="Number of days spent reading Manga"
* ),
* @OA\Property(
* property="mean_score",
* type="number",
* format="float",
* description="Mean Score"
* ),
* @OA\Property(
* property="reading",
* type="integer",
* description="Manga Reading"
* ),
* @OA\Property(
* property="completed",
* type="integer",
* description="Manga Completed"
* ),
* @OA\Property(
* property="on_hold",
* type="integer",
* description="Manga On-Hold"
* ),
* @OA\Property(
* property="dropped",
* type="integer",
* description="Manga Dropped"
* ),
* @OA\Property(
* property="plan_to_read",
* type="integer",
* description="Manga Planned to Read"
* ),
* @OA\Property(
* property="total_entries",
* type="integer",
* description="Total Manga entries on User list"
* ),
* @OA\Property(
* property="reread",
* type="integer",
* description="Manga re-read"
* ),
* @OA\Property(
* property="chapters_read",
* type="integer",
* description="Number of Manga Chapters Read"
* ),
* @OA\Property(
* property="volumes_read",
* type="integer",
* description="Number of Manga Volumes Read"
* ),
* ),
* ),
* @OA\Property(
* property="external",
* type="array",
*
* @OA\Items(
* type="object",
*
* @OA\Property(
* property="name",
* type="string",
* ),
* @OA\Property(
* property="url",
* type="string",
* ),
* ),
* ),
@ -215,6 +230,7 @@ class ProfileFullResource extends JsonResource
'favorites' => $this->favorites,
'updates' => $this->last_updates,
'about' => $this->about,
'external' => $this->external_links
];
}
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\Http\Resources\V4;
use Illuminate\Http\Resources\Json\JsonResource;
class StreamingLinksResource extends JsonResource
{
/**
* @OA\Schema(
* schema="streaming_links",
* description="Streaming links",
*
* @OA\Property(
* property="data",
* type="array",
*
* @OA\Items(
* type="object",
*
* @OA\Property(
* property="name",
* type="string",
* ),
* @OA\Property(
* property="url",
* type="string",
* ),
* ),
* ),
* )
*/
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return $this->streaming_links;
}
}

View File

@ -102,6 +102,10 @@ $router->group(
$router->get('/external', [
'uses' => 'AnimeController@external'
]);
$router->get('/streaming', [
'uses' => 'AnimeController@streaming'
]);
}
);
@ -363,6 +367,10 @@ $router->group(
$router->get('/clubs', [
'uses' => 'UserController@clubs'
]);
$router->get('/external', [
'uses' => 'UserController@external'
]);
}
);
}
@ -534,4 +542,4 @@ $router->group(
'uses' => 'InsightsController@trends'
]);
}
);
);