mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Clean up budget and limit routes.
This commit is contained in:
@@ -23,7 +23,7 @@ namespace FireflyIII\Api\V1\Controllers\Models\Budget;
|
|||||||
|
|
||||||
|
|
||||||
use FireflyIII\Api\V1\Controllers\Controller;
|
use FireflyIII\Api\V1\Controllers\Controller;
|
||||||
use FireflyIII\Api\V1\Requests\BudgetStoreRequest;
|
use FireflyIII\Api\V1\Requests\Models\Budget\StoreRequest;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Transformers\BudgetTransformer;
|
use FireflyIII\Transformers\BudgetTransformer;
|
||||||
@@ -59,13 +59,13 @@ class StoreController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Store a budget.
|
* Store a budget.
|
||||||
*
|
*
|
||||||
* @param BudgetStoreRequest $request
|
* @param StoreRequest $request
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function store(BudgetStoreRequest $request): JsonResponse
|
public function store(StoreRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$budget = $this->repository->store($request->getAll());
|
$budget = $this->repository->store($request->getAll());
|
||||||
$manager = $this->getManager();
|
$manager = $this->getManager();
|
||||||
|
@@ -23,7 +23,7 @@ namespace FireflyIII\Api\V1\Controllers\Models\Budget;
|
|||||||
|
|
||||||
|
|
||||||
use FireflyIII\Api\V1\Controllers\Controller;
|
use FireflyIII\Api\V1\Controllers\Controller;
|
||||||
use FireflyIII\Api\V1\Requests\BudgetUpdateRequest;
|
use FireflyIII\Api\V1\Requests\Models\Budget\UpdateRequest;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Transformers\BudgetTransformer;
|
use FireflyIII\Transformers\BudgetTransformer;
|
||||||
@@ -58,12 +58,12 @@ class UpdateController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Update a budget.
|
* Update a budget.
|
||||||
*
|
*
|
||||||
* @param BudgetUpdateRequest $request
|
* @param UpdateRequest $request
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function update(BudgetUpdateRequest $request, Budget $budget): JsonResponse
|
public function update(UpdateRequest $request, Budget $budget): JsonResponse
|
||||||
{
|
{
|
||||||
$data = $request->getAll();
|
$data = $request->getAll();
|
||||||
$budget = $this->repository->update($budget, $data);
|
$budget = $this->repository->update($budget, $data);
|
||||||
|
@@ -0,0 +1,79 @@
|
|||||||
|
<?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\BudgetLimit;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Api\V1\Controllers\Controller;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DestroyController
|
||||||
|
*/
|
||||||
|
class DestroyController extends Controller
|
||||||
|
{
|
||||||
|
private BudgetLimitRepositoryInterface $blRepository;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BudgetLimitController constructor.
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->middleware(
|
||||||
|
function ($request, $next) {
|
||||||
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||||
|
$this->blRepository->setUser($user);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param Budget $budget
|
||||||
|
* @param BudgetLimit $budgetLimit
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function destroy(Budget $budget, BudgetLimit $budgetLimit): JsonResponse
|
||||||
|
{
|
||||||
|
if ($budget->id !== $budgetLimit->budget_id) {
|
||||||
|
throw new FireflyException('20028: The budget limit does not belong to the budget.');
|
||||||
|
}
|
||||||
|
$this->blRepository->destroyBudgetLimit($budgetLimit);
|
||||||
|
|
||||||
|
return response()->json([], 204);
|
||||||
|
}
|
||||||
|
}
|
122
app/Api/V1/Controllers/Models/BudgetLimit/ListController.php
Normal file
122
app/Api/V1/Controllers/Models/BudgetLimit/ListController.php
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
<?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\BudgetLimit;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Api\V1\Controllers\Controller;
|
||||||
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Http\Api\TransactionFilter;
|
||||||
|
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||||
|
use League\Fractal\Resource\Collection as FractalCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ListController
|
||||||
|
*/
|
||||||
|
class ListController extends Controller
|
||||||
|
{
|
||||||
|
use TransactionFilter;
|
||||||
|
|
||||||
|
private BudgetLimitRepositoryInterface $blRepository;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BudgetLimitController constructor.
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->middleware(
|
||||||
|
function ($request, $next) {
|
||||||
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||||
|
$this->blRepository->setUser($user);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show all transactions.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param Budget $budget
|
||||||
|
* @param BudgetLimit $budgetLimit
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function transactions(Request $request, Budget $budget, BudgetLimit $budgetLimit): JsonResponse
|
||||||
|
{
|
||||||
|
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
|
||||||
|
$type = $request->get('type') ?? 'default';
|
||||||
|
$this->parameters->set('type', $type);
|
||||||
|
|
||||||
|
$types = $this->mapTransactionTypes($this->parameters->get('type'));
|
||||||
|
$manager = $this->getManager();
|
||||||
|
|
||||||
|
/** @var User $admin */
|
||||||
|
$admin = auth()->user();
|
||||||
|
|
||||||
|
// use new group collector:
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
$collector
|
||||||
|
->setUser($admin)
|
||||||
|
// filter on budget.
|
||||||
|
->setBudget($budget)
|
||||||
|
// all info needed for the API:
|
||||||
|
->withAPIInformation()
|
||||||
|
// set page size:
|
||||||
|
->setLimit($pageSize)
|
||||||
|
// set page to retrieve
|
||||||
|
->setPage($this->parameters->get('page'))
|
||||||
|
// set types of transactions to return.
|
||||||
|
->setTypes($types);
|
||||||
|
|
||||||
|
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
|
||||||
|
$collector->setTypes($types);
|
||||||
|
$paginator = $collector->getPaginatedGroups();
|
||||||
|
$paginator->setPath(route('api.v1.budgets.limits.transactions', [$budget->id, $budgetLimit->id]) . $this->buildParams());
|
||||||
|
$transactions = $paginator->getCollection();
|
||||||
|
|
||||||
|
/** @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);
|
||||||
|
}
|
||||||
|
}
|
123
app/Api/V1/Controllers/Models/BudgetLimit/ShowController.php
Normal file
123
app/Api/V1/Controllers/Models/BudgetLimit/ShowController.php
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<?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\BudgetLimit;
|
||||||
|
|
||||||
|
use FireflyIII\Api\V1\Controllers\Controller;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use FireflyIII\Transformers\BudgetLimitTransformer;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
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 BudgetLimitRepositoryInterface $blRepository;
|
||||||
|
private BudgetRepositoryInterface $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BudgetLimitController constructor.
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->middleware(
|
||||||
|
function ($request, $next) {
|
||||||
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$this->repository = app(BudgetRepositoryInterface::class);
|
||||||
|
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||||
|
$this->repository->setUser($user);
|
||||||
|
$this->blRepository->setUser($user);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the budget limits for this budget..
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function index(Request $request, Budget $budget): JsonResponse
|
||||||
|
{
|
||||||
|
$manager = $this->getManager();
|
||||||
|
$manager->parseIncludes('budget');
|
||||||
|
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
|
||||||
|
$collection = $this->blRepository->getBudgetLimits($budget, $this->parameters->get('start'), $this->parameters->get('end'));
|
||||||
|
$count = $collection->count();
|
||||||
|
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||||
|
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
|
||||||
|
$paginator->setPath(route('api.v1.budgets.limits.index', [$budget->id]) . $this->buildParams());
|
||||||
|
|
||||||
|
/** @var BudgetLimitTransformer $transformer */
|
||||||
|
$transformer = app(BudgetLimitTransformer::class);
|
||||||
|
$transformer->setParameters($this->parameters);
|
||||||
|
|
||||||
|
$resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits');
|
||||||
|
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||||
|
|
||||||
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param Budget $budget
|
||||||
|
* @param BudgetLimit $budgetLimit
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function show(Request $request, Budget $budget, BudgetLimit $budgetLimit): JsonResponse
|
||||||
|
{
|
||||||
|
if ($budget->id !== $budgetLimit->budget_id) {
|
||||||
|
throw new FireflyException('20028: The budget limit does not belong to the budget.');
|
||||||
|
}
|
||||||
|
// continue!
|
||||||
|
$manager = $this->getManager();
|
||||||
|
|
||||||
|
/** @var BudgetLimitTransformer $transformer */
|
||||||
|
$transformer = app(BudgetLimitTransformer::class);
|
||||||
|
$transformer->setParameters($this->parameters);
|
||||||
|
|
||||||
|
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
|
||||||
|
|
||||||
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,92 @@
|
|||||||
|
<?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\BudgetLimit;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Api\V1\Controllers\Controller;
|
||||||
|
use FireflyIII\Api\V1\Requests\Models\BudgetLimit\StoreRequest;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||||
|
use FireflyIII\Transformers\BudgetLimitTransformer;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use League\Fractal\Resource\Item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class StoreController
|
||||||
|
*/
|
||||||
|
class StoreController extends Controller
|
||||||
|
{
|
||||||
|
private BudgetLimitRepositoryInterface $blRepository;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BudgetLimitController constructor.
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->middleware(
|
||||||
|
function ($request, $next) {
|
||||||
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||||
|
$this->blRepository->setUser($user);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param StoreRequest $request
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
* @throws FireflyException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function store(StoreRequest $request, Budget $budget): JsonResponse
|
||||||
|
{
|
||||||
|
$data = $request->getAll();
|
||||||
|
$data['start_date'] = $data['start'];
|
||||||
|
$data['end_date'] = $data['end'];
|
||||||
|
$data['budget_id'] = $budget->id;
|
||||||
|
|
||||||
|
$budgetLimit = $this->blRepository->store($data);
|
||||||
|
$manager = $this->getManager();
|
||||||
|
|
||||||
|
|
||||||
|
/** @var BudgetLimitTransformer $transformer */
|
||||||
|
$transformer = app(BudgetLimitTransformer::class);
|
||||||
|
$transformer->setParameters($this->parameters);
|
||||||
|
|
||||||
|
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
|
||||||
|
|
||||||
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,94 @@
|
|||||||
|
<?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\BudgetLimit;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Api\V1\Controllers\Controller;
|
||||||
|
use FireflyIII\Api\V1\Requests\Models\BudgetLimit\UpdateRequest;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use FireflyIII\Transformers\BudgetLimitTransformer;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use League\Fractal\Resource\Item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class UpdateController
|
||||||
|
*/
|
||||||
|
class UpdateController extends Controller
|
||||||
|
{
|
||||||
|
private BudgetLimitRepositoryInterface $blRepository;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BudgetLimitController constructor.
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
$this->middleware(
|
||||||
|
function ($request, $next) {
|
||||||
|
/** @var User $user */
|
||||||
|
$user = auth()->user();
|
||||||
|
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||||
|
$this->blRepository->setUser($user);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param UpdateRequest $request
|
||||||
|
* @param Budget $budget
|
||||||
|
* @param BudgetLimit $budgetLimit
|
||||||
|
*
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function update(UpdateRequest $request, Budget $budget, BudgetLimit $budgetLimit): JsonResponse
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($budget->id !== $budgetLimit->budget_id) {
|
||||||
|
throw new FireflyException('20028: The budget limit does not belong to the budget.');
|
||||||
|
}
|
||||||
|
$data = $request->getAll();
|
||||||
|
$data['budget_id'] = $budget->id;
|
||||||
|
$budgetLimit = $this->blRepository->update($budgetLimit, $data);
|
||||||
|
$manager = $this->getManager();
|
||||||
|
|
||||||
|
/** @var BudgetLimitTransformer $transformer */
|
||||||
|
$transformer = app(BudgetLimitTransformer::class);
|
||||||
|
$transformer->setParameters($this->parameters);
|
||||||
|
|
||||||
|
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
|
||||||
|
|
||||||
|
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -1,259 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* BudgetLimitController.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 FireflyIII\Api\V1\Requests\BudgetLimitStoreRequest;
|
|
||||||
use FireflyIII\Api\V1\Requests\BudgetLimitUpdateRequest;
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
|
||||||
use FireflyIII\Models\BudgetLimit;
|
|
||||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
||||||
use FireflyIII\Support\Http\Api\TransactionFilter;
|
|
||||||
use FireflyIII\Transformers\BudgetLimitTransformer;
|
|
||||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
|
||||||
use FireflyIII\User;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
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 BudgetLimitController.
|
|
||||||
*/
|
|
||||||
class BudgetLimitController extends Controller
|
|
||||||
{
|
|
||||||
use TransactionFilter;
|
|
||||||
|
|
||||||
private BudgetLimitRepositoryInterface $blRepository;
|
|
||||||
private BudgetRepositoryInterface $repository;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BudgetLimitController constructor.
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
$this->middleware(
|
|
||||||
function ($request, $next) {
|
|
||||||
/** @var User $user */
|
|
||||||
$user = auth()->user();
|
|
||||||
$this->repository = app(BudgetRepositoryInterface::class);
|
|
||||||
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
|
||||||
$this->repository->setUser($user);
|
|
||||||
$this->blRepository->setUser($user);
|
|
||||||
|
|
||||||
return $next($request);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*
|
|
||||||
* @param BudgetLimit $budgetLimit
|
|
||||||
*
|
|
||||||
* @return JsonResponse
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
public function delete(BudgetLimit $budgetLimit): JsonResponse
|
|
||||||
{
|
|
||||||
$this->blRepository->destroyBudgetLimit($budgetLimit);
|
|
||||||
|
|
||||||
return response()->json([], 204);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
*
|
|
||||||
* @return JsonResponse
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
public function index(Request $request): JsonResponse
|
|
||||||
{
|
|
||||||
$manager = $this->getManager();
|
|
||||||
$manager->parseIncludes('budget');
|
|
||||||
$budgetId = (int)($request->get('budget_id') ?? 0);
|
|
||||||
$budget = $this->repository->findNull($budgetId);
|
|
||||||
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
|
|
||||||
$this->parameters->set('budget_id', $budgetId);
|
|
||||||
|
|
||||||
$collection = new Collection;
|
|
||||||
if (null === $budget) {
|
|
||||||
$collection = $this->blRepository->getAllBudgetLimits($this->parameters->get('start'), $this->parameters->get('end'));
|
|
||||||
}
|
|
||||||
if (null !== $budget) {
|
|
||||||
$collection = $this->blRepository->getBudgetLimits($budget, $this->parameters->get('start'), $this->parameters->get('end'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$count = $collection->count();
|
|
||||||
$budgetLimits = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
|
||||||
$paginator = new LengthAwarePaginator($budgetLimits, $count, $pageSize, $this->parameters->get('page'));
|
|
||||||
$paginator->setPath(route('api.v1.budget_limits.index') . $this->buildParams());
|
|
||||||
|
|
||||||
/** @var BudgetLimitTransformer $transformer */
|
|
||||||
$transformer = app(BudgetLimitTransformer::class);
|
|
||||||
$transformer->setParameters($this->parameters);
|
|
||||||
|
|
||||||
$resource = new FractalCollection($budgetLimits, $transformer, 'budget_limits');
|
|
||||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
|
||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*
|
|
||||||
* @param BudgetLimit $budgetLimit
|
|
||||||
*
|
|
||||||
* @return JsonResponse
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
public function show(BudgetLimit $budgetLimit): JsonResponse
|
|
||||||
{
|
|
||||||
$manager = $this->getManager();
|
|
||||||
|
|
||||||
/** @var BudgetLimitTransformer $transformer */
|
|
||||||
$transformer = app(BudgetLimitTransformer::class);
|
|
||||||
$transformer->setParameters($this->parameters);
|
|
||||||
|
|
||||||
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
|
|
||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*
|
|
||||||
* @param BudgetLimitStoreRequest $request
|
|
||||||
*
|
|
||||||
* @return JsonResponse
|
|
||||||
* @throws FireflyException
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function store(BudgetLimitStoreRequest $request): JsonResponse
|
|
||||||
{
|
|
||||||
$data = $request->getAll();
|
|
||||||
$data['start_date'] = $data['start'];
|
|
||||||
$data['end_date'] = $data['end'];
|
|
||||||
|
|
||||||
$budgetLimit = $this->blRepository->store($data);
|
|
||||||
$manager = $this->getManager();
|
|
||||||
|
|
||||||
|
|
||||||
/** @var BudgetLimitTransformer $transformer */
|
|
||||||
$transformer = app(BudgetLimitTransformer::class);
|
|
||||||
$transformer->setParameters($this->parameters);
|
|
||||||
|
|
||||||
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
|
|
||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show all transactions.
|
|
||||||
*
|
|
||||||
* @param Request $request
|
|
||||||
* @param BudgetLimit $budgetLimit
|
|
||||||
*
|
|
||||||
* @return JsonResponse
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
public function transactions(Request $request, BudgetLimit $budgetLimit): JsonResponse
|
|
||||||
{
|
|
||||||
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
|
|
||||||
$type = $request->get('type') ?? 'default';
|
|
||||||
$this->parameters->set('type', $type);
|
|
||||||
|
|
||||||
$types = $this->mapTransactionTypes($this->parameters->get('type'));
|
|
||||||
$manager = $this->getManager();
|
|
||||||
|
|
||||||
/** @var User $admin */
|
|
||||||
$admin = auth()->user();
|
|
||||||
|
|
||||||
// use new group collector:
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
|
||||||
$collector = app(GroupCollectorInterface::class);
|
|
||||||
$collector
|
|
||||||
->setUser($admin)
|
|
||||||
// filter on budget.
|
|
||||||
->setBudget($budgetLimit->budget)
|
|
||||||
// all info needed for the API:
|
|
||||||
->withAPIInformation()
|
|
||||||
// set page size:
|
|
||||||
->setLimit($pageSize)
|
|
||||||
// set page to retrieve
|
|
||||||
->setPage($this->parameters->get('page'))
|
|
||||||
// set types of transactions to return.
|
|
||||||
->setTypes($types);
|
|
||||||
|
|
||||||
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
|
|
||||||
$collector->setTypes($types);
|
|
||||||
$paginator = $collector->getPaginatedGroups();
|
|
||||||
$paginator->setPath(route('api.v1.budget_limits.transactions', [$budgetLimit->id]) . $this->buildParams());
|
|
||||||
$transactions = $paginator->getCollection();
|
|
||||||
|
|
||||||
/** @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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
|
||||||
*
|
|
||||||
* @param BudgetLimitUpdateRequest $request
|
|
||||||
* @param BudgetLimit $budgetLimit
|
|
||||||
*
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function update(BudgetLimitUpdateRequest $request, BudgetLimit $budgetLimit): JsonResponse
|
|
||||||
{
|
|
||||||
$data = $request->getAll();
|
|
||||||
$budgetLimit = $this->blRepository->update($budgetLimit, $data);
|
|
||||||
$manager = $this->getManager();
|
|
||||||
|
|
||||||
/** @var BudgetLimitTransformer $transformer */
|
|
||||||
$transformer = app(BudgetLimitTransformer::class);
|
|
||||||
$transformer->setParameters($this->parameters);
|
|
||||||
|
|
||||||
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
|
|
||||||
|
|
||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace FireflyIII\Api\V1\Requests;
|
namespace FireflyIII\Api\V1\Requests\Models\Budget;
|
||||||
|
|
||||||
use FireflyIII\Rules\IsBoolean;
|
use FireflyIII\Rules\IsBoolean;
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
@@ -31,11 +31,11 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BudgetStoreRequest
|
* Class StoreRequest
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class BudgetStoreRequest extends FormRequest
|
class StoreRequest extends FormRequest
|
||||||
{
|
{
|
||||||
use ConvertsDataTypes, ValidatesAutoBudgetRequest, ChecksLogin;
|
use ConvertsDataTypes, ValidatesAutoBudgetRequest, ChecksLogin;
|
||||||
|
|
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace FireflyIII\Api\V1\Requests;
|
namespace FireflyIII\Api\V1\Requests\Models\Budget;
|
||||||
|
|
||||||
use FireflyIII\Rules\IsBoolean;
|
use FireflyIII\Rules\IsBoolean;
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
@@ -31,11 +31,11 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BudgetUpdateRequest
|
* Class UpdateRequest
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class BudgetUpdateRequest extends FormRequest
|
class UpdateRequest extends FormRequest
|
||||||
{
|
{
|
||||||
use ConvertsDataTypes, ValidatesAutoBudgetRequest, ChecksLogin;
|
use ConvertsDataTypes, ValidatesAutoBudgetRequest, ChecksLogin;
|
||||||
|
|
@@ -21,18 +21,18 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace FireflyIII\Api\V1\Requests;
|
namespace FireflyIII\Api\V1\Requests\Models\BudgetLimit;
|
||||||
|
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BudgetLimitStoreRequest
|
* Class StoreRequest
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class BudgetLimitStoreRequest extends FormRequest
|
class StoreRequest extends FormRequest
|
||||||
{
|
{
|
||||||
use ConvertsDataTypes, ChecksLogin;
|
use ConvertsDataTypes, ChecksLogin;
|
||||||
|
|
||||||
@@ -44,7 +44,6 @@ class BudgetLimitStoreRequest extends FormRequest
|
|||||||
public function getAll(): array
|
public function getAll(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'budget_id' => $this->integer('budget_id'),
|
|
||||||
'start' => $this->date('start'),
|
'start' => $this->date('start'),
|
||||||
'end' => $this->date('end'),
|
'end' => $this->date('end'),
|
||||||
'amount' => $this->string('amount'),
|
'amount' => $this->string('amount'),
|
||||||
@@ -61,7 +60,6 @@ class BudgetLimitStoreRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'budget_id' => 'required|exists:budgets,id|belongsToUser:budgets,id',
|
|
||||||
'start' => 'required|before:end|date',
|
'start' => 'required|before:end|date',
|
||||||
'end' => 'required|after:start|date',
|
'end' => 'required|after:start|date',
|
||||||
'amount' => 'required|gt:0',
|
'amount' => 'required|gt:0',
|
@@ -21,18 +21,18 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace FireflyIII\Api\V1\Requests;
|
namespace FireflyIII\Api\V1\Requests\Models\BudgetLimit;
|
||||||
|
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BudgetLimitUpdateRequest
|
* Class UpdateRequest
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
class BudgetLimitUpdateRequest extends FormRequest
|
class UpdateRequest extends FormRequest
|
||||||
{
|
{
|
||||||
use ConvertsDataTypes, ChecksLogin;
|
use ConvertsDataTypes, ChecksLogin;
|
||||||
|
|
||||||
@@ -43,20 +43,13 @@ class BudgetLimitUpdateRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function getAll(): array
|
public function getAll(): array
|
||||||
{
|
{
|
||||||
$data = [
|
return [
|
||||||
'budget_id' => $this->integer('budget_id'),
|
|
||||||
'start' => $this->date('start'),
|
'start' => $this->date('start'),
|
||||||
'end' => $this->date('end'),
|
'end' => $this->date('end'),
|
||||||
'amount' => $this->string('amount'),
|
'amount' => $this->string('amount'),
|
||||||
'currency_id' => $this->integer('currency_id'),
|
'currency_id' => $this->integer('currency_id'),
|
||||||
'currency_code' => $this->string('currency_code'),
|
'currency_code' => $this->string('currency_code'),
|
||||||
];
|
];
|
||||||
// if request has a budget already, drop the rule.
|
|
||||||
$budget = $this->route()->parameter('budget');
|
|
||||||
if (null !== $budget) {
|
|
||||||
$data['budget_id'] = $budget->id;
|
|
||||||
}
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,21 +59,13 @@ class BudgetLimitUpdateRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$rules = [
|
return [
|
||||||
'budget_id' => 'required|exists:budgets,id|belongsToUser:budgets,id',
|
'start' => 'before:end|date',
|
||||||
'start' => 'required|before:end|date',
|
'end' => 'after:start|date',
|
||||||
'end' => 'required|after:start|date',
|
'amount' => 'gt:0',
|
||||||
'amount' => 'required|gt:0',
|
|
||||||
'currency_id' => 'numeric|exists:transaction_currencies,id',
|
'currency_id' => 'numeric|exists:transaction_currencies,id',
|
||||||
'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
|
'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
|
||||||
];
|
];
|
||||||
// if request has a budget already, drop the rule.
|
|
||||||
$budget = $this->route()->parameter('budget');
|
|
||||||
if (null !== $budget) {
|
|
||||||
unset($rules['budget_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -84,20 +84,19 @@ class BudgetLimitTransformer extends AbstractTransformer
|
|||||||
$amount = number_format((float)$amount, $currencyDecimalPlaces, '.', '');
|
$amount = number_format((float)$amount, $currencyDecimalPlaces, '.', '');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => (int)$budgetLimit->id,
|
'id' => (string) $budgetLimit->id,
|
||||||
'created_at' => $budgetLimit->created_at->toAtomString(),
|
'created_at' => $budgetLimit->created_at->toAtomString(),
|
||||||
'updated_at' => $budgetLimit->updated_at->toAtomString(),
|
'updated_at' => $budgetLimit->updated_at->toAtomString(),
|
||||||
'start' => $budgetLimit->start_date->format('Y-m-d'),
|
'start' => $budgetLimit->start_date->format('Y-m-d'),
|
||||||
'end' => $budgetLimit->end_date->format('Y-m-d'),
|
'end' => $budgetLimit->end_date->format('Y-m-d'),
|
||||||
'budget_id' => (int)$budgetLimit->budget_id,
|
'budget_id' => (string)$budgetLimit->budget_id,
|
||||||
'currency_id' => $currencyId,
|
'currency_id' => (string) $currencyId,
|
||||||
'currency_code' => $currencyCode,
|
'currency_code' => $currencyCode,
|
||||||
'currency_name' => $currencyName,
|
'currency_name' => $currencyName,
|
||||||
'currency_decimal_places' => $currencyName,
|
'currency_decimal_places' => $currencyDecimalPlaces,
|
||||||
'currency_symbol' => $currencySymbol,
|
'currency_symbol' => $currencySymbol,
|
||||||
'amount' => $amount,
|
'amount' => $amount,
|
||||||
'period' => $budgetLimit->period,
|
'period' => $budgetLimit->period,
|
||||||
'auto_budget' => $budgetLimit->auto_budget,
|
|
||||||
'spent' => $expenses[$currencyId]['sum'] ?? '0',
|
'spent' => $expenses[$currencyId]['sum'] ?? '0',
|
||||||
'links' => [
|
'links' => [
|
||||||
[
|
[
|
||||||
|
@@ -89,14 +89,14 @@ class BudgetTransformer extends AbstractTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => (int)$budget->id,
|
'id' => (string)$budget->id,
|
||||||
'created_at' => $budget->created_at->toAtomString(),
|
'created_at' => $budget->created_at->toAtomString(),
|
||||||
'updated_at' => $budget->updated_at->toAtomString(),
|
'updated_at' => $budget->updated_at->toAtomString(),
|
||||||
'active' => $budget->active,
|
'active' => $budget->active,
|
||||||
'name' => $budget->name,
|
'name' => $budget->name,
|
||||||
'auto_budget_type' => $abType,
|
'auto_budget_type' => $abType,
|
||||||
'auto_budget_period' => $abPeriod,
|
'auto_budget_period' => $abPeriod,
|
||||||
'auto_budget_currency_id' => $abCurrencyId,
|
'auto_budget_currency_id' => (string)$abCurrencyId,
|
||||||
'auto_budget_currency_code' => $abCurrencyCode,
|
'auto_budget_currency_code' => $abCurrencyCode,
|
||||||
'auto_budget_amount' => $abAmount,
|
'auto_budget_amount' => $abAmount,
|
||||||
'spent' => $spent,
|
'spent' => $spent,
|
||||||
|
@@ -213,6 +213,33 @@ Route::group(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Budget and Budget Limit API routes:
|
||||||
|
Route::group(
|
||||||
|
['namespace' => 'FireflyIII\Api\V1\Controllers\Models', 'prefix' => 'budgets',
|
||||||
|
'as' => 'api.v1.budgets.',],
|
||||||
|
static function () {
|
||||||
|
Route::get('', ['uses' => 'Budget\ShowController@index', 'as' => 'index']);
|
||||||
|
Route::post('', ['uses' => 'Budget\StoreController@store', 'as' => 'store']);
|
||||||
|
Route::get('{budget}', ['uses' => 'Budget\ShowController@show', 'as' => 'show']);
|
||||||
|
Route::put('{budget}', ['uses' => 'Budget\UpdateController@update', 'as' => 'update']);
|
||||||
|
Route::delete('{budget}', ['uses' => 'Budget\DestroyController@destroy', 'as' => 'delete']);
|
||||||
|
|
||||||
|
Route::get('{budget}/transactions', ['uses' => 'Budget\ListController@transactions', 'as' => 'transactions']);
|
||||||
|
Route::get('{budget}/attachments', ['uses' => 'Budget\ListController@attachments', 'as' => 'attachments']);
|
||||||
|
|
||||||
|
// limits:
|
||||||
|
Route::get('{budget}/limits', ['uses' => 'BudgetLimit\ShowController@index', 'as' => 'limits.index']);
|
||||||
|
Route::post('{budget}/limits', ['uses' => 'BudgetLimit\StoreController@store', 'as' => 'limits.store']);
|
||||||
|
Route::get('{budget}/limits/{budgetLimit}', ['uses' => 'BudgetLimit\ShowController@show', 'as' => 'limits.show']);
|
||||||
|
Route::put('{budget}/limits/{budgetLimit}', ['uses' => 'BudgetLimit\UpdateController@update', 'as' => 'limits.update']);
|
||||||
|
Route::delete('{budget}/limits/{budgetLimit}', ['uses' => 'BudgetLimit\DestroyController@destroy', 'as' => 'limits.delete']);
|
||||||
|
Route::get('{budget}/limits/{budgetLimit}/transactions', ['uses' => 'BudgetLimit\ListController@transactions', 'as' => 'limits.transactions']);
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -263,17 +290,17 @@ Route::group(
|
|||||||
|
|
||||||
// ABOUT FIREFLY III
|
// ABOUT FIREFLY III
|
||||||
// TODO VERIFY API DOCS
|
// TODO VERIFY API DOCS
|
||||||
Route::group(
|
//Route::group(
|
||||||
[
|
// [
|
||||||
'namespace' => 'FireflyIII\Api\V1\Controllers\System', 'prefix' => 'about',
|
// 'namespace' => 'FireflyIII\Api\V1\Controllers\System', 'prefix' => 'about',
|
||||||
'as' => 'api.v1.about.'],
|
// 'as' => 'api.v1.about.'],
|
||||||
static function () {
|
// static function () {
|
||||||
|
//
|
||||||
// Accounts API routes:
|
// // Accounts API routes:
|
||||||
Route::get('', ['uses' => 'AboutController@about', 'as' => 'index']);
|
// Route::get('', ['uses' => 'AboutController@about', 'as' => 'index']);
|
||||||
Route::get('user', ['uses' => 'AboutController@user', 'as' => 'user']);
|
// Route::get('user', ['uses' => 'AboutController@user', 'as' => 'user']);
|
||||||
}
|
// }
|
||||||
);
|
//);
|
||||||
|
|
||||||
|
|
||||||
// DYNAMIC CONFIGURATION (CHANGEABLE)
|
// DYNAMIC CONFIGURATION (CHANGEABLE)
|
||||||
@@ -346,42 +373,7 @@ Route::group(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO VERIFY API DOCS
|
|
||||||
Route::group(
|
|
||||||
['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'budgets/limits',
|
|
||||||
'as' => 'api.v1.budget_limits.',],
|
|
||||||
static function () {
|
|
||||||
|
|
||||||
// Budget Limit API routes:
|
|
||||||
Route::get('', ['uses' => 'BudgetLimitController@index', 'as' => 'index']);
|
|
||||||
Route::post('', ['uses' => 'BudgetLimitController@store', 'as' => 'store']);
|
|
||||||
Route::get('{budgetLimit}', ['uses' => 'BudgetLimitController@show', 'as' => 'show']);
|
|
||||||
Route::put('{budgetLimit}', ['uses' => 'BudgetLimitController@update', 'as' => 'update']);
|
|
||||||
Route::delete('{budgetLimit}', ['uses' => 'BudgetLimitController@delete', 'as' => 'delete']);
|
|
||||||
|
|
||||||
Route::get('{budgetLimit}/transactions', ['uses' => 'BudgetLimitController@transactions', 'as' => 'transactions']);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO VERIFY API DOCS
|
|
||||||
Route::group(
|
|
||||||
['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'budgets',
|
|
||||||
'as' => 'api.v1.budgets.',],
|
|
||||||
static function () {
|
|
||||||
|
|
||||||
// Budget API routes:
|
|
||||||
Route::get('', ['uses' => 'Models\Budget\ShowController@index', 'as' => 'index']);
|
|
||||||
Route::post('', ['uses' => 'Models\Budget\StoreController@store', 'as' => 'store']);
|
|
||||||
Route::get('{budget}', ['uses' => 'Models\Budget\ShowController@show', 'as' => 'show']);
|
|
||||||
Route::put('{budget}', ['uses' => 'Models\Budget\UpdateController@update', 'as' => 'update']);
|
|
||||||
Route::delete('{budget}', ['uses' => 'Models\Budget\DestroyController@destroy', 'as' => 'delete']);
|
|
||||||
Route::post('{budget}/limits', ['uses' => 'BudgetLimitController@store', 'as' => 'store_budget_limit']);
|
|
||||||
|
|
||||||
Route::get('{budget}/transactions', ['uses' => 'Models\Budget\ListController@transactions', 'as' => 'transactions']);
|
|
||||||
Route::get('{budget}/attachments', ['uses' => 'Models\Budget\ListController@attachments', 'as' => 'attachments']);
|
|
||||||
Route::get('{budget}/limits', ['uses' => 'Models\Budget\ListController@budgetLimits', 'as' => 'budget_limits']);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO VERIFY API DOCS
|
// TODO VERIFY API DOCS
|
||||||
Route::group(
|
Route::group(
|
||||||
|
Reference in New Issue
Block a user