Allow to query workflows by status
[MAILPOET-4417]
This commit is contained in:
@ -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(),
|
||||
|
Reference in New Issue
Block a user