This commit is contained in:
2025-05-14 17:30:37 +08:00
parent fd534aad85
commit 7dc90492b4
8 changed files with 509 additions and 183 deletions
@@ -4,12 +4,12 @@ namespace app\applet\controller;
use support\Request;
use support\Response;
use app\applet\model\DraftsModel;
use app\applet\service\DraftsService;
use app\applet\model\DraftsDataModel;
use app\applet\service\DraftsDataService;
use app\applet\validate\DraftsValidator;
use app\mzl\common\controller\BaseController;
class DraftsController extends BaseController
class DraftsDataController extends BaseController
{
/**
@@ -28,7 +28,7 @@ class DraftsController extends BaseController
*/
protected function getService()
{
return new DraftsService(new DraftsModel());
return new DraftsDataService(new DraftsDataModel());
}
/**
@@ -78,4 +78,42 @@ class DraftsController extends BaseController
return $this->errorResponse($th->getMessage());
}
}
/**
* 新增草稿
* @param Request $request
* @return Response
*/
public function add(Request $request): Response
{
try {
$data = $this->injectAdd($request->all());
return $this->getService()->add($data)
? $this->successResponse()
: $this->errorResponse();
} catch (\Throwable $th) {
return $this->errorResponse($th->getMessage());
}
}
public function show(Request $request, int $id, string $scene = 'show'): Response
{
try {
return parent::show($request, $id, $scene);
} catch (\Throwable $th) {
return $this->errorResponse($th->getMessage());
}
}
public function edit(Request $request, int $id): Response
{
try {
return $this->getService()->edit($request->all(), $id)
? $this->successResponse()
: $this->errorResponse();
} catch (\Throwable $th) {
return $this->errorResponse($th->getMessage());
}
}
}