mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
add /club/{id}/staff
This commit is contained in:
parent
6544e0cf25
commit
488971b58e
@ -190,4 +190,89 @@ class ClubController extends Controller
|
||||
$request
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/clubs/{id}/staff",
|
||||
* operationId="getClubStaff",
|
||||
* tags={"clubs"},
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* name="id",
|
||||
* in="path",
|
||||
* required=true,
|
||||
* @OA\Schema(type="integer")
|
||||
* ),
|
||||
*
|
||||
* @OA\Response(
|
||||
* response="200",
|
||||
* description="Returns Club Staff",
|
||||
* @OA\JsonContent(
|
||||
* ref="#/components/schemas/club staff"
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="400",
|
||||
* description="Error: Bad request. When required parameters were not supplied.",
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function staff(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\ClubStaffResource(
|
||||
$results->first()
|
||||
))->response();
|
||||
|
||||
return $this->prepareResponse(
|
||||
$response,
|
||||
$results,
|
||||
$request
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -538,8 +538,10 @@ class SearchController extends Controller
|
||||
* @OA\Schema(
|
||||
* @OA\Property(
|
||||
* property="data",
|
||||
* type="object",
|
||||
* type="array",
|
||||
*
|
||||
* @OA\Items(
|
||||
* type="object",
|
||||
* @OA\Schema(
|
||||
* @OA\Property(
|
||||
* property="url",
|
||||
@ -552,9 +554,7 @@ class SearchController extends Controller
|
||||
* description="MyAnimeList Username"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="image_url",
|
||||
* type="string",
|
||||
* description="Image URL"
|
||||
* ref="#/components/schemas/user images"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="last_online",
|
||||
@ -564,6 +564,7 @@ class SearchController extends Controller
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* },
|
||||
* ),
|
||||
*/
|
||||
|
@ -136,7 +136,6 @@ class ClubResource extends JsonResource
|
||||
'category' => $this->category,
|
||||
'created' => $this->created,
|
||||
'type' => $this->type,
|
||||
'staff' => $this->staff,
|
||||
'anime_relations' => $this->anime_relations,
|
||||
'manga_relations' => $this->manga_relations,
|
||||
'character_relations' => $this->character_relations,
|
||||
|
47
app/Http/Resources/V4/ClubStaffResource.php
Normal file
47
app/Http/Resources/V4/ClubStaffResource.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\V4;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ClubStaffResource extends JsonResource
|
||||
{
|
||||
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="club staff",
|
||||
* description="Club Staff Resource",
|
||||
*
|
||||
* @OA\Property(
|
||||
* property="data",
|
||||
* type="array",
|
||||
*
|
||||
* @OA\Items(
|
||||
* type="object",
|
||||
*
|
||||
* @OA\Property(
|
||||
* property="url",
|
||||
* type="string",
|
||||
* description="User URL",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="username",
|
||||
* type="string",
|
||||
* description="User's username",
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return $this['staff'];
|
||||
}
|
||||
}
|
@ -394,6 +394,10 @@ $router->group(
|
||||
$router->get('/{id:[0-9]+}/members', [
|
||||
'uses' => 'ClubController@members'
|
||||
]);
|
||||
|
||||
$router->get('/{id:[0-9]+}/staff', [
|
||||
'uses' => 'ClubController@staff'
|
||||
]);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -779,6 +779,39 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/clubs/{id}/staff": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"clubs"
|
||||
],
|
||||
"operationId": "getClubStaff",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Returns Club Staff",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/club staff"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Error: Bad request. When required parameters were not supplied."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/genres/anime": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@ -3084,8 +3117,11 @@
|
||||
{
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
@ -4338,6 +4374,28 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"club staff": {
|
||||
"description": "Club Staff Resource",
|
||||
"properties": {
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"properties": {
|
||||
"url": {
|
||||
"description": "User URL",
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"description": "User's username",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"trailer": {
|
||||
"description": "Youtube Details",
|
||||
"type": "object",
|
||||
|
Loading…
x
Reference in New Issue
Block a user