Skip to content

Commit

Permalink
Allow fixing the default pageSize
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Jan 18, 2016
1 parent f7c56c9 commit 7644cb8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"require-dev": {
"laravel/laravel": "5.*",
"laravel/lumen": "5.*",
"phpunit/phpunit": "4.*",
"fabpot/php-cs-fixer": "^1.10"
},
Expand Down
13 changes: 8 additions & 5 deletions src/NilPortugues/Laravel5/JsonApi/Controller/JsonApiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ trait JsonApiTrait
*/
protected $serializer;

/**
* @var int
*/
protected $pageSize = 10;

/**
* @param JsonApiSerializer $serializer
*/
Expand All @@ -44,17 +49,15 @@ public function __construct(JsonApiSerializer $serializer)
/**
* Get many resources.
*
* @param int $pageSize
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function index($pageSize = 10)
public function index()
{
$apiRequest = RequestFactory::create();

$page = $apiRequest->getPage();
if (!$page->size()) {
$page->setSize($pageSize);
$page->setSize($this->pageSize);
}

$fields = $apiRequest->getFields();
Expand All @@ -67,7 +70,7 @@ public function index($pageSize = 10)
$totalAmount = $this->totalAmountResourceCallable();
$results = $this->listResourceCallable();

$controllerAction = '\\'.get_class($this).'@index';
$controllerAction = '\\'.get_called_class().'@index';
$uri = action($controllerAction, []);

return $this->addHeaders($resource->get($totalAmount, $results, $uri, get_class($this->getDataModel())));
Expand Down
3 changes: 1 addition & 2 deletions tests/NilPortugues/App/Controller/EmployeesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ public function getOrdersByEmployee($id)
{
$apiRequest = RequestFactory::create();

$pageSize = 10;
$page = $apiRequest->getPage();
if (!$page->size()) {
$page->setSize($pageSize);
$page->setSize($this->pageSize);
}

$fields = $apiRequest->getFields();
Expand Down

0 comments on commit 7644cb8

Please sign in to comment.