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/Favorites/GetFavoriteUsers.php
2015-08-03 19:23:11 +02:00

48 lines
1.3 KiB
PHP

<?php
namespace Szurubooru\Routes\Favorites;
use Szurubooru\Routes\AbstractRoute;
use Szurubooru\Services\AuthService;
use Szurubooru\Services\FavoritesService;
use Szurubooru\Services\PostService;
use Szurubooru\Services\PrivilegeService;
use Szurubooru\ViewProxies\UserViewProxy;
class GetFavoriteUsers extends AbstractRoute
{
private $privilegeService;
private $authService;
private $postService;
private $favoritesService;
private $userViewProxy;
public function __construct(
PrivilegeService $privilegeService,
AuthService $authService,
PostService $postService,
FavoritesService $favoritesService,
UserViewProxy $userViewProxy)
{
$this->privilegeService = $privilegeService;
$this->authService = $authService;
$this->postService = $postService;
$this->favoritesService = $favoritesService;
$this->userViewProxy = $userViewProxy;
}
public function getMethods()
{
return ['GET'];
}
public function getUrl()
{
return '/api/posts/:postNameOrId/favorites';
}
public function work($args)
{
$post = $this->postService->getByNameOrId($args['postNameOrId']);
$users = $this->favoritesService->getFavoriteUsers($post);
return ['users' => $this->userViewProxy->fromArray($users)];
}
}