Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Final patches in API
James Cole414c99489cbd
diff --git a/app/Api/V1/Controllers/Summary/BasicController.php b/app/Api/V1/Controllers/Summary/BasicController.phpindex adcfa04b32..d18af60f8c 100644--- a/app/Api/V1/Controllers/Summary/BasicController.php+++ b/app/Api/V1/Controllers/Summary/BasicController.php@@ -27,7 +27,7 @@ namespace FireflyIII\Api\V1\Controllers\Summary;use Carbon\Carbon;use Exception;use FireflyIII\Api\V1\Controllers\Controller;-use FireflyIII\Api\V1\Requests\DateRequest;+use FireflyIII\Api\V1\Requests\Data\DateRequest;use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Helpers\Report\NetWorthInterface;use FireflyIII\Models\Account;diff --git a/app/Api/V1/Controllers/todo-Webhook/CreateController.php b/app/Api/V1/Controllers/todo-Webhook/CreateController.phpdeleted file mode 100644index 8d6c30b9f5..0000000000--- a/app/Api/V1/Controllers/todo-Webhook/CreateController.php+++ /dev/null@@ -1,101 +0,0 @@-<?php--/*- * CreateController.php- * Copyright (c) 2021 [email protected]- *- * 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);-/*- * CreateController.php- * Copyright (c) 2020 [email protected]- *- * 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\Webhook;---use FireflyIII\Api\V1\Controllers\Controller;-use FireflyIII\Api\V1\Requests\Webhook\CreateRequest;-use FireflyIII\Repositories\Webhook\WebhookRepositoryInterface;-use FireflyIII\Transformers\WebhookTransformer;-use FireflyIII\User;-use Illuminate\Http\JsonResponse;-use League\Fractal\Resource\Item;--/**- * Class CreateController- */-class CreateController extends Controller-{- private WebhookRepositoryInterface $repository;-- /**- * @codeCoverageIgnore- */- public function __construct()- {- parent::__construct();- $this->middleware(- function ($request, $next) {- /** @var User $admin */- $admin = auth()->user();-- /** @var WebhookRepositoryInterface repository */- $this->repository = app(WebhookRepositoryInterface::class);- $this->repository->setUser($admin);-- return $next($request);- }- );- }-- /**- * @param CreateRequest $request- *- * @return JsonResponse- */- public function store(CreateRequest $request): JsonResponse- {- $data = $request->getData();- $webhook = $this->repository->store($data);- $manager = $this->getManager();- /** @var WebhookTransformer $transformer */- $transformer = app(WebhookTransformer::class);- $transformer->setParameters($this->parameters);-- $resource = new Item($webhook, $transformer, 'webhooks');-- return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);- }--}diff --git a/app/Api/V1/Controllers/todo/PreferenceController.php b/app/Api/V1/Controllers/todo/PreferenceController.phpdeleted file mode 100644index 4451d5465b..0000000000--- a/app/Api/V1/Controllers/todo/PreferenceController.php+++ /dev/null@@ -1,149 +0,0 @@-<?php-/*- * PreferenceController.php- * Copyright (c) 2021 [email protected]- *- * 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\PreferenceRequest;-use FireflyIII\Models\AccountType;-use FireflyIII\Models\Preference;-use FireflyIII\Repositories\Account\AccountRepositoryInterface;-use FireflyIII\Transformers\PreferenceTransformer;-use FireflyIII\User;-use Illuminate\Http\JsonResponse;-use Illuminate\Support\Collection;-use League\Fractal\Resource\Collection as FractalCollection;-use League\Fractal\Resource\Item;--/**- * Class PreferenceController- */-class PreferenceController extends Controller-{- /**- * LinkTypeController constructor.- *- * @codeCoverageIgnore- */- public function __construct()- {- parent::__construct();- $this->middleware(- static function ($request, $next) {- /** @var User $user */- $user = auth()->user();- $repository = app(AccountRepositoryInterface::class);- $repository->setUser($user);-- // an important fallback is that the frontPageAccount array gets refilled automatically- // when it turns up empty.- $frontPageAccounts = app('preferences')->getForUser($user, 'frontPageAccounts', [])->data;- if (0 === count($frontPageAccounts)) {- /** @var Collection $accounts */- $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);- $accountIds = $accounts->pluck('id')->toArray();- app('preferences')->setForUser($user, 'frontPageAccounts', $accountIds);- }-- return $next($request);- }- );- }-- /**- * List all of them.- *- * @return JsonResponse- * @codeCoverageIgnore- */- public function index(): JsonResponse- {- /** @var User $user */- $user = auth()->user();- $available = [- 'language', 'customFiscalYear', 'fiscalYearStart', 'currencyPreference',- 'transaction_journal_optional_fields', 'frontPageAccounts', 'viewRange',- 'listPageSize',- ];-- $preferences = new Collection;- foreach ($available as $name) {- $pref = app('preferences')->getForUser($user, $name);- if (null !== $pref) {- $preferences->push($pref);- }- }-- $manager = $this->getManager();-- /** @var PreferenceTransformer $transformer */- $transformer = app(PreferenceTransformer::class);- $transformer->setParameters($this->parameters);-- $resource = new FractalCollection($preferences, $transformer, 'preferences');-- return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);-- }---- /**- * Update a preference.- *- * @param PreferenceRequest $request- * @param Preference $preference- *- * @return JsonResponse- */- public function update(PreferenceRequest $request, Preference $preference): JsonResponse- {-- $data = $request->getAll();- $newValue = $data['data'];- switch ($preference->name) {- default:- break;- case 'transaction_journal_optional_fields':- case 'frontPageAccounts':- $newValue = explode(',', $data['data']);- break;- case 'listPageSize':- $newValue = (int) $data['data'];- break;- case 'customFiscalYear':- $newValue = 1 === (int) $data['data'];- break;- }- $result = app('preferences')->set($preference->name, $newValue);-- $manager = $this->getManager();- /** @var PreferenceTransformer $transformer */- $transformer = app(PreferenceTransformer::class);- $transformer->setParameters($this->parameters);-- $resource = new Item($result, $transformer, 'preferences');-- return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);-- }-}diff --git a/app/Api/V1/Requests/todo/DateRequest.php b/app/Api/V1/Requests/Data/DateRequest.phpsimilarity index 94%rename from app/Api/V1/Requests/todo/DateRequest.phprename to app/Api/V1/Requests/Data/DateRequest.phpindex d63c268089..c5ea73f04b 100644--- a/app/Api/V1/Requests/todo/DateRequest.php+++ b/app/Api/V1/Requests/Data/DateRequest.php@@ -1,8 +1,8 @@<?php-/**+/** DateRequest.php- * Copyright (c) 2019 [email protected]+ * Copyright (c) 2021 [email protected]** This file is part of Firefly III (https://github.com/firefly-iii).*@@ -22,7 +22,7 @@declare(strict_types=1);-namespace FireflyIII\Api\V1\Requests;+namespace FireflyIII\Api\V1\Requests\Data;use FireflyIII\Support\Request\ChecksLogin;diff --git a/app/Api/V1/Requests/todo/PreferenceRequest.php b/app/Api/V1/Requests/todo/PreferenceRequest.phpdeleted file mode 100644index 9676385a61..0000000000--- a/app/Api/V1/Requests/todo/PreferenceRequest.php+++ /dev/null@@ -1,65 +0,0 @@-<?php-/**- * PreferenceRequest.php- * Copyright (c) 2019 [email protected]- *- * 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\Requests;--use FireflyIII\Support\Request\ChecksLogin;-use FireflyIII\Support\Request\ConvertsDataTypes;-use Illuminate\Foundation\Http\FormRequest;--/**- * Class PreferenceRequest- *- * @codeCoverageIgnore- */-class PreferenceRequest extends FormRequest-{- use ConvertsDataTypes, ChecksLogin;---- /**- * Get all data from the request.- *- * @return array- */- public function getAll(): array- {- return [- 'data' => $this->get('data'),- ];- }-- /**- * The rules that the incoming request must be matched against.- *- * @return array- */- public function rules(): array- {- return [- 'data' => 'required|between:1,65000',- ];- }--}