Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
New (empty) API controllers.
James Colec8de1d3372b9
diff --git a/app/Api/V1/Controllers/PiggyBankController.php b/app/Api/V1/Controllers/PiggyBankController.phpnew file mode 100644index 0000000000..01eb9608dc--- /dev/null+++ b/app/Api/V1/Controllers/PiggyBankController.php@@ -0,0 +1,145 @@+<?php+/**+ * PiggyBankController.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III 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 General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Api\V1\Controllers;++use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;+use FireflyIII\Transformers\BudgetTransformer;+use FireflyIII\Transformers\PiggyBankTransformer;+use FireflyIII\User;+use Illuminate\Http\JsonResponse;+use Illuminate\Http\Request;+use Illuminate\Pagination\LengthAwarePaginator;+use League\Fractal\Manager;+use League\Fractal\Pagination\IlluminatePaginatorAdapter;+use League\Fractal\Resource\Collection as FractalCollection;+use League\Fractal\Serializer\JsonApiSerializer;++class PiggyBankController extends Controller+{++ /** @var PiggyBankRepositoryInterface */+ private $repository;++ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ /** @var User $user */+ $user = auth()->user();++ $this->repository = app(PiggyBankRepositoryInterface::class);++ return $next($request);+ }+ );+ }++ /**+ * Delete the resource.+ *+ * @param string $object+ *+ * @return JsonResponse+ */+ public function delete(string $object): JsonResponse+ {+ // todo delete object.++ return response()->json([], 204);+ }++ /**+ * List all of them.+ *+ * @param Request $request+ *+ * @return JsonResponse]+ */+ public function index(Request $request): JsonResponse+ {+ // create some objects:+ $manager = new Manager;+ $baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';++ // 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->repository->getPiggyBanks();+ $count = $collection->count();+ $piggyBanks= $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);++ // make paginator:+ $paginator = new LengthAwarePaginator($piggyBanks, $count, $pageSize, $this->parameters->get('page'));+ $paginator->setPath(route('api.v1.piggy_banks.index') . $this->buildParams());++ // present to user.+ $manager->setSerializer(new JsonApiSerializer($baseUrl));+ $resource = new FractalCollection($piggyBanks, new PiggyBankTransformer($this->parameters), 'piggy_banks');+ $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));++ return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');++ }++ /**+ * List single resource.+ *+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function show(Request $request, string $object): JsonResponse+ {+ // todo implement me.++ }++ /**+ * Store new object.+ *+ * @param Request $request+ *+ * @return JsonResponse+ */+ public function store(Request $request): JsonResponse+ {+ // todo replace code and replace request object.++ }++ /**+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function update(Request $request, string $object): JsonResponse+ {+ // todo replace code and replace request object.++ }+}\ No newline at end of filediff --git a/app/Api/V1/Controllers/PreferenceController.php b/app/Api/V1/Controllers/PreferenceController.phpnew file mode 100644index 0000000000..01b4ae40e4--- /dev/null+++ b/app/Api/V1/Controllers/PreferenceController.php@@ -0,0 +1,112 @@+<?php+/**+ * PreferencesController.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III 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 General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Api\V1\Controllers;++use FireflyIII\User;+use Illuminate\Http\JsonResponse;+use Illuminate\Http\Request;+++class PreferenceController extends Controller+{+ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ /** @var User $user */+ $user = auth()->user();++ // todo add local repositories.+ return $next($request);+ }+ );+ }++ /**+ * Delete the resource.+ *+ * @param string $object+ *+ * @return JsonResponse+ */+ public function delete(string $object): JsonResponse+ {+ // todo delete object.++ return response()->json([], 204);+ }++ /**+ * List all of them.+ *+ * @param Request $request+ *+ * @return JsonResponse]+ */+ public function index(Request $request): JsonResponse+ {+ // todo implement.++ }++ /**+ * List single resource.+ *+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function show(Request $request, string $object): JsonResponse+ {+ // todo implement me.++ }++ /**+ * Store new object.+ *+ * @param Request $request+ *+ * @return JsonResponse+ */+ public function store(Request $request): JsonResponse+ {+ // todo replace code and replace request object.++ }++ /**+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function update(Request $request, string $object): JsonResponse+ {+ // todo replace code and replace request object.++ }+}\ No newline at end of filediff --git a/app/Api/V1/Controllers/RecurrenceController.php b/app/Api/V1/Controllers/RecurrenceController.phpnew file mode 100644index 0000000000..519ffd65f8--- /dev/null+++ b/app/Api/V1/Controllers/RecurrenceController.php@@ -0,0 +1,112 @@+<?php+/**+ * RecurrenceController.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III 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 General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Api\V1\Controllers;++use FireflyIII\User;+use Illuminate\Http\JsonResponse;+use Illuminate\Http\Request;+++class RecurrenceController+{+ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ /** @var User $user */+ $user = auth()->user();++ // todo add local repositories.+ return $next($request);+ }+ );+ }++ /**+ * Delete the resource.+ *+ * @param string $object+ *+ * @return JsonResponse+ */+ public function delete(string $object): JsonResponse+ {+ // todo delete object.++ return response()->json([], 204);+ }++ /**+ * List all of them.+ *+ * @param Request $request+ *+ * @return JsonResponse]+ */+ public function index(Request $request): JsonResponse+ {+ // todo implement.++ }++ /**+ * List single resource.+ *+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function show(Request $request, string $object): JsonResponse+ {+ // todo implement me.++ }++ /**+ * Store new object.+ *+ * @param Request $request+ *+ * @return JsonResponse+ */+ public function store(Request $request): JsonResponse+ {+ // todo replace code and replace request object.++ }++ /**+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function update(Request $request, string $object): JsonResponse+ {+ // todo replace code and replace request object.++ }+}\ No newline at end of filediff --git a/app/Api/V1/Controllers/RuleController.php b/app/Api/V1/Controllers/RuleController.phpnew file mode 100644index 0000000000..e3d6fedb78--- /dev/null+++ b/app/Api/V1/Controllers/RuleController.php@@ -0,0 +1,112 @@+<?php+/**+ * RuleController.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III 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 General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Api\V1\Controllers;++use FireflyIII\User;+use Illuminate\Http\JsonResponse;+use Illuminate\Http\Request;+++class RuleController extends Controller+{+ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ /** @var User $user */+ $user = auth()->user();++ // todo add local repositories.+ return $next($request);+ }+ );+ }++ /**+ * Delete the resource.+ *+ * @param string $object+ *+ * @return JsonResponse+ */+ public function delete(string $object): JsonResponse+ {+ // todo delete object.++ return response()->json([], 204);+ }++ /**+ * List all of them.+ *+ * @param Request $request+ *+ * @return JsonResponse]+ */+ public function index(Request $request): JsonResponse+ {+ // todo implement.++ }++ /**+ * List single resource.+ *+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function show(Request $request, string $object): JsonResponse+ {+ // todo implement me.++ }++ /**+ * Store new object.+ *+ * @param Request $request+ *+ * @return JsonResponse+ */+ public function store(Request $request): JsonResponse+ {+ // todo replace code and replace request object.++ }++ /**+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function update(Request $request, string $object): JsonResponse+ {+ // todo replace code and replace request object.++ }+}\ No newline at end of filediff --git a/app/Api/V1/Controllers/RuleGroupController.php b/app/Api/V1/Controllers/RuleGroupController.phpnew file mode 100644index 0000000000..3c1cec83e4--- /dev/null+++ b/app/Api/V1/Controllers/RuleGroupController.php@@ -0,0 +1,112 @@+<?php+/**+ * RuleGroupController.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III 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 General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Api\V1\Controllers;++use FireflyIII\User;+use Illuminate\Http\JsonResponse;+use Illuminate\Http\Request;+++class RuleGroupController extends Controller+{+ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ /** @var User $user */+ $user = auth()->user();++ // todo add local repositories.+ return $next($request);+ }+ );+ }++ /**+ * Delete the resource.+ *+ * @param string $object+ *+ * @return JsonResponse+ */+ public function delete(string $object): JsonResponse+ {+ // todo delete object.++ return response()->json([], 204);+ }++ /**+ * List all of them.+ *+ * @param Request $request+ *+ * @return JsonResponse]+ */+ public function index(Request $request): JsonResponse+ {+ // todo implement.++ }++ /**+ * List single resource.+ *+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function show(Request $request, string $object): JsonResponse+ {+ // todo implement me.++ }++ /**+ * Store new object.+ *+ * @param Request $request+ *+ * @return JsonResponse+ */+ public function store(Request $request): JsonResponse+ {+ // todo replace code and replace request object.++ }++ /**+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function update(Request $request, string $object): JsonResponse+ {+ // todo replace code and replace request object.++ }+}\ No newline at end of filediff --git a/app/Api/V1/Controllers/TagController.php b/app/Api/V1/Controllers/TagController.phpnew file mode 100644index 0000000000..8aa1b6acb0--- /dev/null+++ b/app/Api/V1/Controllers/TagController.php@@ -0,0 +1,112 @@+<?php+/**+ * TagController.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III 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 General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Api\V1\Controllers;++use FireflyIII\User;+use Illuminate\Http\JsonResponse;+use Illuminate\Http\Request;+++class TagController extends Controller+{+ public function __construct()+ {+ parent::__construct();+ $this->middleware(+ function ($request, $next) {+ /** @var User $user */+ $user = auth()->user();++ // todo add local repositories.+ return $next($request);+ }+ );+ }++ /**+ * Delete the resource.+ *+ * @param string $object+ *+ * @return JsonResponse+ */+ public function delete(string $object): JsonResponse+ {+ // todo delete object.++ return response()->json([], 204);+ }++ /**+ * List all of them.+ *+ * @param Request $request+ *+ * @return JsonResponse]+ */+ public function index(Request $request): JsonResponse+ {+ // todo implement.++ }++ /**+ * List single resource.+ *+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function show(Request $request, string $object): JsonResponse+ {+ // todo implement me.++ }++ /**+ * Store new object.+ *+ * @param Request $request+ *+ * @return JsonResponse+ */+ public function store(Request $request): JsonResponse+ {+ // todo replace code and replace request object.++ }++ /**+ * @param Request $request+ * @param string $object+ *+ * @return JsonResponse+ */+ public function update(Request $request, string $object): JsonResponse+ {+ // todo replace code and replace request object.++ }+}\ No newline at end of filediff --git a/app/Api/V1/Requests/LinkTypeRequest.php b/app/Api/V1/Requests/LinkTypeRequest.phpnew file mode 100644index 0000000000..c44dbcb145--- /dev/null+++ b/app/Api/V1/Requests/LinkTypeRequest.php@@ -0,0 +1,86 @@+<?php+/**+ * LinkTypeRequest.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III 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 General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Api\V1\Requests;++use FireflyIII\Models\LinkType;+use Illuminate\Validation\Rule;++/**+ *+ * Class LinkTypeRequest+ */+class LinkTypeRequest extends Request+{+ /**+ * @return bool+ */+ public function authorize(): bool+ {+ // Only allow authenticated users+ return auth()->check();+ }++ /**+ * @return array+ */+ public function getAll(): array+ {+ return [+ 'name' => $this->string('name'),+ 'outward' => $this->string('outward'),+ 'inward' => $this->string('inward'),+ ];+++ }++ /**+ * @return array+ */+ public function rules(): array+ {+ $rules = [+ 'name' => 'required|unique:link_types,name|min:1',+ 'outward' => 'required|unique:link_types,outward|min:1|different:inward',+ 'inward' => 'required|unique:link_types,inward|min:1|different:outward',+ ];+ // Rule::unique('users')->ignore($user->id),+++ switch ($this->method()) {+ default:+ break;+ case 'PUT':+ case 'PATCH':+ /** @var LinkType $linkType */+ $linkType = $this->route()->parameter('linkType');+ $rules['name'] = ['required', Rule::unique('link_types', 'name')->ignore($linkType->id), 'min:1'];+ $rules['outward'] = ['required', 'different:inward', Rule::unique('link_types', 'outward')->ignore($linkType->id), 'min:1'];+ $rules['inward'] = ['required', 'different:outward', Rule::unique('link_types', 'inward')->ignore($linkType->id), 'min:1'];+ break;+ }++ return $rules;+ }+}\ No newline at end of file