diff --git a/extensions/tags/src/Api/Controller/ListTagsController.php b/extensions/tags/src/Api/Controller/ListTagsController.php new file mode 100644 index 000000000..3c10f9697 --- /dev/null +++ b/extensions/tags/src/Api/Controller/ListTagsController.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Tags\Api\Controller; + +use Flarum\Api\Controller\AbstractCollectionController; +use Flarum\Tags\Api\Serializer\TagSerializer; +use Flarum\Tags\TagRepository; +use Psr\Http\Message\ServerRequestInterface; +use Tobscure\JsonApi\Document; + +class ListTagsController extends AbstractCollectionController +{ + /** + * {@inheritdoc} + */ + public $serializer = TagSerializer::class; + + /** + * @var \Flarum\Tags\TagRepository + */ + protected $tags; + + /** + * @param \Flarum\Tags\TagRepository $tags + */ + public function __construct(TagRepository $tags) + { + $this->tags = $tags; + } + + /** + * {@inheritdoc} + */ + protected function data(ServerRequestInterface $request, Document $document) + { + return $this->tags->all(); + } +} diff --git a/extensions/tags/src/Listener/AddTagsApi.php b/extensions/tags/src/Listener/AddTagsApi.php index 29f66d846..6190202e6 100755 --- a/extensions/tags/src/Listener/AddTagsApi.php +++ b/extensions/tags/src/Listener/AddTagsApi.php @@ -24,6 +24,7 @@ class AddTagsApi public function configureApiRoutes(ConfigureApiRoutes $event) { + $event->get('/tags', 'tags.index', Controller\ListTagsController::class); $event->post('/tags', 'tags.create', Controller\CreateTagController::class); $event->post('/tags/order', 'tags.order', Controller\OrderTagsController::class); $event->patch('/tags/{id}', 'tags.update', Controller\UpdateTagController::class); diff --git a/extensions/tags/src/TagRepository.php b/extensions/tags/src/TagRepository.php index 76687ec5e..4cad9deb5 100644 --- a/extensions/tags/src/TagRepository.php +++ b/extensions/tags/src/TagRepository.php @@ -41,7 +41,7 @@ class TagRepository */ public function all(User $user = null) { - $query = Tag::newQuery(); + $query = Tag::query(); return $this->scopeVisibleTo($query, $user)->get(); }