Skip to content

Commit c3e216b

Browse files
committed
add agent
1 parent 2878fe0 commit c3e216b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1716
-418
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/*
3+
* Fusio - Self-Hosted API Management for Builders.
4+
* For the current version and information visit <https://www.fusio-project.org/>
5+
*
6+
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
namespace Fusio\Impl\Backend\Action\Agent;
22+
23+
use Fusio\Engine\ActionInterface;
24+
use Fusio\Engine\ContextInterface;
25+
use Fusio\Engine\ParametersInterface;
26+
use Fusio\Engine\RequestInterface;
27+
use Fusio\Impl\Service\Agent;
28+
use Fusio\Impl\Service\Category;
29+
use Fusio\Impl\Service\System\ContextFactory;
30+
use Fusio\Model\Backend\CategoryCreate;
31+
use PSX\Http\Environment\HttpResponse;
32+
33+
/**
34+
* Create
35+
*
36+
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
37+
* @license http://www.apache.org/licenses/LICENSE-2.0
38+
* @link https://www.fusio-project.org
39+
*/
40+
readonly class Create implements ActionInterface
41+
{
42+
public function __construct(private Agent $agentService, private ContextFactory $contextFactory)
43+
{
44+
}
45+
46+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
47+
{
48+
$body = $request->getPayload();
49+
50+
assert($body instanceof AgentCreate);
51+
52+
$id = $this->agentService->create(
53+
$body,
54+
$this->contextFactory->newActionContext($context)
55+
);
56+
57+
return new HttpResponse(201, [], [
58+
'success' => true,
59+
'message' => 'Agent successfully created',
60+
'id' => '' . $id,
61+
]);
62+
}
63+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/*
3+
* Fusio - Self-Hosted API Management for Builders.
4+
* For the current version and information visit <https://www.fusio-project.org/>
5+
*
6+
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
namespace Fusio\Impl\Backend\Action\Agent;
22+
23+
use Fusio\Engine\ActionInterface;
24+
use Fusio\Engine\ContextInterface;
25+
use Fusio\Engine\ParametersInterface;
26+
use Fusio\Engine\RequestInterface;
27+
use Fusio\Impl\Service\Agent;
28+
use Fusio\Impl\Service\System\ContextFactory;
29+
30+
/**
31+
* Delete
32+
*
33+
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
34+
* @license http://www.apache.org/licenses/LICENSE-2.0
35+
* @link https://www.fusio-project.org
36+
*/
37+
readonly class Delete implements ActionInterface
38+
{
39+
public function __construct(private Agent $agentService, private ContextFactory $contextFactory)
40+
{
41+
}
42+
43+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
44+
{
45+
$id = $this->agentService->delete(
46+
$request->get('agent_id'),
47+
$this->contextFactory->newActionContext($context)
48+
);
49+
50+
return [
51+
'success' => true,
52+
'message' => 'Agent successfully deleted',
53+
'id' => '' . $id,
54+
];
55+
}
56+
}

src/Backend/Action/Agent/Get.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/*
3+
* Fusio - Self-Hosted API Management for Builders.
4+
* For the current version and information visit <https://www.fusio-project.org/>
5+
*
6+
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
namespace Fusio\Impl\Backend\Action\Agent;
22+
23+
use Fusio\Engine\ActionInterface;
24+
use Fusio\Engine\ContextInterface;
25+
use Fusio\Engine\ParametersInterface;
26+
use Fusio\Engine\RequestInterface;
27+
use Fusio\Impl\Backend\View;
28+
use Fusio\Impl\Table;
29+
use PSX\Http\Exception as StatusCode;
30+
31+
/**
32+
* Get
33+
*
34+
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
35+
* @license http://www.apache.org/licenses/LICENSE-2.0
36+
* @link https://www.fusio-project.org
37+
*/
38+
class Get implements ActionInterface
39+
{
40+
public function __construct(private View\Agent $view)
41+
{
42+
}
43+
44+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
45+
{
46+
$agent = $this->view->getEntity(
47+
$request->get('agent_id'),
48+
$context
49+
);
50+
51+
if (empty($agent)) {
52+
throw new StatusCode\NotFoundException('Could not find agent');
53+
}
54+
55+
if ($agent['status'] == Table\Agent::STATUS_DELETED) {
56+
throw new StatusCode\GoneException('Agent was deleted');
57+
}
58+
59+
return $agent;
60+
}
61+
}
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,33 @@
1818
* limitations under the License.
1919
*/
2020

21-
namespace Fusio\Impl\Service\Agent;
21+
namespace Fusio\Impl\Backend\Action\Agent;
22+
23+
use Fusio\Engine\ActionInterface;
24+
use Fusio\Engine\ContextInterface;
25+
use Fusio\Engine\ParametersInterface;
26+
use Fusio\Engine\RequestInterface;
27+
use Fusio\Impl\Backend\Filter\QueryFilter;
28+
use Fusio\Impl\Backend\View;
2229

2330
/**
24-
* IntentFactory
31+
* GetAll
2532
*
2633
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
2734
* @license http://www.apache.org/licenses/LICENSE-2.0
2835
* @link https://www.fusio-project.org
2936
*/
30-
readonly class IntentFactory
37+
class GetAll implements ActionInterface
3138
{
32-
public function __construct(
33-
private Intent\ActionIntent $actionIntent,
34-
private Intent\SchemaIntent $schemaIntent,
35-
private Intent\ArchitectIntent $architectIntent,
36-
private Intent\GeneralIntent $generalIntent
37-
) {
39+
public function __construct(private View\Agent $view)
40+
{
3841
}
3942

40-
public function factory(?Intent $intent): IntentInterface
43+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
4144
{
42-
return match($intent) {
43-
Intent::ACTION => $this->actionIntent,
44-
Intent::SCHEMA => $this->schemaIntent,
45-
Intent::ARCHITECT => $this->architectIntent,
46-
default => $this->generalIntent,
47-
};
45+
return $this->view->getCollection(
46+
QueryFilter::from($request),
47+
$context
48+
);
4849
}
4950
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/*
3+
* Fusio - Self-Hosted API Management for Builders.
4+
* For the current version and information visit <https://www.fusio-project.org/>
5+
*
6+
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
namespace Fusio\Impl\Backend\Action\Agent;
22+
23+
use Fusio\Engine\ActionInterface;
24+
use Fusio\Engine\Agent\ToolsInterface;
25+
use Fusio\Engine\ContextInterface;
26+
use Fusio\Engine\ParametersInterface;
27+
use Fusio\Engine\RequestInterface;
28+
29+
/**
30+
* GetTools
31+
*
32+
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
33+
* @license http://www.apache.org/licenses/LICENSE-2.0
34+
* @link https://www.fusio-project.org
35+
*/
36+
readonly class GetTools implements ActionInterface
37+
{
38+
public function __construct(private ToolsInterface $tools)
39+
{
40+
}
41+
42+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
43+
{
44+
return [
45+
'tools' => $this->getTools(),
46+
];
47+
}
48+
49+
private function getTools(): array
50+
{
51+
$toolbox = $this->tools->resolve();
52+
53+
$result = [];
54+
foreach ($toolbox->getTools() as $tool) {
55+
$result[] = [
56+
'name' => $tool->getName(),
57+
'description' => $tool->getDescription(),
58+
];
59+
}
60+
61+
return $result;
62+
}
63+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/*
3+
* Fusio - Self-Hosted API Management for Builders.
4+
* For the current version and information visit <https://www.fusio-project.org/>
5+
*
6+
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
namespace Fusio\Impl\Backend\Action\Agent;
22+
23+
use Fusio\Engine\ActionInterface;
24+
use Fusio\Engine\ContextInterface;
25+
use Fusio\Engine\ParametersInterface;
26+
use Fusio\Engine\RequestInterface;
27+
use Fusio\Impl\Service\Agent;
28+
use Fusio\Impl\Service\System\ContextFactory;
29+
30+
/**
31+
* Update
32+
*
33+
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
34+
* @license http://www.apache.org/licenses/LICENSE-2.0
35+
* @link https://www.fusio-project.org
36+
*/
37+
readonly class Update implements ActionInterface
38+
{
39+
public function __construct(private Agent $agentService, private ContextFactory $contextFactory)
40+
{
41+
}
42+
43+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
44+
{
45+
$body = $request->getPayload();
46+
47+
assert($body instanceof AgentUpdate);
48+
49+
$id = $this->agentService->update(
50+
$request->get('agent_id'),
51+
$body,
52+
$this->contextFactory->newActionContext($context)
53+
);
54+
55+
return [
56+
'success' => true,
57+
'message' => 'Agent successfully updated',
58+
'id' => '' . $id,
59+
];
60+
}
61+
}

0 commit comments

Comments
 (0)