Commit f223677d authored by Vipul Basapati's avatar Vipul Basapati

Added Responses to User Module

parent 71ff81f3
......@@ -2,18 +2,23 @@
namespace App\Http\Controllers\Backend\Access\User;
use App\Models\Access\User\User;
use App\Http\Controllers\Controller;
use App\Http\Requests\Backend\Access\User\CreateUserRequest;
use App\Http\Requests\Backend\Access\User\DeleteUserRequest;
use App\Http\Responses\RedirectResponse;
use App\Models\Access\Permission\Permission;
use App\Http\Responses\Backend\Access\User\EditResponse;
use App\Http\Responses\Backend\Access\User\ShowResponse;
use App\Repositories\Backend\Access\Role\RoleRepository;
use App\Repositories\Backend\Access\User\UserRepository;
use App\Http\Responses\Backend\Access\User\IndexResponse;
use App\Http\Requests\Backend\Access\User\EditUserRequest;
use App\Http\Requests\Backend\Access\User\ManageUserRequest;
use App\Http\Requests\Backend\Access\User\ShowUserRequest;
use App\Http\Responses\Backend\Access\User\CreateResponse;
use App\Http\Requests\Backend\Access\User\StoreUserRequest;
use App\Http\Requests\Backend\Access\User\CreateUserRequest;
use App\Http\Requests\Backend\Access\User\DeleteUserRequest;
use App\Http\Requests\Backend\Access\User\ManageUserRequest;
use App\Http\Requests\Backend\Access\User\UpdateUserRequest;
use App\Models\Access\Permission\Permission;
use App\Models\Access\User\User;
use App\Repositories\Backend\Access\Role\RoleRepository;
use App\Repositories\Backend\Access\User\UserRepository;
/**
* Class UserController.
......@@ -21,18 +26,18 @@ use App\Repositories\Backend\Access\User\UserRepository;
class UserController extends Controller
{
/**
* @var UserRepository
* @var \App\Repositories\Backend\Access\User\UserRepository
*/
protected $users;
/**
* @var RoleRepository
* @var \App\Repositories\Backend\Access\Role\RoleRepository
*/
protected $roles;
/**
* @param UserRepository $users
* @param RoleRepository $roles
* @param \App\Repositories\Backend\Access\User\UserRepository $users
* @param \App\Repositories\Backend\Access\Role\RoleRepository $roles
*/
public function __construct(UserRepository $users, RoleRepository $roles)
{
......@@ -41,94 +46,87 @@ class UserController extends Controller
}
/**
* @param ManageUserRequest $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @param \App\Http\Requests\Backend\Access\User\ManageUserRequest $request
*
* @return \App\Http\Responses\Backend\Access\User\IndexResponse
*/
public function index(ManageUserRequest $request)
{
return view('backend.access.users.index');
return new IndexResponse();
}
/**
* @param CreateUserRequest $request
* @param \App\Http\Requests\Backend\Access\User\CreateUserRequest $request
*
* @return mixed
* @return \App\Http\Responses\Backend\Access\User\CreateResponse
*/
public function create(CreateUserRequest $request)
{
return view('backend.access.users.create')->with([
'roles' => $this->roles->getAll(),
]);
$roles = $this->roles->getAll();
return new CreateResponse($roles);
}
/**
* @param StoreUserRequest $request
* @param \App\Http\Requests\Backend\Access\User\StoreUserRequest $request
*
* @return mixed
* @return \App\Http\Responses\RedirectResponse
*/
public function store(StoreUserRequest $request)
{
$this->users->create($request);
return redirect()->route('admin.access.user.index')->withFlashSuccess(trans('alerts.backend.users.created'));
return new RedirectResponse('admin.access.user.index', ['flash_success' => trans('alerts.backend.users.created')]);
}
/**
* @param User $user
* @param ShowUserRequest $request
* @param \App\Models\Access\User\User $user
* @param \App\Http\Requests\Backend\Access\User\ShowUserRequest $request
*
* @return mixed
* @return \App\Http\Responses\Backend\Access\User\ShowResponse
*/
public function show(User $user, ShowUserRequest $request)
{
return view('backend.access.users.show')
->withUser($user);
return new ShowResponse($user);
}
/**
* @param User $user
* @param EditUserRequest $request
* @param \App\Models\Access\User\User $user
* @param \App\Http\Requests\Backend\Access\User\EditUserRequest $request
*
* @return mixed
* @return \App\Http\Responses\Backend\Access\User\EditResponse
*/
public function edit(User $user, EditUserRequest $request)
{
$roles = $this->roles->getAll();
$permissions = Permission::getSelectData('display_name');
$userPermissions = $user->permissions()->get()->pluck('id')->toArray();
return view('backend.access.users.edit')->with([
'user' => $user,
'userRoles' => $user->roles->pluck('id')->all(),
'roles' => $this->roles->getAll(),
'userPermissions' => $userPermissions,
'permissions' => $permissions,
]);
return new EditResponse($user, $roles, $permissions);
}
/**
* @param User $user
* @param UpdateUserRequest $request
* @param \App\Models\Access\User\User $user
* @param \App\Http\Requests\Backend\Access\User\UpdateUserRequest $request
*
* @return mixed
* @return \App\Http\Responses\RedirectResponse
*/
public function update(User $user, UpdateUserRequest $request)
{
$this->users->update($user, $request);
return redirect()->route('admin.access.user.index')->withFlashSuccess(trans('alerts.backend.users.updated'));
return new RedirectResponse('admin.access.user.index', ['flash_success' => trans('alerts.backend.users.updated')]);
}
/**
* @param User $user
* @param DeleteUserRequest $request
* @param \App\Models\Access\User\User $user
* @param \App\Http\Requests\Backend\Access\User\DeleteUserRequest $request
*
* @return mixed
* @return \App\Http\Responses\RedirectResponse
*/
public function destroy(User $user, DeleteUserRequest $request)
{
$this->users->delete($user);
return redirect()->route('admin.access.user.deleted')->withFlashSuccess(trans('alerts.backend.users.deleted'));
return new RedirectResponse('admin.access.user.index', ['flash_success' => trans('alerts.backend.users.deleted')]);
}
}
<?php
namespace App\Http\Responses\Backend\Access\User;
use Illuminate\Contracts\Support\Responsable;
class CreateResponse implements Responsable
{
/**
* @var \App\Models\Access\Role\Role
*/
protected $roles;
/**
* @param \Illuminate\Database\Eloquent\Collection $roles
*/
public function __construct($roles)
{
$this->roles = $roles;
}
/**
* In Response
*
* @param \App\Http\Requests\Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
return view('backend.access.users.create')->with([
'roles' => $this->roles,
]);
}
}
<?php
namespace App\Http\Responses\Backend\Access\User;
use Illuminate\Contracts\Support\Responsable;
class EditResponse implements Responsable
{
/**
* @var \App\Models\Access\User\User
*/
protected $user;
/**
* @var \App\Models\Access\Permission\Permission
*/
protected $permissions;
/**
* @var \App\Models\Access\Role\Role
*/
protected $roles;
/**
* @param \App\Models\Access\User\User $user
*/
public function __construct($user, $roles, $permissions)
{
$this->user = $user;
$this->roles = $roles;
$this->permissions = $permissions;
}
public function toResponse($request)
{
$permissions = $this->permissions;
$userPermissions = $this->user->permissions()->get()->pluck('id')->toArray();
return view('backend.access.users.edit')->with([
'user' => $this->user,
'userRoles' => $this->user->roles->pluck('id')->all(),
'roles' => $this->roles,
'userPermissions' => $userPermissions,
'permissions' => $permissions,
]);
}
}
<?php
namespace App\Http\Responses\Backend\Access\User;
use Illuminate\Contracts\Support\Responsable;
class IndexResponse implements Responsable
{
/**
* In Response
*
* @param \App\Http\Requests\Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
return view('backend.access.users.index');
}
}
<?php
namespace App\Http\Responses\Backend\Access\User;
use Illuminate\Contracts\Support\Responsable;
class ShowResponse implements Responsable
{
/**
* @var \App\Models\Access\User\User
*/
protected $user;
/**
* @param \App\Models\Access\User\User $user
*/
public function __construct($user)
{
$this->user = $user;
}
/**
* In Response
*
* @param \App\Http\Requests\Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
return view('backend.access.users.show')->withUser($this->user);
}
}
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