mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 06:53:47 +08:00
Added REST tags endpoint (https://github.com/flarum/core/issues/600)
This commit is contained in:
parent
36c4c5d966
commit
1b23e44b06
47
extensions/tags/src/Api/Controller/ListTagsController.php
Normal file
47
extensions/tags/src/Api/Controller/ListTagsController.php
Normal 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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -41,7 +41,7 @@ class TagRepository
|
|||
*/
|
||||
public function all(User $user = null)
|
||||
{
|
||||
$query = Tag::newQuery();
|
||||
$query = Tag::query();
|
||||
|
||||
return $this->scopeVisibleTo($query, $user)->get();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user