diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 8abfab88a1..9bf8ff645d 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -274,6 +274,44 @@ class AssetsController extends Controller } + /** + * Returns JSON with information about an asset (by tag) for detail view. + * + * @author [A. Gianotto] [] + * @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] [] + * @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); } + } diff --git a/routes/api.php b/routes/api.php index 88c428c725..15dfe09998 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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'