Allow to query workflows by status

[MAILPOET-4417]
This commit is contained in:
David Remer
2022-08-10 13:21:06 +03:00
committed by Veljko V
parent dde3b159ea
commit b546344e42

View File

@ -8,6 +8,7 @@ use MailPoet\Automation\Engine\API\Request;
use MailPoet\Automation\Engine\API\Response;
use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
use MailPoet\Validator\Builder;
class WorkflowsGetEndpoint extends Endpoint {
/** @var WorkflowStorage */
@ -20,12 +21,19 @@ class WorkflowsGetEndpoint extends Endpoint {
}
public function handle(Request $request): Response {
$workflows = $this->workflowStorage->getWorkflows();
$status = $request->getParam('status') ? (array)$request->getParam('status') : null;
$workflows = $this->workflowStorage->getWorkflows($status);
return new Response(array_map(function (Workflow $workflow) {
return $this->buildWorkflow($workflow);
}, $workflows));
}
public static function getRequestSchema(): array {
return [
'status' => Builder::array(Builder::string()),
];
}
private function buildWorkflow(Workflow $workflow): array {
return [
'id' => $workflow->getId(),