Merge pull request #28

Closes flarum/core#600.
This commit is contained in:
Franz Liedke 2016-04-15 21:06:01 +09:00
commit 6e0f77b0e3
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($request->getAttribute('actor'));
}
}

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();
}