Commit 62478b6b authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Add pagination for door group relationships

parent 4641d0b2
......@@ -36,6 +36,10 @@ class AttemptsController extends ApiController
$presenter
);
return $this->respondWithData($presenter->getViewModel(50));
return $this->respondWithData($presenter->getViewModel([
'start' => $this->request->input('start'),
'end' => $this->request->input('end'),
'door_id' => $this->request->input('door_id'),
]));
}
}
......@@ -21,7 +21,7 @@ class APIPresenter extends BasePresenter implements Presenter
}
/** @inheritDoc */
public function getViewModel(int $perPage, array $appends = []): array
public function getViewModel(array $appends = [], int $perPage = 50): array
{
return $this->paginate($this->attempts, $perPage, $appends);
}
......
......@@ -11,9 +11,9 @@ interface Presenter
public function present(ResponseModel $responseModel): void;
/**
* @param int $perPage
* @param array $appends
* @param int $perPage
* @return array
*/
public function getViewModel(int $perPage, array $appends = []): array;
public function getViewModel(array $appends = [], int $perPage = 50): array;
}
......@@ -3,16 +3,19 @@
namespace Source\UseCases\DoorGroup\GetDoorGroups;
use Source\Entities\Group;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;
class APIPresenter extends BasePresenter implements Presenter
{
protected array $viewModel = [];
use Paginates;
protected array $groups = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel['groups'] = array_map(static function (Group $group) {
$this->groups['groups'] = array_map(static function (Group $group) {
return [
'id' => $group->getId(),
'title' => $group->getTitle(),
......@@ -24,6 +27,6 @@ class APIPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public function getViewModel(): array
{
return $this->viewModel;
return $this->paginate($this->groups);
}
}
......@@ -3,16 +3,19 @@
namespace Source\UseCases\DoorGroup\GetGroupDoors;
use Source\Entities\Door;
use Source\Sanitize\Paginates;
use Source\UseCases\BasePresenter;
class APIPresenter extends BasePresenter implements Presenter
{
protected array $viewModel = [];
use Paginates;
protected array $doors = [];
/** @inheritDoc */
public function present(ResponseModel $responseModel): void
{
$this->viewModel['doors'] = array_map(function (Door $door) {
$this->doors = array_map(function (Door $door) {
return $this->formatDoor($door);
}, $responseModel->getDoors());
}
......@@ -20,6 +23,6 @@ class APIPresenter extends BasePresenter implements Presenter
/** @inheritDoc */
public function getViewModel(): array
{
return $this->viewModel;
return $this->paginate($this->doors);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment