From 34919b03969130da4947c352eb7f3a19e986e4e1 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 23 Mar 2018 14:50:11 -0700 Subject: [PATCH 1/2] Added API calls to look up assets by tag and serial --- app/Http/Controllers/Api/AssetsController.php | 39 +++++++++++++++++++ routes/api.php | 11 ++++++ 2 files changed, 50 insertions(+) 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' From 6043d37b056a278bb08503d55fd90d64611136e4 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 23 Mar 2018 16:19:26 -0700 Subject: [PATCH 2/2] Added the backup env flag to the example env --- .env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example b/.env.example index 32d1074ba5..170065491a 100644 --- a/.env.example +++ b/.env.example @@ -7,6 +7,7 @@ APP_KEY=ChangeMe APP_URL=null APP_TIMEZONE='UTC' APP_LOCALE=en +BACKUP_ENV=false # -------------------------------------------- # REQUIRED: DATABASE SETTINGS