Expand API and routes.

This commit is contained in:
James Cole
2018-12-08 21:26:20 +01:00
parent 3b15415a1b
commit 05b0425929
27 changed files with 686 additions and 516 deletions

View File

@@ -37,19 +37,6 @@ use Symfony\Component\HttpFoundation\ParameterBag;
*/
class CategoryTransformer extends TransformerAbstract
{
/**
* List of resources possible to include
*
* @var array
*/
protected $availableIncludes = ['user', 'transactions'];
/**
* List of resources to automatically include
*
* @var array
*/
protected $defaultIncludes = ['user'];
/** @var ParameterBag */
protected $parameters;
@@ -65,46 +52,6 @@ class CategoryTransformer extends TransformerAbstract
$this->parameters = $parameters;
}
/**
* Include any transactions.
*
* @param Category $category
*
* @codeCoverageIgnore
* @return FractalCollection
*/
public function includeTransactions(Category $category): FractalCollection
{
$pageSize = (int)app('preferences')->getForUser($category->user, 'listPageSize', 50)->data;
// journals always use collector and limited using URL parameters.
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($category->user);
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
$collector->setAllAssetAccounts();
$collector->setCategories(new Collection([$category]));
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$transactions = $collector->getTransactions();
return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**
* Include the user.
*
* @param Category $category
*
* @codeCoverageIgnore
* @return Item
*/
public function includeUser(Category $category): Item
{
return $this->item($category->user, new UserTransformer($this->parameters), 'users');
}
/**
* Convert category.
*