mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
Added API calls to look up assets by tag and serial
This commit is contained in:
parent
c4c137dc08
commit
34919b0396
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue