|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * ------------------------------------------------------------------------- |
| 5 | + * Tag plugin for GLPI |
| 6 | + * ------------------------------------------------------------------------- |
| 7 | + * |
| 8 | + * LICENSE |
| 9 | + * |
| 10 | + * This file is part of Tag. |
| 11 | + * |
| 12 | + * Tag is free software; you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU General Public License as published by |
| 14 | + * the Free Software Foundation; either version 2 of the License, or |
| 15 | + * (at your option) any later version. |
| 16 | + * |
| 17 | + * Tag is distributed in the hope that it will be useful, |
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | + * GNU General Public License for more details. |
| 21 | + * |
| 22 | + * You should have received a copy of the GNU General Public License |
| 23 | + * along with Tag. If not, see <http://www.gnu.org/licenses/>. |
| 24 | + * ------------------------------------------------------------------------- |
| 25 | + * @copyright Copyright (C) 2014-2022 by Teclib'. |
| 26 | + * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html |
| 27 | + * @link https://github.com/pluginsGLPI/tag |
| 28 | + * ------------------------------------------------------------------------- |
| 29 | + */ |
| 30 | + |
| 31 | +use Glpi\Api\HL\Controller\AbstractController; |
| 32 | +use Glpi\Api\HL\Doc as Doc; |
| 33 | +use Glpi\Api\HL\Route; |
| 34 | +use Glpi\Http\Request; |
| 35 | +use Glpi\Http\Response; |
| 36 | + |
| 37 | +#[Route(path: '/Tag', priority: 1, tags: ['Tag'])] |
| 38 | +final class PluginTagApicontroller extends AbstractController |
| 39 | +{ |
| 40 | + protected static function getRawKnownSchemas(): array |
| 41 | + { |
| 42 | + return [ |
| 43 | + 'Tag' => [ |
| 44 | + 'type' => Doc\Schema::TYPE_OBJECT, |
| 45 | + 'x-itemtype' => PluginTagTag::class, |
| 46 | + 'properties' => [ |
| 47 | + 'id' => [ |
| 48 | + 'type' => Doc\Schema::TYPE_INTEGER, |
| 49 | + 'format' => Doc\Schema::FORMAT_INTEGER_INT64, |
| 50 | + 'x-readonly' => true, |
| 51 | + ], |
| 52 | + 'name' => ['type' => Doc\Schema::TYPE_STRING], |
| 53 | + 'comment' => ['type' => Doc\Schema::TYPE_STRING], |
| 54 | + ] |
| 55 | + ] |
| 56 | + ]; |
| 57 | + } |
| 58 | + |
| 59 | + #[Route(path: '/', methods: ['GET'])] |
| 60 | + #[Doc\Route( |
| 61 | + description: 'List or search tags' |
| 62 | + )] |
| 63 | + public function getTags(Request $request): Response |
| 64 | + { |
| 65 | + return $this->searchBySchema($this->getKnownSchema('Tag'), $request->getParameters()); |
| 66 | + } |
| 67 | + |
| 68 | + #[Route(path: '/{id}', methods: ['GET'], requirements: ['id' => '\d+'])] |
| 69 | + #[Doc\Route( |
| 70 | + description: 'Get a tag by ID', |
| 71 | + parameters: [ |
| 72 | + [ |
| 73 | + 'name' => 'id', |
| 74 | + 'description' => 'The ID of the tag', |
| 75 | + 'location' => Doc\Parameter::LOCATION_PATH, |
| 76 | + 'schema' => ['type' => Doc\Schema::TYPE_INTEGER] |
| 77 | + ] |
| 78 | + ] |
| 79 | + )] |
| 80 | + public function getTag(Request $request, int $id): Response |
| 81 | + { |
| 82 | + return $this->getOneBySchema($this->getKnownSchema('Tag'), $request->getAttributes(), $request->getParameters(), $id); |
| 83 | + } |
| 84 | + |
| 85 | + #[Route(path: '/', methods: ['POST'])] |
| 86 | + #[Doc\Route(description: 'Create a new tag', parameters: [ |
| 87 | + [ |
| 88 | + 'name' => '_', |
| 89 | + 'location' => Doc\Parameter::LOCATION_BODY, |
| 90 | + 'type' => Doc\Schema::TYPE_OBJECT, |
| 91 | + 'schema' => 'Tag', |
| 92 | + ] |
| 93 | + ])] |
| 94 | + public function createTag(Request $request): Response |
| 95 | + { |
| 96 | + return $this->createBySchema($this->getKnownSchema('Tag'), $request->getParameters(), 'getTag'); |
| 97 | + } |
| 98 | + |
| 99 | + #[Route(path: '/{id}', methods: ['PATCH'], requirements: ['id' => '\d+'])] |
| 100 | + #[Doc\Route( |
| 101 | + description: 'Update a tag by ID', |
| 102 | + parameters: [ |
| 103 | + [ |
| 104 | + 'name' => 'id', |
| 105 | + 'description' => 'The ID of the tag', |
| 106 | + 'location' => Doc\Parameter::LOCATION_PATH, |
| 107 | + 'schema' => ['type' => Doc\Schema::TYPE_INTEGER] |
| 108 | + ], |
| 109 | + [ |
| 110 | + 'name' => '_', |
| 111 | + 'location' => Doc\Parameter::LOCATION_BODY, |
| 112 | + 'type' => Doc\Schema::TYPE_OBJECT, |
| 113 | + 'schema' => 'Tag', |
| 114 | + ] |
| 115 | + ], |
| 116 | + responses: [ |
| 117 | + ['schema' => 'Tag'] |
| 118 | + ] |
| 119 | + )] |
| 120 | + public function updateTag(Request $request, int $id): Response |
| 121 | + { |
| 122 | + return $this->updateBySchema($this->getKnownSchema('Tag'), $request->getAttributes(), $request->getParameters(), $id); |
| 123 | + } |
| 124 | + |
| 125 | + #[Route(path: '/{id}', methods: ['DELETE'], requirements: ['id' => '\d+'])] |
| 126 | + #[Doc\Route( |
| 127 | + description: 'Delete a tag by ID', |
| 128 | + parameters: [ |
| 129 | + [ |
| 130 | + 'name' => 'id', |
| 131 | + 'description' => 'The ID of the tag', |
| 132 | + 'location' => Doc\Parameter::LOCATION_PATH, |
| 133 | + 'schema' => ['type' => Doc\Schema::TYPE_INTEGER] |
| 134 | + ] |
| 135 | + ] |
| 136 | + )] |
| 137 | + public function deleteTag(Request $request, int $id): Response |
| 138 | + { |
| 139 | + return $this->deleteBySchema($this->getKnownSchema('Tag'), $request->getAttributes(), $request->getParameters(), $id); |
| 140 | + } |
| 141 | +} |
0 commit comments