Commit a99a8018 authored by cygnet's avatar cygnet

Refactoring done on api/roles controller

parent ee136503
...@@ -22,26 +22,29 @@ class RolesController extends APIController ...@@ -22,26 +22,29 @@ class RolesController extends APIController
$this->repository = $repository; $this->repository = $repository;
} }
/** /**
* Return the users. * Return the roles.
* *
* @return \Illuminate\Http\Response * @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/ */
public function index(Request $request) public function index(Request $request)
{ {
$limit = $request->get('paginate') ? $request->get('paginate') : 25; $limit = $request->get('paginate') ? $request->get('paginate') : 25;
return RoleResource::collection( return RoleResource::collection(
$this->repository->getPaginated($limit) $this->repository->getForDataTable()->paginate($limit)
); );
} }
/** /**
* Return the specified resource. * Return the specified resource.
* *
* @param User $user * @param Role $role
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\JsonResponse
*/ */
public function show(Role $role) public function show(Role $role)
{ {
...@@ -49,7 +52,7 @@ class RolesController extends APIController ...@@ -49,7 +52,7 @@ class RolesController extends APIController
} }
/** /**
* Creates the Resourse for Role. * Creates the Resource for Role.
* *
* @param Request $request * @param Request $request
* *
...@@ -57,7 +60,7 @@ class RolesController extends APIController ...@@ -57,7 +60,7 @@ class RolesController extends APIController
*/ */
public function store(Request $request) public function store(Request $request)
{ {
$validation = $this->validatingRequest($request); $validation = $this->validateRole($request);
if ($validation->fails()) { if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first()); return $this->throwValidation($validation->messages()->first());
} }
...@@ -68,14 +71,16 @@ class RolesController extends APIController ...@@ -68,14 +71,16 @@ class RolesController extends APIController
} }
/** /**
* Update User.
*
* @param Request $request
* @param Role $role * @param Role $role
* @param UpdateRoleRequest $request
* *
* @return mixed * @return \Illuminate\Http\JsonResponse
*/ */
public function update(Request $request, Role $role) public function update(Request $request, Role $role)
{ {
$validation = $this->validatingRequest($request); $validation = $this->validateRole($request);
if ($validation->fails()) { if ($validation->fails()) {
return $this->throwValidation($validation->messages()->first()); return $this->throwValidation($validation->messages()->first());
...@@ -88,7 +93,30 @@ class RolesController extends APIController ...@@ -88,7 +93,30 @@ class RolesController extends APIController
return new RoleResource($role); return new RoleResource($role);
} }
public function validatingRequest(Request $request) /**
* @param Role $role
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function destroy(Role $role, Request $request)
{
$this->repository->delete($role);
return $this->respond([
'message' => trans('alerts.backend.roles.deleted'),
]);
}
/**
* validateUser User.
*
* @param $request
*
* @return Validator object
*/
public function validateRole(Request $request)
{ {
$permissions = ''; $permissions = '';
...@@ -103,17 +131,4 @@ class RolesController extends APIController ...@@ -103,17 +131,4 @@ class RolesController extends APIController
return $validation; return $validation;
} }
/**
* @param Role $role
* @param DeleteRoleRequest $request
*
* @return mixed
*/
public function destroy(Role $role, Request $request)
{
$this->repository->delete($role);
return ['message'=>'success'];
}
} }
...@@ -27,17 +27,14 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio ...@@ -27,17 +27,14 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
Route::post('password/email', 'ForgotPasswordController@sendResetLinkEmail'); Route::post('password/email', 'ForgotPasswordController@sendResetLinkEmail');
// Route::post('password/reset', 'ResetPasswordController@reset')->name('password.reset'); // Route::post('password/reset', 'ResetPasswordController@reset')->name('password.reset');
}); });
Route::resource('users', 'UsersController', ['except' => ['edit', 'udpate']]);
// Users // Users
Route::group(['prefix' => 'users'], function () { Route::resource('users', 'UsersController', ['except' => ['create','edit']]);
Route::get('deactiveUsers', 'UsersController@deactivatedUserList'); Route::get('deactivatedUsers', 'DeactivatedUsersController@index');
Route::get('deleteUsers', 'UsersController@deleteUserList'); Route::get('deletedUsers', 'DeletedUsersController@index');
});
// Roles // Roles
Route::resource('roles', 'RolesController'); Route::resource('roles', 'RolesController' , ['except' => ['create', 'edit']]);
// Permission // Permission
Route::resource('permission', 'PermissionController'); Route::resource('permission', 'PermissionController');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment