-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api\V2\SC; | ||
|
||
use App\Http\Controllers\Api\V2\AbstractApiV2Controller; | ||
use App\Http\Resources\SC\Mission\GiverLinkResource; | ||
use App\Http\Resources\SC\Mission\GiverResource; | ||
use App\Models\SC\Mission\Giver; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
use Illuminate\Support\Facades\Validator; | ||
use OpenApi\Attributes as OA; | ||
use Spatie\QueryBuilder\QueryBuilder; | ||
|
||
class MissionGiverController extends AbstractApiV2Controller | ||
{ | ||
#[OA\Get( | ||
path: '/api/v2/missions-givers', | ||
tags: ['In-Game', 'Missions'], | ||
parameters: [ | ||
new OA\Parameter(ref: '#/components/parameters/page'), | ||
new OA\Parameter(ref: '#/components/parameters/limit'), | ||
], | ||
responses: [ | ||
new OA\Response( | ||
response: 200, | ||
description: 'List of Mission Givers', | ||
content: new OA\JsonContent( | ||
type: 'array', | ||
items: new OA\Items(ref: '#/components/schemas/mission_giver_link_v2') | ||
) | ||
), | ||
] | ||
)] | ||
public function index(Request $request): AnonymousResourceCollection | ||
{ | ||
$query = QueryBuilder::for(Giver::class, $request) | ||
->paginate($this->limit) | ||
->appends(request()->query()); | ||
|
||
return GiverLinkResource::collection($query); | ||
} | ||
|
||
#[OA\Get( | ||
path: '/api/v2/mission-givers/{giver}', | ||
tags: ['In-Game', 'Missions'], | ||
parameters: [ | ||
new OA\Parameter(ref: '#/components/parameters/locale'), | ||
new OA\Parameter( | ||
name: 'giver', | ||
in: 'path', | ||
required: true, | ||
schema: new OA\Schema( | ||
description: 'Mission Giver UUID', | ||
type: 'string', | ||
), | ||
), | ||
], | ||
responses: [ | ||
new OA\Response( | ||
response: 200, | ||
description: 'A Mission Giver', | ||
content: new OA\JsonContent( | ||
type: 'array', | ||
items: new OA\Items(ref: '#/components/schemas/mission_giver_v2') | ||
) | ||
), | ||
] | ||
)] | ||
public function show(Request $request): JsonResource | ||
{ | ||
['giver' => $identifier] = Validator::validate( | ||
[ | ||
'giver' => $request->giver, | ||
], | ||
[ | ||
'giver' => 'required|uuid', | ||
] | ||
); | ||
|
||
$model = QueryBuilder::for(Giver::class, $request) | ||
->where('uuid', $identifier) | ||
->with([ | ||
'missions', | ||
]) | ||
->firstOrFail(); | ||
|
||
return new GiverResource($model); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources\SC\Mission; | ||
|
||
use App\Http\Resources\AbstractTranslationResource; | ||
use Illuminate\Http\Request; | ||
use OpenApi\Attributes as OA; | ||
|
||
#[OA\Schema( | ||
schema: 'mission_giver_link_v2', | ||
title: 'Mission Giver Link', | ||
properties: [ | ||
new OA\Property(property: 'uuid', type: 'string', nullable: true), | ||
new OA\Property(property: 'name', type: 'string', nullable: true), | ||
new OA\Property(property: 'link', type: 'string', nullable: true), | ||
], | ||
type: 'object' | ||
)] | ||
class GiverLinkResource extends AbstractTranslationResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
'uuid' => $this->uuid, | ||
'name' => $this->name, | ||
'link' => $this->makeApiUrl(self::MISSION_GIVERS_SHOW, $this->uuid), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters