Skip to content

Commit

Permalink
use sort
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Jan 30, 2024
1 parent f897796 commit 4d197f3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Api/Controllers/ListPollsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Flarum\Http\UrlGenerator;
use FoF\Polls\Api\Serializers\PollSerializer;
use FoF\Polls\Poll;
use FoF\Polls\PollRepository;
use Illuminate\Database\Eloquent\Collection;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
Expand All @@ -31,13 +32,19 @@ class ListPollsController extends AbstractListController
'myVotes.option',
];

/**
* @var PollRepository
*/
protected $polls;

/**
* @var UrlGenerator
*/
protected $url;

public function __construct(UrlGenerator $url)
public function __construct(PollRepository $polls, UrlGenerator $url)
{
$this->polls = $polls;
$this->url = $url;
}

Expand All @@ -47,17 +54,16 @@ public function data(ServerRequestInterface $request, Document $document): Colle

// Not yet needed, but here if/when we do.
// $filters = $this->extractFilter($request);
// $sort = $this->extractSort($request);
// $sortIsDefault = $this->sortIsDefault($request);
$sort = $this->extractSort($request);
$sortIsDefault = $this->sortIsDefault($request);

$limit = $this->extractLimit($request);
$offset = $this->extractOffset($request);
$include = $this->extractInclude($request);

$results = Poll::query()
$results = $this->polls->queryVisibleTo($actor)
->select('polls.*')
->whereVisibleTo($actor)
->orderBy('id')
->orderBy($sortIsDefault ? 'id' : $sort, 'desc')
->skip($offset)
->take($limit);

Expand Down

0 comments on commit 4d197f3

Please sign in to comment.