mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-22 20:16:22 +00:00 
			
		
		
		
	PHPStorm can order methods by alphabet, who knew.
This commit is contained in:
		| @@ -72,7 +72,7 @@ class CategoryController extends Controller | ||||
|         $filtered = $result->map( | ||||
|             static function (Category $item) { | ||||
|                 return [ | ||||
|                     'id'   => (string) $item->id, | ||||
|                     'id'   => (string)$item->id, | ||||
|                     'name' => $item->name, | ||||
|                 ]; | ||||
|             } | ||||
|   | ||||
| @@ -72,10 +72,10 @@ class TagController extends Controller | ||||
|         $filtered = $result->map( | ||||
|             static function (Tag $item) { | ||||
|                 return [ | ||||
|                     'id'      => (string) $item->id, | ||||
|                     'name'    => $item->tag, | ||||
|                     'value'   => (string) $item->id, | ||||
|                     'label'   => $item->tag, | ||||
|                     'id'    => (string)$item->id, | ||||
|                     'name'  => $item->tag, | ||||
|                     'value' => (string)$item->id, | ||||
|                     'label' => $item->tag, | ||||
|                 ]; | ||||
|             } | ||||
|         ); | ||||
|   | ||||
| @@ -126,23 +126,23 @@ class AccountController extends Controller | ||||
|                 $currency = $default; | ||||
|             } | ||||
|             $currentSet        = [ | ||||
|                 'label'                            => $account->name, | ||||
|                 'label'                          => $account->name, | ||||
|                 // the currency that belongs to the account.
 | ||||
|                 'currency_id'                      => (string)$currency->id, | ||||
|                 'currency_code'                    => $currency->code, | ||||
|                 'currency_symbol'                  => $currency->symbol, | ||||
|                 'currency_decimal_places'          => $currency->decimal_places, | ||||
|                 'currency_id'                    => (string)$currency->id, | ||||
|                 'currency_code'                  => $currency->code, | ||||
|                 'currency_symbol'                => $currency->symbol, | ||||
|                 'currency_decimal_places'        => $currency->decimal_places, | ||||
| 
 | ||||
|                 // the default currency of the user (could be the same!)
 | ||||
|                 'native_currency_id'               => (string)$default->id, | ||||
|                 'native_currency_code'             => $default->code, | ||||
|                 'native_currency_symbol'           => $default->symbol, | ||||
|                 'native_currency_decimal_places'   => $default->decimal_places, | ||||
|                 'start'                            => $start->toAtomString(), | ||||
|                 'end'                              => $end->toAtomString(), | ||||
|                 'period'                           => '1D', | ||||
|                 'entries'                          => [], | ||||
|                 'native_entries'                   => [], | ||||
|                 'native_currency_id'             => (string)$default->id, | ||||
|                 'native_currency_code'           => $default->code, | ||||
|                 'native_currency_symbol'         => $default->symbol, | ||||
|                 'native_currency_decimal_places' => $default->decimal_places, | ||||
|                 'start'                          => $start->toAtomString(), | ||||
|                 'end'                            => $end->toAtomString(), | ||||
|                 'period'                         => '1D', | ||||
|                 'entries'                        => [], | ||||
|                 'native_entries'                 => [], | ||||
|             ]; | ||||
|             $currentStart      = clone $start; | ||||
|             $range             = app('steam')->balanceInRange($account, $start, clone $end, $currency); | ||||
|   | ||||
| @@ -124,11 +124,11 @@ class BudgetController extends Controller | ||||
|         foreach ($rows as $row) { | ||||
|             $current  = [ | ||||
|                 'label'                          => $budget->name, | ||||
|                 'currency_id'                    => (string) $row['currency_id'], | ||||
|                 'currency_id'                    => (string)$row['currency_id'], | ||||
|                 'currency_code'                  => $row['currency_code'], | ||||
|                 'currency_name'                  => $row['currency_name'], | ||||
|                 'currency_decimal_places'        => $row['currency_decimal_places'], | ||||
|                 'native_currency_id'             => (string) $row['native_currency_id'], | ||||
|                 'native_currency_id'             => (string)$row['native_currency_id'], | ||||
|                 'native_currency_code'           => $row['native_currency_code'], | ||||
|                 'native_currency_name'           => $row['native_currency_name'], | ||||
|                 'native_currency_decimal_places' => $row['native_currency_decimal_places'], | ||||
| @@ -189,12 +189,12 @@ class BudgetController extends Controller | ||||
|         foreach ($array as $currencyId => $block) { | ||||
|             $this->currencies[$currencyId] ??= TransactionCurrency::find($currencyId); | ||||
|             $return[$currencyId]           ??= [ | ||||
|                 'currency_id'                    => (string) $currencyId, | ||||
|                 'currency_id'                    => (string)$currencyId, | ||||
|                 'currency_code'                  => $block['currency_code'], | ||||
|                 'currency_name'                  => $block['currency_name'], | ||||
|                 'currency_symbol'                => $block['currency_symbol'], | ||||
|                 'currency_decimal_places'        => (int) $block['currency_decimal_places'], | ||||
|                 'native_currency_id'             => (string) $this->currency->id, | ||||
|                 'currency_decimal_places'        => (int)$block['currency_decimal_places'], | ||||
|                 'native_currency_id'             => (string)$this->currency->id, | ||||
|                 'native_currency_code'           => $this->currency->code, | ||||
|                 'native_currency_name'           => $this->currency->name, | ||||
|                 'native_currency_symbol'         => $this->currency->symbol, | ||||
|   | ||||
| @@ -112,22 +112,22 @@ class CategoryController extends Controller | ||||
|             } | ||||
|             // create arrays
 | ||||
|             $return[$key] ??= [ | ||||
|                 'label'                            => $categoryName, | ||||
|                 'currency_id'                      => (string)$currency->id, | ||||
|                 'currency_code'                    => $currency->code, | ||||
|                 'currency_name'                    => $currency->name, | ||||
|                 'currency_symbol'                  => $currency->symbol, | ||||
|                 'currency_decimal_places'          => $currency->decimal_places, | ||||
|                 'native_currency_id'               => (string)$default->id, | ||||
|                 'native_currency_code'             => $default->code, | ||||
|                 'native_currency_name'             => $default->name, | ||||
|                 'native_currency_symbol'           => $default->symbol, | ||||
|                 'native_currency_decimal_places'   => $default->decimal_places, | ||||
|                 'period'                           => null, | ||||
|                 'start'                            => $start->toAtomString(), | ||||
|                 'end'                              => $end->toAtomString(), | ||||
|                 'amount'                           => '0', | ||||
|                 'native_amount'                    => '0', | ||||
|                 'label'                          => $categoryName, | ||||
|                 'currency_id'                    => (string)$currency->id, | ||||
|                 'currency_code'                  => $currency->code, | ||||
|                 'currency_name'                  => $currency->name, | ||||
|                 'currency_symbol'                => $currency->symbol, | ||||
|                 'currency_decimal_places'        => $currency->decimal_places, | ||||
|                 'native_currency_id'             => (string)$default->id, | ||||
|                 'native_currency_code'           => $default->code, | ||||
|                 'native_currency_name'           => $default->name, | ||||
|                 'native_currency_symbol'         => $default->symbol, | ||||
|                 'native_currency_decimal_places' => $default->decimal_places, | ||||
|                 'period'                         => null, | ||||
|                 'start'                          => $start->toAtomString(), | ||||
|                 'end'                            => $end->toAtomString(), | ||||
|                 'amount'                         => '0', | ||||
|                 'native_amount'                  => '0', | ||||
|             ]; | ||||
| 
 | ||||
|             // add monies
 | ||||
|   | ||||
| @@ -67,43 +67,6 @@ class Controller extends BaseController | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     final protected function jsonApiList(string $key, LengthAwarePaginator $paginator, AbstractTransformer $transformer): array | ||||
|     { | ||||
|         $manager  = new Manager(); | ||||
|         $baseUrl  = request()->getSchemeAndHttpHost().'/api/v2'; | ||||
|         $manager->setSerializer(new JsonApiSerializer($baseUrl)); | ||||
| 
 | ||||
|         $objects  = $paginator->getCollection(); | ||||
| 
 | ||||
|         // the transformer, at this point, needs to collect information that ALL items in the collection
 | ||||
|         // require, like meta-data and stuff like that, and save it for later.
 | ||||
|         $transformer->collectMetaData($objects); | ||||
| 
 | ||||
|         $resource = new FractalCollection($objects, $transformer, $key); | ||||
|         $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); | ||||
| 
 | ||||
|         return $manager->createData($resource)->toArray(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Returns a JSON API object and returns it. | ||||
|      * | ||||
|      * @param array<int, mixed>|Model $object | ||||
|      */ | ||||
|     final protected function jsonApiObject(string $key, array|Model $object, AbstractTransformer $transformer): array | ||||
|     { | ||||
|         // create some objects:
 | ||||
|         $manager  = new Manager(); | ||||
|         $baseUrl  = request()->getSchemeAndHttpHost().'/api/v2'; | ||||
|         $manager->setSerializer(new JsonApiSerializer($baseUrl)); | ||||
| 
 | ||||
|         $transformer->collectMetaData(new Collection([$object])); | ||||
| 
 | ||||
|         $resource = new Item($object, $transformer, $key); | ||||
| 
 | ||||
|         return $manager->createData($resource)->toArray(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * TODO duplicate from V1 controller | ||||
|      * Method to grab all parameters from the URL. | ||||
| @@ -184,4 +147,41 @@ class Controller extends BaseController | ||||
| 
 | ||||
|         return $bag; | ||||
|     } | ||||
| 
 | ||||
|     final protected function jsonApiList(string $key, LengthAwarePaginator $paginator, AbstractTransformer $transformer): array | ||||
|     { | ||||
|         $manager  = new Manager(); | ||||
|         $baseUrl  = request()->getSchemeAndHttpHost().'/api/v2'; | ||||
|         $manager->setSerializer(new JsonApiSerializer($baseUrl)); | ||||
| 
 | ||||
|         $objects  = $paginator->getCollection(); | ||||
| 
 | ||||
|         // the transformer, at this point, needs to collect information that ALL items in the collection
 | ||||
|         // require, like meta-data and stuff like that, and save it for later.
 | ||||
|         $transformer->collectMetaData($objects); | ||||
| 
 | ||||
|         $resource = new FractalCollection($objects, $transformer, $key); | ||||
|         $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); | ||||
| 
 | ||||
|         return $manager->createData($resource)->toArray(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Returns a JSON API object and returns it. | ||||
|      * | ||||
|      * @param array<int, mixed>|Model $object | ||||
|      */ | ||||
|     final protected function jsonApiObject(string $key, array|Model $object, AbstractTransformer $transformer): array | ||||
|     { | ||||
|         // create some objects:
 | ||||
|         $manager  = new Manager(); | ||||
|         $baseUrl  = request()->getSchemeAndHttpHost().'/api/v2'; | ||||
|         $manager->setSerializer(new JsonApiSerializer($baseUrl)); | ||||
| 
 | ||||
|         $transformer->collectMetaData(new Collection([$object])); | ||||
| 
 | ||||
|         $resource = new Item($object, $transformer, $key); | ||||
| 
 | ||||
|         return $manager->createData($resource)->toArray(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -51,20 +51,6 @@ class ShowController extends Controller | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Show a budget. | ||||
|      */ | ||||
|     public function show(Budget $budget): JsonResponse | ||||
|     { | ||||
|         $transformer = new BudgetTransformer(); | ||||
|         $transformer->setParameters($this->parameters); | ||||
| 
 | ||||
|         return response() | ||||
|             ->api($this->jsonApiObject('budgets', $budget, $transformer)) | ||||
|             ->header('Content-Type', self::CONTENT_TYPE) | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * 2023-10-29 removed the cerSum reference, not sure where this is used atm | ||||
|      * so removed from api.php. Also applies to "spent" method. | ||||
| @@ -80,6 +66,20 @@ class ShowController extends Controller | ||||
|         return response()->json($result); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Show a budget. | ||||
|      */ | ||||
|     public function show(Budget $budget): JsonResponse | ||||
|     { | ||||
|         $transformer = new BudgetTransformer(); | ||||
|         $transformer->setParameters($this->parameters); | ||||
| 
 | ||||
|         return response() | ||||
|             ->api($this->jsonApiObject('budgets', $budget, $transformer)) | ||||
|             ->header('Content-Type', self::CONTENT_TYPE) | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * This endpoint is documented at: | ||||
|      * TODO add URL | ||||
|   | ||||
| @@ -114,23 +114,6 @@ class BasicController extends Controller | ||||
|         return response()->json($total); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Check if date is outside session range. | ||||
|      */ | ||||
|     protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
 | ||||
|     { | ||||
|         $result = false; | ||||
|         if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) { | ||||
|             $result = true; | ||||
|         } | ||||
|         // start and end in the past? use $end
 | ||||
|         if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) { | ||||
|             $result = true; | ||||
|         } | ||||
| 
 | ||||
|         return $result; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
| @@ -411,4 +394,21 @@ class BasicController extends Controller | ||||
| 
 | ||||
|         return $return; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Check if date is outside session range. | ||||
|      */ | ||||
|     protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
 | ||||
|     { | ||||
|         $result = false; | ||||
|         if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) { | ||||
|             $result = true; | ||||
|         } | ||||
|         // start and end in the past? use $end
 | ||||
|         if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) { | ||||
|             $result = true; | ||||
|         } | ||||
| 
 | ||||
|         return $result; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -35,43 +35,6 @@ use Illuminate\Http\JsonResponse; | ||||
|  */ | ||||
| class TransactionController extends Controller | ||||
| { | ||||
|     public function listByCount(ListByCountRequest $request): JsonResponse | ||||
|     { | ||||
|         // collect transactions:
 | ||||
|         /** @var GroupCollectorInterface $collector */ | ||||
|         $collector = app(GroupCollectorInterface::class); | ||||
|         $collector->setUserGroup(auth()->user()->userGroup) | ||||
|             ->withAPIInformation() | ||||
|             ->setStartRow($request->getStartRow()) | ||||
|             ->setEndRow($request->getEndRow()) | ||||
|             ->setTypes($request->getTransactionTypes()) | ||||
|         ; | ||||
| 
 | ||||
|         $start     = $this->parameters->get('start'); | ||||
|         $end       = $this->parameters->get('end'); | ||||
|         if (null !== $start) { | ||||
|             $collector->setStart($start); | ||||
|         } | ||||
|         if (null !== $end) { | ||||
|             $collector->setEnd($end); | ||||
|         } | ||||
| 
 | ||||
|         $paginator = $collector->getPaginatedGroups(); | ||||
|         $params    = $request->buildParams(); | ||||
|         $paginator->setPath( | ||||
|             sprintf( | ||||
|                 '%s?%s', | ||||
|                 route('api.v2.transactions.list'), | ||||
|                 $params | ||||
|             ) | ||||
|         ); | ||||
| 
 | ||||
|         return response() | ||||
|             ->json($this->jsonApiList('transactions', $paginator, new TransactionGroupTransformer())) | ||||
|             ->header('Content-Type', self::CONTENT_TYPE) | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     public function list(ListRequest $request): JsonResponse | ||||
|     { | ||||
|         // collect transactions:
 | ||||
| @@ -115,4 +78,40 @@ class TransactionController extends Controller | ||||
|             ->header('Content-Type', self::CONTENT_TYPE) | ||||
|         ; | ||||
|     } | ||||
| 
 | ||||
|     public function listByCount(ListByCountRequest $request): JsonResponse | ||||
|     { | ||||
|         // collect transactions:
 | ||||
|         /** @var GroupCollectorInterface $collector */ | ||||
|         $collector = app(GroupCollectorInterface::class); | ||||
|         $collector->setUserGroup(auth()->user()->userGroup) | ||||
|             ->withAPIInformation() | ||||
|             ->setStartRow($request->getStartRow()) | ||||
|             ->setEndRow($request->getEndRow()) | ||||
|             ->setTypes($request->getTransactionTypes()) | ||||
|         ; | ||||
| 
 | ||||
|         $start     = $this->parameters->get('start'); | ||||
|         $end       = $this->parameters->get('end'); | ||||
|         if (null !== $start) { | ||||
|             $collector->setStart($start); | ||||
|         } | ||||
|         if (null !== $end) { | ||||
|             $collector->setEnd($end); | ||||
|         } | ||||
| 
 | ||||
|         $paginator = $collector->getPaginatedGroups(); | ||||
|         $params    = $request->buildParams(); | ||||
|         $paginator->setPath( | ||||
|             sprintf( | ||||
|                 '%s?%s', | ||||
|                 route('api.v2.transactions.list'), | ||||
|                 $params | ||||
|             ) | ||||
|         ); | ||||
| 
 | ||||
|         return response() | ||||
|             ->json($this->jsonApiList('transactions', $paginator, new TransactionGroupTransformer())) | ||||
|             ->header('Content-Type', self::CONTENT_TYPE); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user