Fix rule group API

This commit is contained in:
James Cole 2021-03-06 18:00:49 +01:00
parent cfa9e8b318
commit 4ba713e553
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
12 changed files with 818 additions and 550 deletions

View File

@ -0,0 +1,73 @@
<?php
/*
* DestroyController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Models\RuleGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
* Class DestroyController
*/
class DestroyController extends Controller
{
private RuleGroupRepositoryInterface $ruleGroupRepository;
/**
* RuleGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->ruleGroupRepository->setUser($user);
return $next($request);
}
);
}
/**
* Delete the resource.
*
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function destroy(RuleGroup $ruleGroup): JsonResponse
{
$this->ruleGroupRepository->destroy($ruleGroup, null);
return response()->json([], 204);
}
}

View File

@ -0,0 +1,96 @@
<?php
/*
* ListController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Models\RuleGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
/**
* Class ListController
*/
class ListController extends Controller
{
private RuleGroupRepositoryInterface $ruleGroupRepository;
/**
* RuleGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->ruleGroupRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param RuleGroup $group
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function rules(RuleGroup $group): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->ruleGroupRepository->getRules($group);
$count = $collection->count();
$rules = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.rule_groups.rules', [$group->id]) . $this->buildParams());
/** @var RuleTransformer $transformer */
$transformer = app(RuleTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($rules, $transformer, 'rules');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@ -0,0 +1,119 @@
<?php
/*
* ShowController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Models\RuleGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Transformers\RuleGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class ShowController
*/
class ShowController extends Controller
{
private RuleGroupRepositoryInterface $ruleGroupRepository;
/**
* RuleGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->ruleGroupRepository->setUser($user);
return $next($request);
}
);
}
/**
* List all of them.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of rule groups. Count it and split it.
$collection = $this->ruleGroupRepository->get();
$count = $collection->count();
$ruleGroups = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($ruleGroups, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.rule_groups.index') . $this->buildParams());
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($ruleGroups, $transformer, 'rule_groups');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List single resource.
*
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(RuleGroup $ruleGroup): JsonResponse
{
$manager = $this->getManager();
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@ -0,0 +1,90 @@
<?php
/*
* StoreController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Models\RuleGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\RuleGroup\StoreRequest;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Transformers\RuleGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class StoreController
*/
class StoreController extends Controller
{
private AccountRepositoryInterface $accountRepository;
private RuleGroupRepositoryInterface $ruleGroupRepository;
/**
* RuleGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->ruleGroupRepository->setUser($user);
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->accountRepository->setUser($user);
return $next($request);
}
);
}
/**
* Store new object.
*
* @param StoreRequest $request
*
* @return JsonResponse
*/
public function store(StoreRequest $request): JsonResponse
{
$ruleGroup = $this->ruleGroupRepository->store($request->getAll());
$manager = $this->getManager();
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@ -0,0 +1,169 @@
<?php
/*
* TriggerController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Models\RuleGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\RuleGroup\TestRequest;
use FireflyIII\Api\V1\Requests\Models\RuleGroup\TriggerRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\TransactionRules\Engine\RuleEngineInterface;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
/**
* Class TriggerController
*/
class TriggerController extends Controller
{
private RuleGroupRepositoryInterface $ruleGroupRepository;
/**
* RuleGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->ruleGroupRepository->setUser($user);
return $next($request);
}
);
}
/**
* @param TestRequest $request
* @param RuleGroup $group
*
* @return JsonResponse
* @throws FireflyException
*
*/
public function testGroup(TestRequest $request, RuleGroup $group): JsonResponse
{
/** @var Collection $rules */
$rules = $this->ruleGroupRepository->getActiveRules($group);
if (0 === $rules->count()) {
throw new FireflyException('200023: No rules in this rule group.');
}
$parameters = $request->getTestParameters();
/** @var RuleEngineInterface $ruleEngine */
$ruleEngine = app(RuleEngineInterface::class);
$ruleEngine->setRules($rules);
// overrule the rule(s) if necessary.
if (array_key_exists('start', $parameters) && null !== $parameters['start']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_after', 'value' => $parameters['start']->format('Y-m-d')]);
}
if (array_key_exists('end', $parameters) && null !== $parameters['end']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_before', 'value' => $parameters['end']->format('Y-m-d')]);
}
if (array_key_exists('accounts', $parameters) && '' !== $parameters['accounts']) {
$ruleEngine->addOperator(['type' => 'account_id', 'value' => implode(',', $parameters['accounts'])]);
}
// file the rule(s)
$transactions = $ruleEngine->find();
$count = $transactions->count();
$paginator = new LengthAwarePaginator($transactions, $count, 31337, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.rule_groups.test', [$group->id]) . $this->buildParams());
// resulting list is presented as JSON thing.
$manager = $this->getManager();
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Execute the given rule group on a set of existing transactions.
*
* @param TriggerRequest $request
* @param RuleGroup $group
*
* @return JsonResponse
* @throws Exception
*/
public function triggerGroup(TriggerRequest $request, RuleGroup $group): JsonResponse
{
/** @var Collection $rules */
$rules = $this->ruleGroupRepository->getActiveRules($group);
if (0 === $rules->count()) {
throw new FireflyException('200023: No rules in this rule group.');
}
// Get parameters specified by the user
$parameters = $request->getTriggerParameters();
/** @var RuleEngineInterface $ruleEngine */
$ruleEngine = app(RuleEngineInterface::class);
$ruleEngine->setRules($rules);
// overrule the rule(s) if necessary.
if (array_key_exists('start', $parameters) && null !== $parameters['start']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_after', 'value' => $parameters['start']->format('Y-m-d')]);
}
if (array_key_exists('end', $parameters) && null !== $parameters['end']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_before', 'value' => $parameters['end']->format('Y-m-d')]);
}
if (array_key_exists('accounts', $parameters) && '' !== $parameters['accounts']) {
$ruleEngine->addOperator(['type' => 'account_id', 'value' => implode(',', $parameters['accounts'])]);
}
// file the rule(s)
$ruleEngine->fire();
return response()->json([], 204);
}
}

View File

@ -0,0 +1,86 @@
<?php
/*
* UpdateController.php
* Copyright (c) 2021 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Models\RuleGroup;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Models\RuleGroup\UpdateRequest;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Transformers\RuleGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use League\Fractal\Resource\Item;
/**
* Class UpdateController
*/
class UpdateController extends Controller
{
private RuleGroupRepositoryInterface $ruleGroupRepository;
/**
* RuleGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->ruleGroupRepository->setUser($user);
return $next($request);
}
);
}
/**
* Update a rule group.
*
* @param UpdateRequest $request
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
*/
public function update(UpdateRequest $request, RuleGroup $ruleGroup): JsonResponse
{
$ruleGroup = $this->ruleGroupRepository->update($ruleGroup, $request->getAll());
$manager = $this->getManager();
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@ -1,363 +0,0 @@
<?php
/**
* RuleGroupController.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
use Exception;
use FireflyIII\Api\V1\Requests\RuleGroupUpdateRequest;
use FireflyIII\Api\V1\Requests\RuleGroupStoreRequest;
use FireflyIII\Api\V1\Requests\RuleGroupTestRequest;
use FireflyIII\Api\V1\Requests\RuleGroupTriggerRequest;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\TransactionRules\Engine\RuleEngineInterface;
use FireflyIII\Transformers\RuleGroupTransformer;
use FireflyIII\Transformers\RuleTransformer;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
use League\Fractal\Resource\Item;
/**
* Class RuleGroupController
*/
class RuleGroupController extends Controller
{
/** @var AccountRepositoryInterface Account repository */
private $accountRepository;
/** @var RuleGroupRepositoryInterface The rule group repository */
private $ruleGroupRepository;
/**
* RuleGroupController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->ruleGroupRepository->setUser($user);
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->accountRepository->setUser($user);
return $next($request);
}
);
}
/**
* Delete the resource.
*
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function delete(RuleGroup $ruleGroup): JsonResponse
{
$this->ruleGroupRepository->destroy($ruleGroup, null);
return response()->json([], 204);
}
/**
* List all of them.
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function index(): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of rule groups. Count it and split it.
$collection = $this->ruleGroupRepository->get();
$count = $collection->count();
$ruleGroups = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($ruleGroups, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.rule_groups.index') . $this->buildParams());
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($ruleGroups, $transformer, 'rule_groups');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
*/
public function moveDown(RuleGroup $ruleGroup): JsonResponse
{
$this->ruleGroupRepository->moveDown($ruleGroup);
$ruleGroup = $this->ruleGroupRepository->find($ruleGroup->id);
$manager = $this->getManager();
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
*/
public function moveUp(RuleGroup $ruleGroup): JsonResponse
{
$this->ruleGroupRepository->moveUp($ruleGroup);
$ruleGroup = $this->ruleGroupRepository->find($ruleGroup->id);
$manager = $this->getManager();
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* @param RuleGroup $group
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function rules(RuleGroup $group): JsonResponse
{
$manager = $this->getManager();
// types to get, page size:
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
// get list of budgets. Count it and split it.
$collection = $this->ruleGroupRepository->getRules($group);
$count = $collection->count();
$rules = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
// make paginator:
$paginator = new LengthAwarePaginator($rules, $count, $pageSize, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.rule_groups.rules', [$group->id]) . $this->buildParams());
/** @var RuleTransformer $transformer */
$transformer = app(RuleTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($rules, $transformer, 'rules');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* List single resource.
*
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
* @codeCoverageIgnore
*/
public function show(RuleGroup $ruleGroup): JsonResponse
{
$manager = $this->getManager();
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Store new object.
*
* @param RuleGroupStoreRequest $request
*
* @return JsonResponse
*/
public function store(RuleGroupStoreRequest $request): JsonResponse
{
$ruleGroup = $this->ruleGroupRepository->store($request->getAll());
$manager = $this->getManager();
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* @param RuleGroupTestRequest $request
* @param RuleGroup $group
*
* @return JsonResponse
* @throws FireflyException
*
*/
public function testGroup(RuleGroupTestRequest $request, RuleGroup $group): JsonResponse
{
/** @var Collection $rules */
$rules = $this->ruleGroupRepository->getActiveRules($group);
if (0 === $rules->count()) {
throw new FireflyException('200023: No rules in this rule group.');
}
$parameters = $request->getTestParameters();
/** @var RuleEngineInterface $ruleEngine */
$ruleEngine = app(RuleEngineInterface::class);
$ruleEngine->setRules($rules);
// overrule the rule(s) if necessary.
if (array_key_exists('start', $parameters) && null !== $parameters['start']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_after', 'value' => $parameters['start']->format('Y-m-d')]);
}
if (array_key_exists('end', $parameters) && null !== $parameters['end']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_before', 'value' => $parameters['end']->format('Y-m-d')]);
}
if (array_key_exists('accounts', $parameters) && '' !== $parameters['accounts']) {
$ruleEngine->addOperator(['type' => 'account_id', 'value' => $parameters['accounts']]);
}
// file the rule(s)
$transactions = $ruleEngine->find();
$count = $transactions->count();
$paginator = new LengthAwarePaginator($transactions, $count, 31337, $this->parameters->get('page'));
$paginator->setPath(route('api.v1.rule_groups.test', [$group->id]) . $this->buildParams());
// resulting list is presented as JSON thing.
$manager = $this->getManager();
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new FractalCollection($transactions, $transformer, 'transactions');
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
/**
* Execute the given rule group on a set of existing transactions.
*
* @param RuleGroupTriggerRequest $request
* @param RuleGroup $group
*
* @return JsonResponse
* @throws Exception
*/
public function triggerGroup(RuleGroupTriggerRequest $request, RuleGroup $group): JsonResponse
{
/** @var Collection $rules */
$rules = $this->ruleGroupRepository->getActiveRules($group);
if (0 === $rules->count()) {
throw new FireflyException('200023: No rules in this rule group.');
}
// Get parameters specified by the user
$parameters = $request->getTriggerParameters();
/** @var RuleEngineInterface $ruleEngine */
$ruleEngine = app(RuleEngineInterface::class);
$ruleEngine->setRules($rules);
// overrule the rule(s) if necessary.
if (array_key_exists('start', $parameters) && null !== $parameters['start']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_after', 'value' => $parameters['start']->format('Y-m-d')]);
}
if (array_key_exists('end', $parameters) && null !== $parameters['end']) {
// add a range:
$ruleEngine->addOperator(['type' => 'date_before', 'value' => $parameters['end']->format('Y-m-d')]);
}
if (array_key_exists('accounts', $parameters) && '' !== $parameters['accounts']) {
$ruleEngine->addOperator(['type' => 'account_id', 'value' => $parameters['accounts']]);
}
// file the rule(s)
$ruleEngine->fire();
return response()->json([], 204);
}
/**
* Update a rule group.
*
* @param RuleGroupUpdateRequest $request
* @param RuleGroup $ruleGroup
*
* @return JsonResponse
*/
public function update(RuleGroupUpdateRequest $request, RuleGroup $ruleGroup): JsonResponse
{
$ruleGroup = $this->ruleGroupRepository->update($ruleGroup, $request->getAll());
$manager = $this->getManager();
/** @var RuleGroupTransformer $transformer */
$transformer = app(RuleGroupTransformer::class);
$transformer->setParameters($this->parameters);
$resource = new Item($ruleGroup, $transformer, 'rule_groups');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
}
}

View File

@ -21,7 +21,7 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
namespace FireflyIII\Api\V1\Requests\Models\RuleGroup;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Rules\IsBoolean;
@ -32,9 +32,9 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* @codeCoverageIgnore
* Class RuleGroupStoreRequest
* Class StoreRequest
*/
class RuleGroupStoreRequest extends FormRequest
class StoreRequest extends FormRequest
{
use ConvertsDataTypes, ChecksLogin;

View File

@ -22,7 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
namespace FireflyIII\Api\V1\Requests\Models\RuleGroup;
use Carbon\Carbon;
@ -32,9 +32,9 @@ use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Collection;
/**
* Class RuleGroupTestRequest
* Class TestRequest
*/
class RuleGroupTestRequest extends FormRequest
class TestRequest extends FormRequest
{
use ConvertsDataTypes, ChecksLogin;
@ -63,11 +63,11 @@ class RuleGroupTestRequest extends FormRequest
}
/**
* @return Collection
* @return array
*/
private function getAccounts(): string
private function getAccounts(): array
{
return (string) $this->query('accounts');
return $this->get('accounts');
}
/**

View File

@ -22,7 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
namespace FireflyIII\Api\V1\Requests\Models\RuleGroup;
use Carbon\Carbon;
@ -31,9 +31,9 @@ use FireflyIII\Support\Request\ConvertsDataTypes;
use Illuminate\Foundation\Http\FormRequest;
/**
* Class RuleGroupTriggerRequest
* Class TriggerRequest
*/
class RuleGroupTriggerRequest extends FormRequest
class TriggerRequest extends FormRequest
{
use ConvertsDataTypes, ChecksLogin;
@ -62,11 +62,11 @@ class RuleGroupTriggerRequest extends FormRequest
}
/**
* @return string
* @return array
*/
private function getAccounts(): string
private function getAccounts(): array
{
return (string) $this->query('accounts');
return $this->get('accounts');
}
/**

View File

@ -21,7 +21,7 @@
declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests;
namespace FireflyIII\Api\V1\Requests\Models\RuleGroup;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Support\Request\ChecksLogin;
@ -31,9 +31,9 @@ use Illuminate\Foundation\Http\FormRequest;
/**
* @codeCoverageIgnore
* Class RuleGroupUpdateRequest
* Class UpdateRequest
*/
class RuleGroupUpdateRequest extends FormRequest
class UpdateRequest extends FormRequest
{
use ConvertsDataTypes, ChecksLogin;

View File

@ -334,15 +334,33 @@ Route::group(
Route::put('{rule}', ['uses' => 'UpdateController@update', 'as' => 'update']);
Route::delete('{rule}', ['uses' => 'DestroyController@destroy', 'as' => 'delete']);
// TODO verify if accounts works.
Route::get('{rule}/test', ['uses' => 'TriggerController@testRule', 'as' => 'test']);
// TODO give results back.
Route::post('{rule}/trigger', ['uses' => 'TriggerController@triggerRule', 'as' => 'trigger']);
// TODO rule transactions, rule bills?
}
);
// Rules API routes:
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers\Models\RuleGroup', 'prefix' => 'rule_groups',
'as' => 'api.v1.rule_groups.',],
static function () {
Route::get('', ['uses' => 'ShowController@index', 'as' => 'index']);
Route::post('', ['uses' => 'StoreController@store', 'as' => 'store']);
Route::get('{ruleGroup}', ['uses' => 'ShowController@show', 'as' => 'show']);
Route::put('{ruleGroup}', ['uses' => 'UpdateController@update', 'as' => 'update']);
Route::delete('{ruleGroup}', ['uses' => 'DestroyController@destroy', 'as' => 'delete']);
Route::get('{ruleGroup}/test', ['uses' => 'TriggerController@testGroup', 'as' => 'test']);
Route::post('{ruleGroup}/trigger', ['uses' => 'TriggerController@triggerGroup', 'as' => 'trigger']);
Route::get('{ruleGroup}/rules', ['uses' => 'ListController@rules', 'as' => 'rules']);
}
);
@ -514,170 +532,150 @@ Route::group(
// TODO VERIFY API DOCS
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'rule_groups',
'as' => 'api.v1.rule_groups.',],
static function () {
// Rules API routes:
Route::get('', ['uses' => 'RuleGroupController@index', 'as' => 'index']);
Route::post('', ['uses' => 'RuleGroupController@store', 'as' => 'store']);
Route::get('{ruleGroup}', ['uses' => 'RuleGroupController@show', 'as' => 'show']);
Route::put('{ruleGroup}', ['uses' => 'RuleGroupController@update', 'as' => 'update']);
Route::delete('{ruleGroup}', ['uses' => 'RuleGroupController@delete', 'as' => 'delete']);
Route::get('{ruleGroup}/test', ['uses' => 'RuleGroupController@testGroup', 'as' => 'test']);
Route::get('{ruleGroup}/rules', ['uses' => 'RuleGroupController@rules', 'as' => 'rules']);
Route::post('{ruleGroup}/trigger', ['uses' => 'RuleGroupController@triggerGroup', 'as' => 'trigger']);
Route::post('{ruleGroup}/up', ['uses' => 'RuleGroupController@moveUp', 'as' => 'up']);
Route::post('{ruleGroup}/down', ['uses' => 'RuleGroupController@moveDown', 'as' => 'down']);
}
);
// TODO VERIFY API DOCS
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers\Search', 'prefix' => 'search',
'as' => 'api.v1.search.',],
static function () {
// Attachment API routes:
Route::get('transactions', ['uses' => 'TransactionController@search', 'as' => 'transactions']);
Route::get('accounts', ['uses' => 'AccountController@search', 'as' => 'accounts']);
}
);
// TODO VERIFY API DOCS
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers\Webhook', 'prefix' => 'webhooks',
'as' => 'api.v1.webhooks.',],
static function () {
// Webhook API routes:
Route::get('', ['uses' => 'IndexController@index', 'as' => 'index']);
// create new one.
Route::post('', ['uses' => 'CreateController@store', 'as' => 'store']);
// update
Route::put('{webhook}', ['uses' => 'EditController@update', 'as' => 'update']);
Route::delete('{webhook}', ['uses' => 'DeleteController@destroy', 'as' => 'destroy']);
}
);
// destroy data route.
// TODO VERIFY API DOCS
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'data',
'as' => 'api.v1.data.',],
static function () {
// Overview API routes:
Route::delete('destroy', ['uses' => 'Data\DestroyController@destroy', 'as' => 'destroy']);
}
);
// TODO VERIFY API DOCS
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'currencies',
'as' => 'api.v1.currencies.',],
static function () {
// Transaction currency API routes:
Route::get('', ['uses' => 'CurrencyController@index', 'as' => 'index']);
Route::post('', ['uses' => 'CurrencyController@store', 'as' => 'store']);
Route::get('default', ['uses' => 'CurrencyController@showDefault', 'as' => 'show.default']);
Route::get('{currency_code}', ['uses' => 'CurrencyController@show', 'as' => 'show']);
Route::put('{currency_code}', ['uses' => 'CurrencyController@update', 'as' => 'update']);
Route::delete('{currency_code}', ['uses' => 'CurrencyController@delete', 'as' => 'delete']);
Route::post('{currency_code}/enable', ['uses' => 'CurrencyController@enable', 'as' => 'enable']);
Route::post('{currency_code}/disable', ['uses' => 'CurrencyController@disable', 'as' => 'disable']);
Route::post('{currency_code}/default', ['uses' => 'CurrencyController@makeDefault', 'as' => 'default']);
Route::get('{currency_code}/accounts', ['uses' => 'CurrencyController@accounts', 'as' => 'accounts']);
Route::get('{currency_code}/available_budgets', ['uses' => 'CurrencyController@availableBudgets', 'as' => 'available_budgets']);
Route::get('{currency_code}/bills', ['uses' => 'CurrencyController@bills', 'as' => 'bills']);
Route::get('{currency_code}/budget_limits', ['uses' => 'CurrencyController@budgetLimits', 'as' => 'budget_limits']);
Route::get('{currency_code}/cer', ['uses' => 'CurrencyController@cer', 'as' => 'cer']);
Route::get('{currency_code}/recurrences', ['uses' => 'CurrencyController@recurrences', 'as' => 'recurrences']);
Route::get('{currency_code}/rules', ['uses' => 'CurrencyController@rules', 'as' => 'rules']);
Route::get('{currency_code}/transactions', ['uses' => 'CurrencyController@transactions', 'as' => 'transactions']);
}
);
// TODO VERIFY API DOCS
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'tags',
'as' => 'api.v1.tags.',],
static function () {
// Tag API routes:
Route::get('', ['uses' => 'TagController@index', 'as' => 'index']);
Route::post('', ['uses' => 'TagController@store', 'as' => 'store']);
Route::get('{tagOrId}', ['uses' => 'TagController@show', 'as' => 'show']);
Route::put('{tagOrId}', ['uses' => 'TagController@update', 'as' => 'update']);
Route::delete('{tagOrId}', ['uses' => 'TagController@delete', 'as' => 'delete']);
Route::get('{tagOrId}/transactions', ['uses' => 'TagController@transactions', 'as' => 'transactions']);
Route::get('{tagOrId}/attachments', ['uses' => 'TagController@attachments', 'as' => 'attachments']);
}
);
// TODO VERIFY API DOCS
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'tag-cloud',
'as' => 'api.v1.tag-cloud.',],
static function () {
// Tag cloud API routes (to prevent collisions)
Route::get('', ['uses' => 'TagController@cloud', 'as' => 'cloud']);
}
);
// TODO VERIFY API DOCS
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'transactions',
'as' => 'api.v1.transactions.',],
static function () {
// Transaction API routes:
Route::get('', ['uses' => 'Models\Transaction\ShowController@index', 'as' => 'index']);
Route::post('', ['uses' => 'Models\Transaction\StoreController@store', 'as' => 'store']);
Route::get('{transactionGroup}', ['uses' => 'Models\Transaction\ShowController@show', 'as' => 'show']);
Route::get('{transactionGroup}/attachments', ['uses' => 'Models\Transaction\ListController@attachments', 'as' => 'attachments']);
Route::get('{transactionGroup}/piggy_bank_events', ['uses' => 'Models\Transaction\ListController@piggyBankEvents', 'as' => 'piggy_bank_events']);
Route::get('{tj}/links', ['uses' => 'Models\Transaction\ListController@transactionLinks', 'as' => 'transaction_links']);
Route::put('{transactionGroup}', ['uses' => 'Models\Transaction\UpdateController@update', 'as' => 'update']);
Route::delete('{transactionGroup}/{tj}', ['uses' => 'Models\Transaction\DestroyController@destroyJournal', 'as' => 'delete-journal']);
Route::delete('{transactionGroup}', ['uses' => 'Models\Transaction\DestroyController@destroy', 'as' => 'delete']);
}
);
// special group for transaction journals
// TODO VERIFY API DOCS
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers\Models\Transaction', 'prefix' => 'transaction-journals',
'as' => 'api.v1.journals.',],
static function () {
// Transaction API routes:
Route::get('{tj}', ['uses' => 'ShowController@showByJournal', 'as' => 'showByJournal']);
}
);
// TODO VERIFY API DOCS
Route::group(
['middleware' => ['auth:api', 'bindings', IsAdmin::class], 'namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'users',
'as' => 'api.v1.users.',],
static function () {
// Users API routes:
Route::get('', ['uses' => 'UserController@index', 'as' => 'index']);
Route::post('', ['uses' => 'UserController@store', 'as' => 'store']);
Route::get('{user}', ['uses' => 'UserController@show', 'as' => 'show']);
Route::put('{user}', ['uses' => 'UserController@update', 'as' => 'update']);
Route::delete('{user}', ['uses' => 'UserController@delete', 'as' => 'delete']);
}
);
//
//
//// TODO VERIFY API DOCS
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers\Search', 'prefix' => 'search',
// 'as' => 'api.v1.search.',],
// static function () {
//
// // Attachment API routes:
// Route::get('transactions', ['uses' => 'TransactionController@search', 'as' => 'transactions']);
// Route::get('accounts', ['uses' => 'AccountController@search', 'as' => 'accounts']);
// }
//);
//
//// TODO VERIFY API DOCS
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers\Webhook', 'prefix' => 'webhooks',
// 'as' => 'api.v1.webhooks.',],
// static function () {
//
// // Webhook API routes:
// Route::get('', ['uses' => 'IndexController@index', 'as' => 'index']);
//
// // create new one.
// Route::post('', ['uses' => 'CreateController@store', 'as' => 'store']);
//
// // update
// Route::put('{webhook}', ['uses' => 'EditController@update', 'as' => 'update']);
// Route::delete('{webhook}', ['uses' => 'DeleteController@destroy', 'as' => 'destroy']);
// }
//);
//
//
//// destroy data route.
//// TODO VERIFY API DOCS
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'data',
// 'as' => 'api.v1.data.',],
// static function () {
//
// // Overview API routes:
// Route::delete('destroy', ['uses' => 'Data\DestroyController@destroy', 'as' => 'destroy']);
// }
//);
//
//
//// TODO VERIFY API DOCS
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'currencies',
// 'as' => 'api.v1.currencies.',],
// static function () {
//
// // Transaction currency API routes:
// Route::get('', ['uses' => 'CurrencyController@index', 'as' => 'index']);
// Route::post('', ['uses' => 'CurrencyController@store', 'as' => 'store']);
// Route::get('default', ['uses' => 'CurrencyController@showDefault', 'as' => 'show.default']);
// Route::get('{currency_code}', ['uses' => 'CurrencyController@show', 'as' => 'show']);
// Route::put('{currency_code}', ['uses' => 'CurrencyController@update', 'as' => 'update']);
// Route::delete('{currency_code}', ['uses' => 'CurrencyController@delete', 'as' => 'delete']);
//
// Route::post('{currency_code}/enable', ['uses' => 'CurrencyController@enable', 'as' => 'enable']);
// Route::post('{currency_code}/disable', ['uses' => 'CurrencyController@disable', 'as' => 'disable']);
// Route::post('{currency_code}/default', ['uses' => 'CurrencyController@makeDefault', 'as' => 'default']);
//
// Route::get('{currency_code}/accounts', ['uses' => 'CurrencyController@accounts', 'as' => 'accounts']);
// Route::get('{currency_code}/available_budgets', ['uses' => 'CurrencyController@availableBudgets', 'as' => 'available_budgets']);
// Route::get('{currency_code}/bills', ['uses' => 'CurrencyController@bills', 'as' => 'bills']);
// Route::get('{currency_code}/budget_limits', ['uses' => 'CurrencyController@budgetLimits', 'as' => 'budget_limits']);
// Route::get('{currency_code}/cer', ['uses' => 'CurrencyController@cer', 'as' => 'cer']);
// Route::get('{currency_code}/recurrences', ['uses' => 'CurrencyController@recurrences', 'as' => 'recurrences']);
// Route::get('{currency_code}/rules', ['uses' => 'CurrencyController@rules', 'as' => 'rules']);
// Route::get('{currency_code}/transactions', ['uses' => 'CurrencyController@transactions', 'as' => 'transactions']);
// }
//);
//
//// TODO VERIFY API DOCS
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'tags',
// 'as' => 'api.v1.tags.',],
// static function () {
// // Tag API routes:
// Route::get('', ['uses' => 'TagController@index', 'as' => 'index']);
// Route::post('', ['uses' => 'TagController@store', 'as' => 'store']);
// Route::get('{tagOrId}', ['uses' => 'TagController@show', 'as' => 'show']);
// Route::put('{tagOrId}', ['uses' => 'TagController@update', 'as' => 'update']);
// Route::delete('{tagOrId}', ['uses' => 'TagController@delete', 'as' => 'delete']);
//
// Route::get('{tagOrId}/transactions', ['uses' => 'TagController@transactions', 'as' => 'transactions']);
// Route::get('{tagOrId}/attachments', ['uses' => 'TagController@attachments', 'as' => 'attachments']);
// }
//);
//
//// TODO VERIFY API DOCS
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'tag-cloud',
// 'as' => 'api.v1.tag-cloud.',],
// static function () {
// // Tag cloud API routes (to prevent collisions)
// Route::get('', ['uses' => 'TagController@cloud', 'as' => 'cloud']);
// }
//);
//
//// TODO VERIFY API DOCS
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'transactions',
// 'as' => 'api.v1.transactions.',],
// static function () {
//
// // Transaction API routes:
// Route::get('', ['uses' => 'Models\Transaction\ShowController@index', 'as' => 'index']);
// Route::post('', ['uses' => 'Models\Transaction\StoreController@store', 'as' => 'store']);
// Route::get('{transactionGroup}', ['uses' => 'Models\Transaction\ShowController@show', 'as' => 'show']);
// Route::get('{transactionGroup}/attachments', ['uses' => 'Models\Transaction\ListController@attachments', 'as' => 'attachments']);
// Route::get('{transactionGroup}/piggy_bank_events', ['uses' => 'Models\Transaction\ListController@piggyBankEvents', 'as' => 'piggy_bank_events']);
// Route::get('{tj}/links', ['uses' => 'Models\Transaction\ListController@transactionLinks', 'as' => 'transaction_links']);
// Route::put('{transactionGroup}', ['uses' => 'Models\Transaction\UpdateController@update', 'as' => 'update']);
// Route::delete('{transactionGroup}/{tj}', ['uses' => 'Models\Transaction\DestroyController@destroyJournal', 'as' => 'delete-journal']);
// Route::delete('{transactionGroup}', ['uses' => 'Models\Transaction\DestroyController@destroy', 'as' => 'delete']);
// }
//);
//
//// special group for transaction journals
//// TODO VERIFY API DOCS
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers\Models\Transaction', 'prefix' => 'transaction-journals',
// 'as' => 'api.v1.journals.',],
// static function () {
//
// // Transaction API routes:
// Route::get('{tj}', ['uses' => 'ShowController@showByJournal', 'as' => 'showByJournal']);
// }
//);
//
//// TODO VERIFY API DOCS
//Route::group(
// ['middleware' => ['auth:api', 'bindings', IsAdmin::class], 'namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'users',
// 'as' => 'api.v1.users.',],
// static function () {
//
// // Users API routes:
// Route::get('', ['uses' => 'UserController@index', 'as' => 'index']);
// Route::post('', ['uses' => 'UserController@store', 'as' => 'store']);
// Route::get('{user}', ['uses' => 'UserController@show', 'as' => 'show']);
// Route::put('{user}', ['uses' => 'UserController@update', 'as' => 'update']);
// Route::delete('{user}', ['uses' => 'UserController@delete', 'as' => 'delete']);
// }
//);