mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
add /club/{id}/relations
This commit is contained in:
parent
488971b58e
commit
1384d02c2a
@ -275,4 +275,89 @@ class ClubController extends Controller
|
||||
$request
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/clubs/{id}/relations",
|
||||
* operationId="getClubRelations",
|
||||
* tags={"clubs"},
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* required=true,
|
||||
* @OA\Schema(type="integer")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response="200",
|
||||
* description="Returns Club Relations",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/club relations"
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="400",
|
||||
* description="Error: Bad request. When required parameters were not supplied.",
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function relations(Request $request, int $id)
|
||||
{
|
||||
$results = Club::query()
|
||||
->where('mal_id', $id)
|
||||
->get();
|
||||
|
||||
if (
|
||||
$results->isEmpty()
|
||||
|| $this->isExpired($request, $results)
|
||||
) {
|
||||
$response = Club::scrape($id);
|
||||
|
||||
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()) {
|
||||
Club::query()
|
||||
->insert($response);
|
||||
}
|
||||
|
||||
if ($this->isExpired($request, $results)) {
|
||||
Club::query()
|
||||
->where('mal_id', $id)
|
||||
->update($response);
|
||||
}
|
||||
|
||||
$results = Club::query()
|
||||
->where('mal_id', $id)
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
return HttpResponse::notFound($request);
|
||||
}
|
||||
|
||||
$response = (new \App\Http\Resources\V4\ClubRelationsResource(
|
||||
$results->first()
|
||||
))->response();
|
||||
|
||||
return $this->prepareResponse(
|
||||
$response,
|
||||
$results,
|
||||
$request
|
||||
);
|
||||
}
|
||||
}
|
||||
|
69
app/Http/Resources/V4/ClubRelationsResource.php
Normal file
69
app/Http/Resources/V4/ClubRelationsResource.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\V4;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ClubRelationsResource extends JsonResource
|
||||
{
|
||||
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="club relations",
|
||||
* description="Club Relations",
|
||||
*
|
||||
* @OA\Property(
|
||||
* property="data",
|
||||
* type="object",
|
||||
*
|
||||
* @OA\Property(
|
||||
* property="anime",
|
||||
* type="array",
|
||||
* @OA\Items(
|
||||
* type="object",
|
||||
* @OA\Property(
|
||||
* ref="#/components/schemas/mal_url"
|
||||
* )
|
||||
* ),
|
||||
* ),
|
||||
*
|
||||
* @OA\Property(
|
||||
* property="manga",
|
||||
* type="array",
|
||||
* @OA\Items(
|
||||
* type="object",
|
||||
* @OA\Property(
|
||||
* ref="#/components/schemas/mal_url"
|
||||
* )
|
||||
* ),
|
||||
* ),
|
||||
*
|
||||
* @OA\Property(
|
||||
* property="characters",
|
||||
* type="array",
|
||||
* @OA\Items(
|
||||
* type="object",
|
||||
* @OA\Property(
|
||||
* ref="#/components/schemas/mal_url"
|
||||
* )
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'anime' => $this['anime'],
|
||||
'manga' => $this['manga'],
|
||||
'characters' => $this['characters'],
|
||||
];
|
||||
}
|
||||
}
|
@ -26,40 +26,30 @@ class ClubResource extends JsonResource
|
||||
* description="MyAnimeList ID"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="name",
|
||||
* type="string",
|
||||
* description="Club name"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="url",
|
||||
* type="string",
|
||||
* description="MyAnimeList URL"
|
||||
* description="Club URL"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="images",
|
||||
* type="object",
|
||||
* description="Images",
|
||||
* @OA\Property(
|
||||
* property="jpg",
|
||||
* type="object",
|
||||
* description="Available images in JPG",
|
||||
* @OA\Property(
|
||||
* property="image_url",
|
||||
* type="string",
|
||||
* description="Image URL JPG (225x335)",
|
||||
* ),
|
||||
* ),
|
||||
* ref="#/components/schemas/common images",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="members_count",
|
||||
* property="members",
|
||||
* type="integer",
|
||||
* description="Number of club members"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="pictures_count",
|
||||
* type="integer",
|
||||
* description="Number of club pictures"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="category",
|
||||
* type="string",
|
||||
* description="Club Category",
|
||||
* enum={"Actors & Artists", "Anime", "Characters", "Cities & Neighborhoods", "Companies", "Conventions", "Games", "Japan", "Manga", "Music", "Others", "Schools"}
|
||||
* enum={"actors & artists", "anime", "characters", "cities & neighborhoods", "companies", "conventions", "games", "japan", "manga", "music", "others", "schools"}
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="created",
|
||||
@ -67,60 +57,11 @@ class ClubResource extends JsonResource
|
||||
* description="Date Created ISO8601"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="type",
|
||||
* property="access",
|
||||
* type="string",
|
||||
* description="Type",
|
||||
* description="Club access",
|
||||
* enum={"public", "private", "secret"}
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="staff",
|
||||
* type="array",
|
||||
* description="Staff members",
|
||||
* @OA\Items(
|
||||
* type="object",
|
||||
* description="Staff member",
|
||||
* @OA\Property(
|
||||
* property="url",
|
||||
* type="string",
|
||||
* description="MyAnimeList URL"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="username",
|
||||
* type="string",
|
||||
* description="MyAnimeList Username"
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="anime_relations",
|
||||
* type="array",
|
||||
* description="Anime Relations",
|
||||
* @OA\Items(
|
||||
* type="object",
|
||||
* description="Resource",
|
||||
* ref="#/components/schemas/mal_url"
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="manga_relations",
|
||||
* type="array",
|
||||
* description="Manga Relations",
|
||||
* @OA\Items(
|
||||
* type="object",
|
||||
* description="Resource",
|
||||
* ref="#/components/schemas/mal_url"
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="character_relations",
|
||||
* type="array",
|
||||
* description="Character Relations",
|
||||
* @OA\Items(
|
||||
* type="object",
|
||||
* description="Resource",
|
||||
* ref="#/components/schemas/mal_url"
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
*/
|
||||
@ -129,16 +70,12 @@ class ClubResource extends JsonResource
|
||||
return [
|
||||
'mal_id' => $this->mal_id,
|
||||
'url' => $this->url,
|
||||
'images' => $this->image,
|
||||
'title' => $this->title,
|
||||
'members_count' => $this->members_count,
|
||||
'pictures_count' => $this->pictures_count,
|
||||
'images' => $this->images,
|
||||
'name' => $this->name,
|
||||
'members' => $this->members,
|
||||
'category' => $this->category,
|
||||
'created' => $this->created,
|
||||
'type' => $this->type,
|
||||
'anime_relations' => $this->anime_relations,
|
||||
'manga_relations' => $this->manga_relations,
|
||||
'character_relations' => $this->character_relations,
|
||||
'access' => $this->access,
|
||||
];
|
||||
}
|
||||
}
|
8
composer.lock
generated
8
composer.lock
generated
@ -2932,12 +2932,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jikan-me/jikan.git",
|
||||
"reference": "da951a70678e173abc0bd29351ca814131f553b1"
|
||||
"reference": "70ea41605c5437c6f4b6205e75099b26f78dc77d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/jikan-me/jikan/zipball/da951a70678e173abc0bd29351ca814131f553b1",
|
||||
"reference": "da951a70678e173abc0bd29351ca814131f553b1",
|
||||
"url": "https://api.github.com/repos/jikan-me/jikan/zipball/70ea41605c5437c6f4b6205e75099b26f78dc77d",
|
||||
"reference": "70ea41605c5437c6f4b6205e75099b26f78dc77d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2986,7 +2986,7 @@
|
||||
"type": "patreon"
|
||||
}
|
||||
],
|
||||
"time": "2021-12-27T20:23:43+00:00"
|
||||
"time": "2021-12-28T19:59:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jms/metadata",
|
||||
|
@ -398,6 +398,10 @@ $router->group(
|
||||
$router->get('/{id:[0-9]+}/staff', [
|
||||
'uses' => 'ClubController@staff'
|
||||
]);
|
||||
|
||||
$router->get('/{id:[0-9]+}/relations', [
|
||||
'uses' => 'ClubController@relations'
|
||||
]);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -812,6 +812,39 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/clubs/{id}/relations": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"clubs"
|
||||
],
|
||||
"operationId": "getClubRelations",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Returns Club Relations",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/club relations"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Error: Bad request. When required parameters were not supplied."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/genres/anime": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@ -4261,6 +4294,50 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"club relations": {
|
||||
"description": "Club Relations",
|
||||
"properties": {
|
||||
"data": {
|
||||
"properties": {
|
||||
"anime": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"properties": {
|
||||
"": {
|
||||
"$ref": "#/components/schemas/mal_url"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"manga": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"properties": {
|
||||
"": {
|
||||
"$ref": "#/components/schemas/mal_url"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"characters": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"properties": {
|
||||
"": {
|
||||
"$ref": "#/components/schemas/mal_url"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"club": {
|
||||
"description": "Club Resource",
|
||||
"properties": {
|
||||
@ -4270,103 +4347,51 @@
|
||||
"description": "MyAnimeList ID",
|
||||
"type": "integer"
|
||||
},
|
||||
"name": {
|
||||
"description": "Club name",
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"description": "MyAnimeList URL",
|
||||
"description": "Club URL",
|
||||
"type": "string"
|
||||
},
|
||||
"images": {
|
||||
"description": "Images",
|
||||
"properties": {
|
||||
"jpg": {
|
||||
"description": "Available images in JPG",
|
||||
"properties": {
|
||||
"image_url": {
|
||||
"description": "Image URL JPG (225x335)",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
"$ref": "#/components/schemas/common images"
|
||||
},
|
||||
"members_count": {
|
||||
"members": {
|
||||
"description": "Number of club members",
|
||||
"type": "integer"
|
||||
},
|
||||
"pictures_count": {
|
||||
"description": "Number of club pictures",
|
||||
"type": "integer"
|
||||
},
|
||||
"category": {
|
||||
"description": "Club Category",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Actors & Artists",
|
||||
"Anime",
|
||||
"Characters",
|
||||
"Cities & Neighborhoods",
|
||||
"Companies",
|
||||
"Conventions",
|
||||
"Games",
|
||||
"Japan",
|
||||
"Manga",
|
||||
"Music",
|
||||
"Others",
|
||||
"Schools"
|
||||
"actors & artists",
|
||||
"anime",
|
||||
"characters",
|
||||
"cities & neighborhoods",
|
||||
"companies",
|
||||
"conventions",
|
||||
"games",
|
||||
"japan",
|
||||
"manga",
|
||||
"music",
|
||||
"others",
|
||||
"schools"
|
||||
]
|
||||
},
|
||||
"created": {
|
||||
"description": "Date Created ISO8601",
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"description": "Type",
|
||||
"access": {
|
||||
"description": "Club access",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"public",
|
||||
"private",
|
||||
"secret"
|
||||
]
|
||||
},
|
||||
"staff": {
|
||||
"description": "Staff members",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"description": "Staff member",
|
||||
"properties": {
|
||||
"url": {
|
||||
"description": "MyAnimeList URL",
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"description": "MyAnimeList Username",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"anime_relations": {
|
||||
"description": "Anime Relations",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/mal_url"
|
||||
}
|
||||
},
|
||||
"manga_relations": {
|
||||
"description": "Manga Relations",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/mal_url"
|
||||
}
|
||||
},
|
||||
"character_relations": {
|
||||
"description": "Character Relations",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/mal_url"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
|
Loading…
x
Reference in New Issue
Block a user