Commit d24e4825 authored by Vipul Basapati's avatar Vipul Basapati

Role Module Response Interface integration complete

parent c7c71028
......@@ -2,16 +2,20 @@
namespace App\Http\Controllers\Backend\Access\Role;
use App\Models\Access\Role\Role;
use App\Http\Controllers\Controller;
use App\Http\Responses\ViewResponse;
use App\Http\Responses\RedirectResponse;
use App\Http\Responses\Backend\Access\Role\EditResponse;
use App\Repositories\Backend\Access\Role\RoleRepository;
use App\Http\Requests\Backend\Access\Role\EditRoleRequest;
use App\Http\Responses\Backend\Access\Role\CreateResponse;
use App\Http\Requests\Backend\Access\Role\StoreRoleRequest;
use App\Http\Requests\Backend\Access\Role\CreateRoleRequest;
use App\Http\Requests\Backend\Access\Role\DeleteRoleRequest;
use App\Http\Requests\Backend\Access\Role\EditRoleRequest;
use App\Http\Requests\Backend\Access\Role\ManageRoleRequest;
use App\Http\Requests\Backend\Access\Role\StoreRoleRequest;
use App\Http\Requests\Backend\Access\Role\UpdateRoleRequest;
use App\Models\Access\Role\Role;
use App\Repositories\Backend\Access\Permission\PermissionRepository;
use App\Repositories\Backend\Access\Role\RoleRepository;
/**
* Class RoleController.
......@@ -19,18 +23,18 @@ use App\Repositories\Backend\Access\Role\RoleRepository;
class RoleController extends Controller
{
/**
* @var RoleRepository
* @var \App\Repositories\Backend\Access\Role\RoleRepository
*/
protected $roles;
/**
* @var PermissionRepository
* @var \App\Repositories\Backend\Access\Permission\PermissionRepository
*/
protected $permissions;
/**
* @param RoleRepository $roles
* @param PermissionRepository $permissions
* @param \App\Repositories\Backend\Access\Role\RoleRepository $roles
* @param \App\Repositories\Backend\Access\Permission\PermissionRepository $permissions
*/
public function __construct(RoleRepository $roles, PermissionRepository $permissions)
{
......@@ -39,76 +43,71 @@ class RoleController extends Controller
}
/**
* @param ManageRoleRequest $request
* @param \App\Http\Requests\Backend\Access\Role\ManageRoleRequest $request
*
* @return mixed
*/
public function index(ManageRoleRequest $request)
{
return view('backend.access.roles.index');
return new ViewResponse('backend.access.roles.index');
}
/**
* @param CreateRoleRequest $request
* @param \App\Http\Requests\Backend\Access\Role\CreateRoleRequest $request
*
* @return mixed
* @return \App\Http\Responses\Backend\Access\Role\CreateResponse
*/
public function create(CreateRoleRequest $request)
{
return view('backend.access.roles.create')
->withPermissions($this->permissions->getAll())
->withRoleCount($this->roles->getCount());
return new CreateResponse($this->permissions, $this->roles);
}
/**
* @param StoreRoleRequest $request
* @param \App\Http\Requests\Backend\Access\Role\StoreRoleRequest $request
*
* @return mixed
* @return \App\Http\Responses\RedirectResponse
*/
public function store(StoreRoleRequest $request)
{
$this->roles->create($request->all());
return redirect()->route('admin.access.role.index')->withFlashSuccess(trans('alerts.backend.roles.created'));
return new RedirectResponse('admin.access.role.index', ['flash_success' => trans('alerts.backend.roles.created')]);
}
/**
* @param Role $role
* @param EditRoleRequest $request
* @param \App\Models\Access\Role\Role $role
* @param \App\Http\Requests\Backend\Access\Role\EditRoleRequest $request
*
* @return mixed
* @return \App\Http\Responses\Backend\Access\Role\EditResponse
*/
public function edit(Role $role, EditRoleRequest $request)
{
return view('backend.access.roles.edit')
->withRole($role)
->withRolePermissions($role->permissions->pluck('id')->all())
->withPermissions($this->permissions->getAll());
return new EditResponse($role, $this->permissions);
}
/**
* @param Role $role
* @param UpdateRoleRequest $request
* @param \App\Models\Access\Role\Role $role
* @param \App\Http\Requests\Backend\Access\Role\UpdateRoleRequest $request
*
* @return mixed
* @return \App\Http\Responses\RedirectResponse
*/
public function update(Role $role, UpdateRoleRequest $request)
{
$this->roles->update($role, $request->all());
return redirect()->route('admin.access.role.index')->withFlashSuccess(trans('alerts.backend.roles.updated'));
return new RedirectResponse('admin.access.role.index', ['flash_success' => trans('alerts.backend.roles.updated')]);
}
/**
* @param Role $role
* @param DeleteRoleRequest $request
* @param \App\Models\Access\Role\Role $role
* @param \App\Http\Requests\Backend\Access\Role\DeleteRoleRequest $request
*
* @return mixed
* @return \App\Http\Responses\RedirectResponse
*/
public function destroy(Role $role, DeleteRoleRequest $request)
{
$this->roles->delete($role);
return redirect()->route('admin.access.role.index')->withFlashSuccess(trans('alerts.backend.roles.deleted'));
return new RedirectResponse('admin.access.role.index', ['flash_success' => trans('alerts.backend.roles.deleted')]);
}
}
......@@ -2,23 +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\Requests\Backend\Access\User\EditUserRequest;
use App\Http\Requests\Backend\Access\User\ManageUserRequest;
use App\Http\Requests\Backend\Access\User\ShowUserRequest;
use App\Http\Requests\Backend\Access\User\StoreUserRequest;
use App\Http\Requests\Backend\Access\User\UpdateUserRequest;
use App\Http\Responses\Backend\Access\User\CreateResponse;
use App\Http\Responses\Backend\Access\User\EditResponse;
use App\Http\Responses\Backend\Access\User\IndexResponse;
use App\Http\Responses\Backend\Access\User\ShowResponse;
use App\Http\Responses\ViewResponse;
use App\Http\Responses\RedirectResponse;
use App\Models\Access\Permission\Permission;
use App\Models\Access\User\User;
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\Requests\Backend\Access\User\EditUserRequest;
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;
/**
* Class UserController.
......@@ -48,11 +48,11 @@ class UserController extends Controller
/**
* @param \App\Http\Requests\Backend\Access\User\ManageUserRequest $request
*
* @return \App\Http\Responses\Backend\Access\User\IndexResponse
* @return \App\Http\Responses\ViewResponse
*/
public function index(ManageUserRequest $request)
{
return new IndexResponse();
return new ViewResponse('backend.access.users.index');
}
/**
......
......@@ -14,12 +14,12 @@ use Yajra\DataTables\Facades\DataTables;
class UserTableController extends Controller
{
/**
* @var UserRepository
* @var \App\Repositories\Backend\Access\User\UserRepository
*/
protected $users;
/**
* @param UserRepository $users
* @param \App\Repositories\Backend\Access\User\UserRepository $users
*/
public function __construct(UserRepository $users)
{
......@@ -27,7 +27,7 @@ class UserTableController extends Controller
}
/**
* @param ManageUserRequest $request
* @param \App\Http\Requests\Backend\Access\User\ManageUserRequest $request
*
* @return mixed
*/
......
<?php
namespace App\Http\Responses\Backend\Access\Role;
use Illuminate\Contracts\Support\Responsable;
class CreateResponse implements Responsable
{
/**
* @var \App\Repositories\Backend\Access\Role\RoleRepository
*/
protected $roles;
/**
* @var \App\Repositories\Backend\Access\Permission\PermissionRepository
*/
protected $permissions;
/**
* @param \App\Repositories\Backend\Access\Permission\PermissionRepository $permissions
* @param \App\Repositories\Backend\Access\Role\RoleRepository $roles
*/
public function __construct($permissions, $roles)
{
$this->permissions = $permissions;
$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.roles.create')
->withPermissions($this->permissions->getAll())
->withRoleCount($this->roles->getCount());
}
}
<?php
namespace App\Http\Responses\Backend\Access\Role;
use Illuminate\Contracts\Support\Responsable;
class EditResponse implements Responsable
{
/**
* @var \App\Models\Access\Role\Role
*/
protected $role;
/**
* @var \App\Repositories\Backend\Access\Permission\PermissionRepository
*/
protected $permissions;
/**
* @param \App\Models\Access\Role\Role $role
* @param \App\Repositories\Backend\Access\Permission\PermissionRepository $permissions
*/
public function __construct($role, $permissions)
{
$this->role = $role;
$this->permissions = $permissions;
}
/**
* toReponse
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
return view('backend.access.roles.edit')
->withRole($this->role)
->withRolePermissions($this->role->permissions->pluck('id')->all())
->withPermissions($this->permissions->getAll());
}
}
......@@ -4,8 +4,21 @@ namespace App\Http\Responses\Backend\Access\User;
use Illuminate\Contracts\Support\Responsable;
class IndexResponse implements 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.
*
......@@ -15,6 +28,6 @@ class IndexResponse implements Responsable
*/
public function toResponse($request)
{
return view('backend.access.users.index');
return view('backend.access.users.show')->withUser($this->user);
}
}
......@@ -31,6 +31,12 @@ class EditResponse implements Responsable
$this->permissions = $permissions;
}
/**
* toReponse
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
$permissions = $this->permissions;
......
<?php
namespace App\Http\Responses;
use Illuminate\Contracts\Support\Responsable;
class ViewResponse implements Responsable
{
/**
* @var String
*/
protected $view;
/**
* @var Array
*/
protected $with;
/**
* @param String $view
* @param Array $with
*/
public function __construct($view, $with = [])
{
$this->view = $view;
$this->with = $with;
}
/**
* In Response.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function toResponse($request)
{
if (!empty($this->with))
{
return view($this->view)->with($this->with);
}
return view($this->view);
}
}
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