hyperf-view/app/System/Controller/Modules/ModuleController.php

97 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\System\Controller\Modules;
use App\System\Request\ModuleRequest;
use App\System\Service\ModuleService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Builder\Annotation\Auth;
use Builder\Annotation\OperationLog;
use Builder\Annotation\Permission;
use Builder\BaseController;
use Psr\Http\Message\ResponseInterface;
/**
* 本地模块管理
* Class ModuleController
* @package App\System\Controller\Modules
*/
#[Controller(prefix: "system/setting/module"), Auth]
class ModuleController extends BaseController
{
#[Inject]
protected ModuleService $service;
/**
* 本地模块列表
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[GetMapping("index"), Permission("setting:module, setting:module:index")]
public function index(): ResponseInterface
{
return $this->success($this->service->getPageList($this->request->all()));
}
/**
* 新增本地模块
* @param ModuleRequest $request
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PutMapping("save"), Permission("setting:module:save"), OperationLog]
public function save(ModuleRequest $request): ResponseInterface
{
$this->service->createModule($request->validated());
return $this->success();
}
/**
* 启停用模块
* @param ModuleRequest $request
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PostMapping("modifyStatus"), Permission("setting:module:status"), OperationLog]
public function modifyStatus(ModuleRequest $request): ResponseInterface
{
return $this->service->modifyStatus($request->validated()) ? $this->success() : $this->error();
}
/**
* 安装模块
* @param string $name
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PutMapping("install"), Permission("setting:module:install"), OperationLog]
public function install(): ResponseInterface
{
return $this->service->installModuleData($this->request->input('name')) ? $this->success() : $this->error();
}
/**
* 卸载删除模块
* @param string $name
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @throws \Throwable
*/
#[DeleteMapping("delete"), Permission("setting:module:delete"), OperationLog]
public function delete(): ResponseInterface
{
return $this->service->uninstallModule($this->request->input('name')) ? $this->success() : $this->error();
}
}