This repository has been archived on 2025-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
szurubooru/src/Routes/Posts/GetPosts.php
2014-11-21 12:45:47 +01:00

61 lines
1.6 KiB
PHP

<?php
namespace Szurubooru\Routes\Posts;
use Szurubooru\Config;
use Szurubooru\Controllers\ViewProxies\PostViewProxy;
use Szurubooru\Helpers\InputReader;
use Szurubooru\Privilege;
use Szurubooru\SearchServices\Parsers\PostSearchParser;
use Szurubooru\Services\PostService;
use Szurubooru\Services\PrivilegeService;
class GetPosts extends AbstractPostRoute
{
private $config;
private $privilegeService;
private $postService;
private $postSearchParser;
private $inputReader;
private $postViewProxy;
public function __construct(
Config $config,
PrivilegeService $privilegeService,
PostService $postService,
PostSearchParser $postSearchParser,
InputReader $inputReader,
PostViewProxy $postViewProxy)
{
$this->config = $config;
$this->privilegeService = $privilegeService;
$this->postService = $postService;
$this->postSearchParser = $postSearchParser;
$this->inputReader = $inputReader;
$this->postViewProxy = $postViewProxy;
}
public function getMethods()
{
return ['GET'];
}
public function getUrl()
{
return '/api/posts';
}
public function work()
{
$this->privilegeService->assertPrivilege(Privilege::LIST_POSTS);
$filter = $this->postSearchParser->createFilterFromInputReader($this->inputReader);
$filter->setPageSize($this->config->posts->postsPerPage);
$this->postService->decorateFilterFromBrowsingSettings($filter);
$result = $this->postService->getFiltered($filter);
$entities = $this->postViewProxy->fromArray($result->getEntities(), $this->getLightFetchConfig());
return [
'data' => $entities,
'pageSize' => $result->getPageSize(),
'totalRecords' => $result->getTotalRecords()];
}
}