add /club/{id}/staff

This commit is contained in:
Irfan 2021-12-29 01:05:55 +05:00
parent 6544e0cf25
commit 488971b58e
6 changed files with 219 additions and 25 deletions

View File

@ -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
);
}
}

View File

@ -538,30 +538,31 @@ class SearchController extends Controller
* @OA\Schema(
* @OA\Property(
* property="data",
* type="object",
* type="array",
*
* @OA\Schema(
* @OA\Property(
* property="url",
* type="string",
* description="MyAnimeList URL"
* ),
* @OA\Property(
* property="username",
* type="string",
* description="MyAnimeList Username"
* ),
* @OA\Property(
* property="image_url",
* type="string",
* description="Image URL"
* ),
* @OA\Property(
* property="last_online",
* type="string",
* description="Last Online Date ISO8601"
* ),
* ),
* @OA\Items(
* type="object",
* @OA\Schema(
* @OA\Property(
* property="url",
* type="string",
* description="MyAnimeList URL"
* ),
* @OA\Property(
* property="username",
* type="string",
* description="MyAnimeList Username"
* ),
* @OA\Property(
* ref="#/components/schemas/user images"
* ),
* @OA\Property(
* property="last_online",
* type="string",
* description="Last Online Date ISO8601"
* ),
* ),
* ),
* ),
* ),
* },

View File

@ -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,

View 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'];
}
}

View File

@ -394,6 +394,10 @@ $router->group(
$router->get('/{id:[0-9]+}/members', [
'uses' => 'ClubController@members'
]);
$router->get('/{id:[0-9]+}/staff', [
'uses' => 'ClubController@staff'
]);
}
);

View File

@ -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,7 +3117,10 @@
{
"properties": {
"data": {
"type": "object"
"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",