From 348c13f318f4cc21169cfb9a13cce97112a8de97 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 1 Mar 2019 16:31:22 -0800 Subject: [PATCH] Add accessories endpoint to user API --- app/Http/Controllers/Api/UsersController.php | 18 ++++++++++++++++++ routes/api.php | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index cdf4d3be64..8783679b9b 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -12,6 +12,7 @@ use App\Http\Requests\SaveUserRequest; use App\Models\Asset; use App\Http\Transformers\AssetsTransformer; use App\Http\Transformers\SelectlistTransformer; +use App\Http\Transformers\AccessoriesTransformer; class UsersController extends Controller { @@ -302,6 +303,23 @@ class UsersController extends Controller return (new AssetsTransformer)->transformAssets($assets, $assets->count()); } + /** + * Return JSON containing a list of accessories assigned to a user. + * + * @author [A. Gianotto] [] + * @since [v4.6.14] + * @param $userId + * @return string JSON + */ + public function accessories($id) + { + $this->authorize('view', User::class); + $user = User::findOrFail($id); + $this->authorize('view', Accessory::class); + $accessories = $user->accessories; + return (new AccessoriesTransformer)->transformAccessories($accessories, $accessories->count()); + } + /** * Reset the user's two-factor status * diff --git a/routes/api.php b/routes/api.php index c66c388820..fffc46d55a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -715,6 +715,13 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { ] ); + Route::get('{user}/accessories', + [ + 'as' => 'api.users.accessorieslist', + 'uses' => 'UsersController@accessories' + ] + ); + Route::post('{user}/upload', [ 'as' => 'api.users.uploads',