Added API calls to look up assets by tag and serial

This commit is contained in:
snipe 2018-03-23 14:50:11 -07:00
parent c4c137dc08
commit 34919b0396
2 changed files with 50 additions and 0 deletions

View file

@ -274,6 +274,44 @@ class AssetsController extends Controller
}
/**
* Returns JSON with information about an asset (by tag) for detail view.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param string $tag
* @since [v4.2.1]
* @return JsonResponse
*/
public function showByTag($tag)
{
if ($asset = Asset::with('assetstatus')->with('assignedTo')->withTrashed()->where('asset_tag',$tag)->first()) {
$this->authorize('view', $asset);
return (new AssetsTransformer)->transformAsset($asset);
}
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 404);
}
/**
* Returns JSON with information about an asset (by serial) for detail view.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param string $serial
* @since [v4.2.1]
* @return JsonResponse
*/
public function showBySerial($serial)
{
if ($assets = Asset::with('assetstatus')->with('assignedTo')
->withTrashed()->where('serial',$serial)->get()) {
$this->authorize('view', $assets);
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
}
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 404);
}
/**
* Returns JSON with information about an asset for detail view.
*
@ -289,6 +327,7 @@ class AssetsController extends Controller
return (new AssetsTransformer)->transformAsset($asset);
}
}

View file

@ -283,6 +283,17 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
Route::group(['prefix' => 'hardware'], function () {
Route::get( 'bytag/{tag}', [
'as' => 'assets.show.bytag',
'uses' => 'AssetsController@showByTag'
]);
Route::get( 'byserial/{serial}', [
'as' => 'assets.show.byserial',
'uses' => 'AssetsController@showBySerial'
]);
Route::get( 'selectlist', [
'as' => 'assets.selectlist',
'uses' => 'AssetsController@selectlist'