Extract workflow delete logic to a controller

[MAILPOET-4540]
This commit is contained in:
Jan Jakes
2022-10-13 15:06:47 +02:00
committed by David Remer
parent 89c43a5cb9
commit b01d050f1d
3 changed files with 35 additions and 17 deletions

View File

@@ -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);
}