|
| 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 | +} |
0 commit comments