mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-07 06:31:22 +00:00
Create new request for search.
This commit is contained in:
@@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Api\V1\Controllers\Search;
|
namespace FireflyIII\Api\V1\Controllers\Search;
|
||||||
|
|
||||||
use FireflyIII\Api\V1\Controllers\Controller;
|
use FireflyIII\Api\V1\Controllers\Controller;
|
||||||
|
use FireflyIII\Api\V1\Requests\Search\TransactionSearchRequest;
|
||||||
use FireflyIII\Support\JsonApi\Enrichments\TransactionGroupEnrichment;
|
use FireflyIII\Support\JsonApi\Enrichments\TransactionGroupEnrichment;
|
||||||
use FireflyIII\Support\Search\SearchInterface;
|
use FireflyIII\Support\Search\SearchInterface;
|
||||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||||
@@ -42,12 +43,12 @@ class TransactionController extends Controller
|
|||||||
* This endpoint is documented at:
|
* This endpoint is documented at:
|
||||||
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/search/searchTransactions
|
* 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();
|
$manager = $this->getManager();
|
||||||
$fullQuery = (string) $request->get('query');
|
$fullQuery = (string) $request->attributes->get('query');
|
||||||
$page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
|
$page = $request->attributes->get('page');
|
||||||
$pageSize = $this->parameters->get('limit');
|
$pageSize = $request->attributes->get('limit');
|
||||||
$searcher->parseQuery($fullQuery);
|
$searcher->parseQuery($fullQuery);
|
||||||
$searcher->setPage($page);
|
$searcher->setPage($page);
|
||||||
$searcher->setLimit($pageSize);
|
$searcher->setLimit($pageSize);
|
||||||
|
|||||||
50
app/Api/V1/Requests/Search/SearchQueryRequest.php
Normal file
50
app/Api/V1/Requests/Search/SearchQueryRequest.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* SearchQueryRequest.php
|
||||||
|
* Copyright (c) 2026 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\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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
40
app/Api/V1/Requests/Search/TransactionSearchRequest.php
Normal file
40
app/Api/V1/Requests/Search/TransactionSearchRequest.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* SearchRequest.php
|
||||||
|
* Copyright (c) 2026 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\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],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user