Skip to content

Commit 51dad31

Browse files
committed
add initial taxonomy implementation
1 parent aee1373 commit 51dad31

34 files changed

+1510
-5
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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\Taxonomy;
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\Category;
28+
use Fusio\Impl\Service\System\ContextFactory;
29+
use Fusio\Model\Backend\CategoryCreate;
30+
use PSX\Http\Environment\HttpResponse;
31+
32+
/**
33+
* Create
34+
*
35+
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
36+
* @license http://www.apache.org/licenses/LICENSE-2.0
37+
* @link https://www.fusio-project.org
38+
*/
39+
class Create implements ActionInterface
40+
{
41+
private Category $categoryService;
42+
private ContextFactory $contextFactory;
43+
44+
public function __construct(Category $categoryService, ContextFactory $contextFactory)
45+
{
46+
$this->categoryService = $categoryService;
47+
$this->contextFactory = $contextFactory;
48+
}
49+
50+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
51+
{
52+
$body = $request->getPayload();
53+
54+
assert($body instanceof CategoryCreate);
55+
56+
$id = $this->categoryService->create(
57+
$body,
58+
$this->contextFactory->newActionContext($context)
59+
);
60+
61+
return new HttpResponse(201, [], [
62+
'success' => true,
63+
'message' => 'Category successfully created',
64+
'id' => '' . $id,
65+
]);
66+
}
67+
}
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\Taxonomy;
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\Category;
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+
class Delete implements ActionInterface
38+
{
39+
private Category $categoryService;
40+
private ContextFactory $contextFactory;
41+
42+
public function __construct(Category $categoryService, ContextFactory $contextFactory)
43+
{
44+
$this->categoryService = $categoryService;
45+
$this->contextFactory = $contextFactory;
46+
}
47+
48+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
49+
{
50+
$id = $this->categoryService->delete(
51+
$request->get('category_id'),
52+
$this->contextFactory->newActionContext($context)
53+
);
54+
55+
return [
56+
'success' => true,
57+
'message' => 'Category successfully deleted',
58+
'id' => '' . $id,
59+
];
60+
}
61+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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\Taxonomy;
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+
private View\Category $view;
41+
42+
public function __construct(View\Category $view)
43+
{
44+
$this->view = $view;
45+
}
46+
47+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
48+
{
49+
$category = $this->view->getEntity(
50+
$request->get('category_id'),
51+
$context
52+
);
53+
54+
if (empty($category)) {
55+
throw new StatusCode\NotFoundException('Could not find category');
56+
}
57+
58+
if ($category['status'] == Table\Category::STATUS_DELETED) {
59+
throw new StatusCode\GoneException('Category was deleted');
60+
}
61+
62+
return $category;
63+
}
64+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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\Taxonomy;
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;
29+
30+
/**
31+
* GetAll
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+
class GetAll implements ActionInterface
38+
{
39+
private View\Category $view;
40+
41+
public function __construct(View\Category $view)
42+
{
43+
$this->view = $view;
44+
}
45+
46+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
47+
{
48+
return $this->view->getCollection(
49+
QueryFilter::from($request),
50+
$context
51+
);
52+
}
53+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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\Taxonomy;
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\Category;
28+
use Fusio\Impl\Service\System\ContextFactory;
29+
use Fusio\Impl\Service\Taxonomy;
30+
use Fusio\Model\Backend\CategoryUpdate;
31+
use Fusio\Model\Backend\TaxonomyUpdate;
32+
33+
/**
34+
* Update
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+
class Update implements ActionInterface
41+
{
42+
private Taxonomy $taxonomyService;
43+
private ContextFactory $contextFactory;
44+
45+
public function __construct(Taxonomy $taxonomyService, ContextFactory $contextFactory)
46+
{
47+
$this->taxonomyService = $taxonomyService;
48+
$this->contextFactory = $contextFactory;
49+
}
50+
51+
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed
52+
{
53+
$body = $request->getPayload();
54+
55+
assert($body instanceof TaxonomyUpdate);
56+
57+
$id = $this->taxonomyService->update(
58+
$request->get('taxonomy_id'),
59+
$body,
60+
$this->contextFactory->newActionContext($context)
61+
);
62+
63+
return [
64+
'success' => true,
65+
'message' => 'Taxonomy successfully updated',
66+
'id' => '' . $id,
67+
];
68+
}
69+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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\Event\Taxonomy;
22+
23+
use Fusio\Impl\Authorization\UserContext;
24+
use Fusio\Impl\Event\EventAbstract;
25+
use Fusio\Model\Backend\TaxonomyCreate;
26+
27+
/**
28+
* CreatedEvent
29+
*
30+
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
31+
* @license http://www.apache.org/licenses/LICENSE-2.0
32+
* @link https://www.fusio-project.org
33+
*/
34+
class CreatedEvent extends EventAbstract
35+
{
36+
private TaxonomyCreate $taxonomy;
37+
38+
public function __construct(TaxonomyCreate $taxonomy, UserContext $context)
39+
{
40+
parent::__construct($context);
41+
42+
$this->taxonomy = $taxonomy;
43+
}
44+
45+
public function getTaxonomy(): TaxonomyCreate
46+
{
47+
return $this->taxonomy;
48+
}
49+
}

0 commit comments

Comments
 (0)