You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.0 KiB
111 lines
3.0 KiB
<?php |
|
|
|
namespace Plugins\Notebook\Controller\Admin; |
|
|
|
use App\Exception\ApiMessageException; |
|
use App\Controller\AbstractController; |
|
use Plugins\Notebook\Request\NotebookRequest; |
|
use Plugins\Notebook\Service\Admin\NotebookService; |
|
use App\Middleware\Admin\AuthenticateMiddleware; |
|
use App\Middleware\Admin\PermissionsMiddleware; |
|
use App\Util\Response; |
|
use Hyperf\HttpServer\Annotation\Controller; |
|
use Hyperf\HttpServer\Annotation\GetMapping; |
|
use Hyperf\HttpServer\Annotation\PostMapping; |
|
use Hyperf\HttpServer\Annotation\Middlewares; |
|
use Hyperf\Validation\Annotation\Scene; |
|
use Hyperf\Validation\Middleware\ValidationMiddleware; |
|
use Hyperf\View\Render; |
|
use Psr\Http\Message\ResponseInterface; |
|
|
|
/** |
|
* 笔记本控制器 |
|
*/ |
|
#[Controller(prefix: 'admin/plugins/notebook')] |
|
#[Middlewares([AuthenticateMiddleware::class, PermissionsMiddleware::class])] |
|
class NotebookController extends AbstractController |
|
{ |
|
|
|
/** |
|
* 列表页 |
|
* |
|
* @param Render $render |
|
* |
|
* @return ResponseInterface |
|
*/ |
|
#[GetMapping(path: 'lists')] |
|
public function lists(Render $render): ResponseInterface |
|
{ |
|
return $render->render('plugins.Notebook.Admin.Notebook.lists'); |
|
} |
|
|
|
/** |
|
* 列表数据 |
|
* |
|
* @return ResponseInterface |
|
*/ |
|
#[GetMapping(path: 'lists-data')] |
|
public function listsData(): ResponseInterface |
|
{ |
|
return Response::json()->success(NotebookService::aop()->lists()); |
|
} |
|
|
|
/** |
|
* 创建数据 |
|
* |
|
* @param NotebookRequest $notebookRequest |
|
* |
|
* @return ResponseInterface |
|
* @throws ApiMessageException |
|
*/ |
|
#[Scene('store')] |
|
#[PostMapping(path: 'create')] |
|
#[Middlewares([ValidationMiddleware::class])] |
|
public function store(NotebookRequest $notebookRequest): ResponseInterface |
|
{ |
|
$model = NotebookService::aop()->store($notebookRequest->post()); |
|
$data = $model->setVisible(['id', "title", "content", "create_time"])->toArray(); |
|
|
|
$data['create_name'] = $model->createAdmin->name; |
|
$data['latest_name'] = $model->latestAdmin->name; |
|
|
|
return Response::json()->success($data); |
|
} |
|
|
|
/** |
|
* 更新数据 |
|
* |
|
* @param NotebookRequest $notebookRequest |
|
* |
|
* @return ResponseInterface |
|
* @throws ApiMessageException |
|
*/ |
|
#[Scene('update')] |
|
#[PostMapping(path: 'update')] |
|
#[Middlewares([ValidationMiddleware::class])] |
|
public function update(NotebookRequest $notebookRequest): ResponseInterface |
|
{ |
|
NotebookService::aop()->update($notebookRequest->post()); |
|
|
|
return Response::json()->success(); |
|
} |
|
|
|
/** |
|
* 删除数据 |
|
* |
|
* @param NotebookRequest $notebookRequest |
|
* |
|
* @return ResponseInterface |
|
* @throws ApiMessageException |
|
*/ |
|
#[Scene('destroy')] |
|
#[PostMapping(path: 'destroy')] |
|
#[Middlewares([ValidationMiddleware::class])] |
|
public function destroy(NotebookRequest $notebookRequest): ResponseInterface |
|
{ |
|
NotebookService::aop()->destroy($notebookRequest->post('ids')); |
|
|
|
return Response::json()->success(); |
|
} |
|
|
|
}
|
|
|