mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Better index for accounts.
This commit is contained in:
		| @@ -24,9 +24,11 @@ declare(strict_types=1); | ||||
| namespace FireflyIII\Api\V2\Controllers\Model\Account; | ||||
| 
 | ||||
| use FireflyIII\Api\V2\Controllers\Controller; | ||||
| use FireflyIII\Api\V2\Request\Model\Account\IndexRequest; | ||||
| use FireflyIII\Api\V2\Request\Model\Transaction\InfiniteListRequest; | ||||
| use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Transformers\V2\AccountTransformer; | ||||
| use FireflyIII\Transformers\V2\BillTransformer; | ||||
| use Illuminate\Http\JsonResponse; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| 
 | ||||
| @@ -56,6 +58,27 @@ class IndexController extends Controller | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * TODO see autocomplete/accountcontroller for list. | ||||
|      */ | ||||
|     public function index(IndexRequest $request): JsonResponse | ||||
|     { | ||||
|         $this->repository->resetAccountOrder(); | ||||
|         $types = $request->getAccountTypes(); | ||||
|         $accounts       = $this->repository->getAccountsByType($types); | ||||
|         $pageSize    = $this->parameters->get('limit'); | ||||
|         $count       = $accounts->count(); | ||||
|         $accounts       = $accounts->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); | ||||
|         $paginator   = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page')); | ||||
|         $transformer = new AccountTransformer(); | ||||
|         $transformer->setParameters($this->parameters); // give params to transformer
 | ||||
| 
 | ||||
|         return response() | ||||
|             ->json($this->jsonApiList('accounts', $paginator, $transformer)) | ||||
|             ->header('Content-Type', self::CONTENT_TYPE) | ||||
|             ; | ||||
|     } | ||||
| 
 | ||||
|     public function infiniteList(InfiniteListRequest $request): JsonResponse | ||||
|     { | ||||
|         $this->repository->resetAccountOrder(); | ||||
|   | ||||
							
								
								
									
										68
									
								
								app/Api/V2/Request/Model/Account/IndexRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								app/Api/V2/Request/Model/Account/IndexRequest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| <?php | ||||
| /* | ||||
|  * IndexRequest.php | ||||
|  * Copyright (c) 2024 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\V2\Request\Model\Account; | ||||
| 
 | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use FireflyIII\Support\Http\Api\AccountFilter; | ||||
| use FireflyIII\Support\Request\ChecksLogin; | ||||
| use FireflyIII\Support\Request\ConvertsDataTypes; | ||||
| use Illuminate\Foundation\Http\FormRequest; | ||||
| 
 | ||||
| /** | ||||
|  * Class IndexRequest | ||||
|  * | ||||
|  * Lots of code stolen from the SingleDateRequest. | ||||
|  */ | ||||
| class IndexRequest extends FormRequest | ||||
| { | ||||
|     use ChecksLogin; | ||||
|     use ConvertsDataTypes; | ||||
|     use AccountFilter; | ||||
| 
 | ||||
|     /** | ||||
|      * Get all data from the request. | ||||
|      */ | ||||
|     public function getDate(): Carbon | ||||
|     { | ||||
|         return $this->getCarbonDate('date'); | ||||
|     } | ||||
| 
 | ||||
|     public function getAccountTypes(): array | ||||
|     { | ||||
|         $type = (string)$this->get('type', 'default'); | ||||
| 
 | ||||
|         return $this->mapAccountTypes($type); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * The rules that the incoming request must be matched against. | ||||
|      */ | ||||
|     public function rules(): array | ||||
|     { | ||||
|         return [ | ||||
|             'date' => 'date|after:1900-01-01|before:2099-12-31', | ||||
|         ]; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user