Return workflow list data in workflows endpoint
[MAILPOET-4287]
This commit is contained in:
@@ -2,12 +2,37 @@
|
|||||||
|
|
||||||
namespace MailPoet\Automation\Engine\Endpoints\Workflows;
|
namespace MailPoet\Automation\Engine\Endpoints\Workflows;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
use MailPoet\Automation\Engine\API\Endpoint;
|
use MailPoet\Automation\Engine\API\Endpoint;
|
||||||
use MailPoet\Automation\Engine\API\Request;
|
use MailPoet\Automation\Engine\API\Request;
|
||||||
use MailPoet\Automation\Engine\API\Response;
|
use MailPoet\Automation\Engine\API\Response;
|
||||||
|
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
|
||||||
|
use MailPoet\Automation\Engine\Workflows\Workflow;
|
||||||
|
|
||||||
class WorkflowsGetEndpoint extends Endpoint {
|
class WorkflowsGetEndpoint extends Endpoint {
|
||||||
|
/** @var WorkflowStorage */
|
||||||
|
private $workflowStorage;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
WorkflowStorage $workflowStorage
|
||||||
|
) {
|
||||||
|
$this->workflowStorage = $workflowStorage;
|
||||||
|
}
|
||||||
|
|
||||||
public function handle(Request $request): Response {
|
public function handle(Request $request): Response {
|
||||||
return new Response(['message' => 'Hello world.']);
|
$workflows = $this->workflowStorage->getWorkflows();
|
||||||
|
return new Response(array_map(function (Workflow $workflow) {
|
||||||
|
return $this->buildWorkflow($workflow);
|
||||||
|
}, $workflows));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildWorkflow(Workflow $workflow): array {
|
||||||
|
return [
|
||||||
|
'id' => $workflow->getId(),
|
||||||
|
'name' => $workflow->getName(),
|
||||||
|
'status' => $workflow->getStatus(),
|
||||||
|
'created_at' => $workflow->getCreatedAt()->format(DateTimeImmutable::W3C),
|
||||||
|
'updated_at' => $workflow->getUpdatedAt()->format(DateTimeImmutable::W3C),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,6 @@ class WorkflowsGetTest extends AutomationTest {
|
|||||||
|
|
||||||
public function testRequest(): void {
|
public function testRequest(): void {
|
||||||
$data = $this->get(self::ENDPOINT_PATH);
|
$data = $this->get(self::ENDPOINT_PATH);
|
||||||
$this->assertSame(['data' => ['message' => 'Hello world.']], $data);
|
$this->assertSame(['data' => []], $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user