mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 11:22:10 +08:00
feat : admin role unfinish
This commit is contained in:
@@ -4,11 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Annotation\Permission;
|
||||
use App\Annotation\ResponseFormat;
|
||||
use App\Middleware\Admin\AdminTokenMiddleware;
|
||||
use App\Middleware\Admin\PermissionMiddleware;
|
||||
use App\Service\Admin\AdminUser\RoleService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\Middleware;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
|
||||
|
||||
#[Controller(prefix: "admin/role")]
|
||||
@@ -17,5 +21,54 @@ use Hyperf\HttpServer\Annotation\Middleware;
|
||||
#[Middleware(middleware: PermissionMiddleware::class, priority: 99)]
|
||||
class AdminRoleController
|
||||
{
|
||||
/**
|
||||
* @var RoleService
|
||||
*/
|
||||
#[Inject]
|
||||
protected RoleService $service;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "list", methods: "GET")]
|
||||
#[Permission(code: 'permission:role:index')]
|
||||
public function pageList(): array
|
||||
{
|
||||
return $this->service->handle();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "", methods: "POST")]
|
||||
#[Permission(code: 'permission:role:save')]
|
||||
public function createRole()
|
||||
{
|
||||
return $this->service->create();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "{id}", methods: "PUT")]
|
||||
#[Permission(code: 'permission:role:update')]
|
||||
public function updateRole(int $id)
|
||||
{
|
||||
return $this->service->update($id);
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "", methods: "DELETE")]
|
||||
#[Permission(code: 'permission:role:delete')]
|
||||
public function deleteRole()
|
||||
{
|
||||
return $this->service->delete();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "{id}/permission", methods: "GET")]
|
||||
#[Permission(code: 'permission:role:getMenu')]
|
||||
public function getRolePermission()
|
||||
{
|
||||
return $this->service->getRole();
|
||||
}
|
||||
|
||||
#[RequestMapping(path: "{id}/permission", methods: "PUT")]
|
||||
#[Permission(code: 'permission:role:setMenu')]
|
||||
public function batchGrantPermissionByRole()
|
||||
{
|
||||
return $this->service->setRole();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,69 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\AdminUser;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Repository\AdminRoleRepository;
|
||||
use App\Service\Admin\BaseAdminService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class RoleService extends BaseAdminService
|
||||
{
|
||||
public function handle()
|
||||
/**
|
||||
* @var AdminRoleRepository
|
||||
*/
|
||||
#[Inject]
|
||||
protected AdminRoleRepository $adminRoleRepository;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
//todo Write logic
|
||||
return $this->adminReturn->success(
|
||||
'success',
|
||||
$this->adminRoleRepository->page(
|
||||
$this->getRequestData(),
|
||||
$this->getCurrentPage(),
|
||||
$this->getPageSize()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function create(): array
|
||||
{
|
||||
if (!$this->adminRoleRepository->create(
|
||||
array_merge(
|
||||
$this->getRequestData(),
|
||||
['created_by' => $this->adminId]
|
||||
)
|
||||
)) throw new ErrException('添加失败');
|
||||
|
||||
return $this->adminReturn->success();
|
||||
}
|
||||
|
||||
public function update(int $id)
|
||||
{
|
||||
if (!$this->adminRoleRepository->updateById(
|
||||
$id,
|
||||
array_merge()
|
||||
));
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getRole()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function setRole()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user