Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Create new request for search.
James Cole54676715c02e
diff --git a/app/Api/V1/Controllers/Search/TransactionController.php b/app/Api/V1/Controllers/Search/TransactionController.phpindex d95daf8c37..ac04fb2bb5 100644--- a/app/Api/V1/Controllers/Search/TransactionController.php+++ b/app/Api/V1/Controllers/Search/TransactionController.php@@ -25,6 +25,7 @@ declare(strict_types=1);namespace FireflyIII\Api\V1\Controllers\Search;use FireflyIII\Api\V1\Controllers\Controller;+use FireflyIII\Api\V1\Requests\Search\TransactionSearchRequest;use FireflyIII\Support\JsonApi\Enrichments\TransactionGroupEnrichment;use FireflyIII\Support\Search\SearchInterface;use FireflyIII\Transformers\TransactionGroupTransformer;@@ -42,12 +43,12 @@ class TransactionController extends Controller* This endpoint is documented at:* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/search/searchTransactions*/- public function search(Request $request, SearchInterface $searcher): JsonResponse+ public function search(TransactionSearchRequest $request, SearchInterface $searcher): JsonResponse{$manager = $this->getManager();- $fullQuery = (string) $request->get('query');- $page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');- $pageSize = $this->parameters->get('limit');+ $fullQuery = (string) $request->attributes->get('query');+ $page = $request->attributes->get('page');+ $pageSize = $request->attributes->get('limit');$searcher->parseQuery($fullQuery);$searcher->setPage($page);$searcher->setLimit($pageSize);diff --git a/app/Api/V1/Requests/Search/SearchQueryRequest.php b/app/Api/V1/Requests/Search/SearchQueryRequest.phpnew file mode 100644index 0000000000..73640dc8ee--- /dev/null+++ b/app/Api/V1/Requests/Search/SearchQueryRequest.php@@ -0,0 +1,50 @@+<?php+/*+ * SearchQueryRequest.php+ * Copyright (c) 2026 [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\Requests\Search;++use FireflyIII\Api\V1\Requests\ApiRequest;+use Illuminate\Contracts\Validation\Validator;++class SearchQueryRequest extends ApiRequest+{+ public function rules(): array+ {+ return [+ 'query' => sprintf('min:0|max:500|%s', $this->required),+ ];+ }+++ public function withValidator(Validator $validator): void+ {+ $validator->after(+ function (Validator $validator): void {+ if ($validator->failed()) {+ return;+ }+ $query = $this->convertString('query');+ $this->attributes->set('query', $query);+ }+ );+ }++}diff --git a/app/Api/V1/Requests/Search/TransactionSearchRequest.php b/app/Api/V1/Requests/Search/TransactionSearchRequest.phpnew file mode 100644index 0000000000..f1bed30e15--- /dev/null+++ b/app/Api/V1/Requests/Search/TransactionSearchRequest.php@@ -0,0 +1,40 @@+<?php+/*+ * SearchRequest.php+ * Copyright (c) 2026 [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\Requests\Search;++use FireflyIII\Api\V1\Requests\AggregateFormRequest;+use FireflyIII\Api\V1\Requests\PaginationRequest;+use FireflyIII\Models\TransactionJournal;++class TransactionSearchRequest extends AggregateFormRequest+{++ #[\Override]+ protected function getRequests(): array+ {+ return [+ [PaginationRequest::class, 'sort_class' => TransactionJournal::class],+ SearchQueryRequest::class,+ // [ObjectTypeApiRequest::class, 'object_type' => Account::class],+ ];+ }+}