This commit is contained in:
Niels Tholenaar 2016-04-14 12:08:21 +02:00
parent 36c4c5d966
commit 1b23e44b06
3 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,47 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* 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();
}
}

View File

@ -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);

View File

@ -41,7 +41,7 @@ class TagRepository
*/
public function all(User $user = null)
{
$query = Tag::newQuery();
$query = Tag::query();
return $this->scopeVisibleTo($query, $user)->get();
}