Adds consumables endpoint to user API

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2022-02-22 20:44:34 -08:00
parent 0cfc0a4bee
commit dc2e6c2b06
2 changed files with 26 additions and 0 deletions

View file

@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
use App\Http\Requests\SaveUserRequest; use App\Http\Requests\SaveUserRequest;
use App\Http\Transformers\AccessoriesTransformer; use App\Http\Transformers\AccessoriesTransformer;
use App\Http\Transformers\AssetsTransformer; use App\Http\Transformers\AssetsTransformer;
use App\Http\Transformers\ConsumablesTransformer;
use App\Http\Transformers\LicensesTransformer; use App\Http\Transformers\LicensesTransformer;
use App\Http\Transformers\SelectlistTransformer; use App\Http\Transformers\SelectlistTransformer;
use App\Http\Transformers\UsersTransformer; use App\Http\Transformers\UsersTransformer;
@ -448,6 +449,24 @@ class UsersController extends Controller
return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request); return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request);
} }
/**
* Return JSON containing a list of consumables assigned to a user.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0]
* @param $userId
* @return string JSON
*/
public function consumables(Request $request, $id)
{
$this->authorize('view', User::class);
$this->authorize('view', Consumable::class);
$user = User::findOrFail($id);
$consumables = $user->consumables;
return (new ConsumablesTransformer)->transformConsumables($consumables, $consumables->count(), $request);
}
/** /**
* Return JSON containing a list of accessories assigned to a user. * Return JSON containing a list of accessories assigned to a user.
* *

View file

@ -858,6 +858,13 @@ Route::group(['prefix' => 'v1','namespace' => 'Api', 'middleware' => 'auth:api']
] ]
); );
Route::get('{user}/consumables',
[
'as' => 'api.users.consumablelist',
'uses' => 'UsersController@consumables'
]
);
Route::get('{user}/accessories', Route::get('{user}/accessories',
[ [