Extract workflow delete logic to a controller
[MAILPOET-4540]
This commit is contained in:
@@ -5,32 +5,22 @@ namespace MailPoet\Automation\Engine\Endpoints\Workflows;
|
||||
use MailPoet\API\REST\Request;
|
||||
use MailPoet\API\REST\Response;
|
||||
use MailPoet\Automation\Engine\API\Endpoint;
|
||||
use MailPoet\Automation\Engine\Data\Workflow;
|
||||
use MailPoet\Automation\Engine\Exceptions\InvalidStateException;
|
||||
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
|
||||
use MailPoet\Automation\Engine\Builder\DeleteWorkflowController;
|
||||
use MailPoet\Validator\Builder;
|
||||
|
||||
class WorkflowsDeleteEndpoint extends Endpoint {
|
||||
/** @var WorkflowStorage */
|
||||
private $workflowStorage;
|
||||
/** @var DeleteWorkflowController */
|
||||
private $deleteController;
|
||||
|
||||
public function __construct(
|
||||
WorkflowStorage $workflowStorage
|
||||
DeleteWorkflowController $deleteController
|
||||
) {
|
||||
$this->workflowStorage = $workflowStorage;
|
||||
$this->deleteController = $deleteController;
|
||||
}
|
||||
|
||||
public function handle(Request $request): Response {
|
||||
$workflowId = $request->getParam('id');
|
||||
if (!is_int($workflowId)) {
|
||||
throw InvalidStateException::create();
|
||||
}
|
||||
$existingWorkflow = $this->workflowStorage->getWorkflow($workflowId);
|
||||
if (!$existingWorkflow instanceof Workflow) {
|
||||
throw InvalidStateException::create();
|
||||
}
|
||||
$this->workflowStorage->deleteWorkflow($existingWorkflow);
|
||||
|
||||
$workflowId = intval($request->getParam('id'));
|
||||
$this->deleteController->deleteWorkflow($workflowId);
|
||||
return new Response(null);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user