Skip to content

Commit

Permalink
feat(api): recover specific asset lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
warlof committed Aug 24, 2020
1 parent ac3bd05 commit cd4ab85
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
17 changes: 14 additions & 3 deletions src/Http/Controllers/Api/v2/CharacterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ class CharacterController extends ApiController
* ),
* in="path"
* ),
* @OA\Parameter(
* name="item_id",
* description="Specific Item ID",
* @OA\Schema(
* type="integer"
* ),
* in="query"
* ),
* @OA\Response(response=200, description="Successful operation",
* @OA\JsonContent(
* type="object",
Expand Down Expand Up @@ -102,10 +110,13 @@ class CharacterController extends ApiController
*/
public function getAssets(int $character_id)
{
$query = CharacterAsset::with('type')
->where('character_id', $character_id);

return Resource::collection(CharacterAsset::with('type')
->where('character_id', $character_id)
->paginate());
if (request()->exists('item_id'))
$query->where('item_id', request()->query('item_id'));

return Resource::collection($query->paginate());
}

/**
Expand Down
17 changes: 14 additions & 3 deletions src/Http/Controllers/Api/v2/CorporationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ class CorporationController extends ApiController
* ),
* in="path"
* ),
* @OA\Parameter(
* name="item_id",
* description="Specific Item ID",
* @OA\Schema(
* type="integer"
* ),
* in="query"
* ),
* @OA\Response(response=200, description="Successful operation",
* @OA\JsonContent(
* type="object",
Expand Down Expand Up @@ -92,10 +100,13 @@ class CorporationController extends ApiController
*/
public function getAssets(int $corporation_id)
{
$query = CorporationAsset::with('type')
->where('corporation_id', $corporation_id);

return Resource::collection(CorporationAsset::with('type')
->where('corporation_id', $corporation_id)
->paginate());
if (request()->exists('item_id'))
$query->where('item_id', request()->query('item_id'));

return Resource::collection($query->paginate());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

Route::group(['prefix' => 'character'], function () {

Route::get('/assets/{character_id}/{item_id?}')->uses('CharacterController@getAssets');
Route::get('/assets/{character_id}')->uses('CharacterController@getAssets');
Route::get('/bookmarks/{character_id}')->uses('CharacterController@getBookmarks');
Route::get('/contacts/{character_id}')->uses('CharacterController@getContacts');
Route::get('/industry/{character_id}')->uses('CharacterController@getIndustry');
Expand Down

0 comments on commit cd4ab85

Please sign in to comment.