From 077f3e095bc25f7aa850c356ee60005d1cd971d2 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 26 Jul 2024 12:52:54 +0200 Subject: [PATCH] Various API changes for v2 --- .../Controllers/AccountController.php | 32 ++--- .../AccountBalanceRepository.php | 2 +- .../AccountBalanceResource.php | 2 +- .../AccountBalances/AccountBalanceSchema.php | 2 +- .../Capabilities/AccountBalanceQuery.php | 2 +- .../{V3 => V2}/Accounts/AccountRepository.php | 2 +- .../{V3 => V2}/Accounts/AccountResource.php | 5 +- .../{V3 => V2}/Accounts/AccountSchema.php | 2 +- .../Accounts/Capabilities/AccountQuery.php | 2 +- app/JsonApi/{V3 => V2}/Server.php | 8 +- app/JsonApi/{V3 => V2}/Users/UserResource.php | 2 +- app/JsonApi/{V3 => V2}/Users/UserSchema.php | 2 +- app/Models/Account.php | 57 ++++---- composer.json | 1 + composer.lock | 126 +++++++++++++++++- config/jsonapi.php | 4 +- config/laravel-model-caching.php | 11 ++ routes/api.php | 101 +++++++++----- 18 files changed, 264 insertions(+), 99 deletions(-) rename app/Http/Controllers/Api/{V3 => V2}/Controllers/AccountController.php (54%) rename app/JsonApi/{V3 => V2}/AccountBalances/AccountBalanceRepository.php (96%) rename app/JsonApi/{V3 => V2}/AccountBalances/AccountBalanceResource.php (94%) rename app/JsonApi/{V3 => V2}/AccountBalances/AccountBalanceSchema.php (95%) rename app/JsonApi/{V3 => V2}/AccountBalances/Capabilities/AccountBalanceQuery.php (96%) rename app/JsonApi/{V3 => V2}/Accounts/AccountRepository.php (97%) rename app/JsonApi/{V3 => V2}/Accounts/AccountResource.php (96%) rename app/JsonApi/{V3 => V2}/Accounts/AccountSchema.php (97%) rename app/JsonApi/{V3 => V2}/Accounts/Capabilities/AccountQuery.php (97%) rename app/JsonApi/{V3 => V2}/Server.php (76%) rename app/JsonApi/{V3 => V2}/Users/UserResource.php (95%) rename app/JsonApi/{V3 => V2}/Users/UserSchema.php (96%) create mode 100644 config/laravel-model-caching.php diff --git a/app/Http/Controllers/Api/V3/Controllers/AccountController.php b/app/Http/Controllers/Api/V2/Controllers/AccountController.php similarity index 54% rename from app/Http/Controllers/Api/V3/Controllers/AccountController.php rename to app/Http/Controllers/Api/V2/Controllers/AccountController.php index 6051904899..7639cee1a3 100644 --- a/app/Http/Controllers/Api/V3/Controllers/AccountController.php +++ b/app/Http/Controllers/Api/V2/Controllers/AccountController.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace FireflyIII\Http\Controllers\Api\V3\Controllers; +namespace FireflyIII\Http\Controllers\Api\V2\Controllers; use FireflyIII\Http\Controllers\Controller; -use FireflyIII\JsonApi\V3\AccountBalances\AccountBalanceSchema; +use FireflyIII\JsonApi\V2\AccountBalances\AccountBalanceSchema; use FireflyIII\Models\Account; use Illuminate\Contracts\Support\Responsable; use LaravelJsonApi\Core\Facades\JsonApi; @@ -26,18 +26,18 @@ class AccountController extends Controller use Actions\Update; use Actions\UpdateRelationship; - public function readAccountBalances(AnonymousQuery $query, AccountBalanceSchema $schema, Account $account): Responsable - { - $schema = JsonApi::server()->schemas()->schemaFor('account-balances'); - - $models = $schema - ->repository() - ->queryAll() - ->withRequest($query) - ->withAccount($account) - ->get() - ; - - return DataResponse::make($models); - } +// public function readAccountBalances(AnonymousQuery $query, AccountBalanceSchema $schema, Account $account): Responsable +// { +// $schema = JsonApi::server()->schemas()->schemaFor('account-balances'); +// +// $models = $schema +// ->repository() +// ->queryAll() +// ->withRequest($query) +// ->withAccount($account) +// ->get() +// ; +// +// return DataResponse::make($models); +// } } diff --git a/app/JsonApi/V3/AccountBalances/AccountBalanceRepository.php b/app/JsonApi/V2/AccountBalances/AccountBalanceRepository.php similarity index 96% rename from app/JsonApi/V3/AccountBalances/AccountBalanceRepository.php rename to app/JsonApi/V2/AccountBalances/AccountBalanceRepository.php index f5fa8c0193..6d4551cc93 100644 --- a/app/JsonApi/V3/AccountBalances/AccountBalanceRepository.php +++ b/app/JsonApi/V2/AccountBalances/AccountBalanceRepository.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3\AccountBalances; +namespace FireflyIII\JsonApi\V2\AccountBalances; use FireflyIII\Entities\AccountBalance; use LaravelJsonApi\Contracts\Store\QueriesAll; diff --git a/app/JsonApi/V3/AccountBalances/AccountBalanceResource.php b/app/JsonApi/V2/AccountBalances/AccountBalanceResource.php similarity index 94% rename from app/JsonApi/V3/AccountBalances/AccountBalanceResource.php rename to app/JsonApi/V2/AccountBalances/AccountBalanceResource.php index 15d12d9152..e9d3520556 100644 --- a/app/JsonApi/V3/AccountBalances/AccountBalanceResource.php +++ b/app/JsonApi/V2/AccountBalances/AccountBalanceResource.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3\AccountBalances; +namespace FireflyIII\JsonApi\V2\AccountBalances; use Illuminate\Http\Request; use LaravelJsonApi\Core\Resources\JsonApiResource; diff --git a/app/JsonApi/V3/AccountBalances/AccountBalanceSchema.php b/app/JsonApi/V2/AccountBalances/AccountBalanceSchema.php similarity index 95% rename from app/JsonApi/V3/AccountBalances/AccountBalanceSchema.php rename to app/JsonApi/V2/AccountBalances/AccountBalanceSchema.php index 6e4b4573cf..e0c2d13bb9 100644 --- a/app/JsonApi/V3/AccountBalances/AccountBalanceSchema.php +++ b/app/JsonApi/V2/AccountBalances/AccountBalanceSchema.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3\AccountBalances; +namespace FireflyIII\JsonApi\V2\AccountBalances; use FireflyIII\Entities\AccountBalance; use LaravelJsonApi\Core\Schema\Schema; diff --git a/app/JsonApi/V3/AccountBalances/Capabilities/AccountBalanceQuery.php b/app/JsonApi/V2/AccountBalances/Capabilities/AccountBalanceQuery.php similarity index 96% rename from app/JsonApi/V3/AccountBalances/Capabilities/AccountBalanceQuery.php rename to app/JsonApi/V2/AccountBalances/Capabilities/AccountBalanceQuery.php index 6221948d4f..19994ab2a0 100644 --- a/app/JsonApi/V3/AccountBalances/Capabilities/AccountBalanceQuery.php +++ b/app/JsonApi/V2/AccountBalances/Capabilities/AccountBalanceQuery.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3\AccountBalances\Capabilities; +namespace FireflyIII\JsonApi\V2\AccountBalances\Capabilities; use FireflyIII\Entities\AccountBalance; use FireflyIII\Models\Account; diff --git a/app/JsonApi/V3/Accounts/AccountRepository.php b/app/JsonApi/V2/Accounts/AccountRepository.php similarity index 97% rename from app/JsonApi/V3/Accounts/AccountRepository.php rename to app/JsonApi/V2/Accounts/AccountRepository.php index 1c4415756d..d73ddd75a2 100644 --- a/app/JsonApi/V3/Accounts/AccountRepository.php +++ b/app/JsonApi/V2/Accounts/AccountRepository.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3\Accounts; +namespace FireflyIII\JsonApi\V2\Accounts; use FireflyIII\Models\Account; use FireflyIII\Support\JsonApi\Concerns\UsergroupAware; diff --git a/app/JsonApi/V3/Accounts/AccountResource.php b/app/JsonApi/V2/Accounts/AccountResource.php similarity index 96% rename from app/JsonApi/V3/Accounts/AccountResource.php rename to app/JsonApi/V2/Accounts/AccountResource.php index 2d4d0525c9..b809641bb5 100644 --- a/app/JsonApi/V3/Accounts/AccountResource.php +++ b/app/JsonApi/V2/Accounts/AccountResource.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3\Accounts; +namespace FireflyIII\JsonApi\V2\Accounts; use FireflyIII\Models\Account; use Illuminate\Http\Request; @@ -123,7 +123,8 @@ class AccountResource extends JsonApiResource { return [ $this->relation('user')->withData($this->resource->user), - $this->relation('account_balances')->withData($this->resource->balances), + $this->relation('currency')->withData($this->resource->transactionCurrency), + //$this->relation('account_balances')->withData($this->resource->balances), ]; } } diff --git a/app/JsonApi/V3/Accounts/AccountSchema.php b/app/JsonApi/V2/Accounts/AccountSchema.php similarity index 97% rename from app/JsonApi/V3/Accounts/AccountSchema.php rename to app/JsonApi/V2/Accounts/AccountSchema.php index 12aefffe11..bb50bd600b 100644 --- a/app/JsonApi/V3/Accounts/AccountSchema.php +++ b/app/JsonApi/V2/Accounts/AccountSchema.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3\Accounts; +namespace FireflyIII\JsonApi\V2\Accounts; use FireflyIII\Models\Account; use LaravelJsonApi\Eloquent\Contracts\Paginator; diff --git a/app/JsonApi/V3/Accounts/Capabilities/AccountQuery.php b/app/JsonApi/V2/Accounts/Capabilities/AccountQuery.php similarity index 97% rename from app/JsonApi/V3/Accounts/Capabilities/AccountQuery.php rename to app/JsonApi/V2/Accounts/Capabilities/AccountQuery.php index 948c5f4486..c52d97d921 100644 --- a/app/JsonApi/V3/Accounts/Capabilities/AccountQuery.php +++ b/app/JsonApi/V2/Accounts/Capabilities/AccountQuery.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3\Accounts\Capabilities; +namespace FireflyIII\JsonApi\V2\Accounts\Capabilities; use FireflyIII\Support\JsonApi\Concerns\UsergroupAware; use FireflyIII\Support\JsonApi\Enrichments\AccountEnrichment; diff --git a/app/JsonApi/V3/Server.php b/app/JsonApi/V2/Server.php similarity index 76% rename from app/JsonApi/V3/Server.php rename to app/JsonApi/V2/Server.php index 6ab65c5e51..a0c5d97356 100644 --- a/app/JsonApi/V3/Server.php +++ b/app/JsonApi/V2/Server.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3; +namespace FireflyIII\JsonApi\V2; -use FireflyIII\JsonApi\V3\Accounts\AccountSchema; -use FireflyIII\JsonApi\V3\AccountBalances\AccountBalanceSchema; -use FireflyIII\JsonApi\V3\Users\UserSchema; +use FireflyIII\JsonApi\V2\Accounts\AccountSchema; +use FireflyIII\JsonApi\V2\AccountBalances\AccountBalanceSchema; +use FireflyIII\JsonApi\V2\Users\UserSchema; use LaravelJsonApi\Core\Server\Server as BaseServer; class Server extends BaseServer diff --git a/app/JsonApi/V3/Users/UserResource.php b/app/JsonApi/V2/Users/UserResource.php similarity index 95% rename from app/JsonApi/V3/Users/UserResource.php rename to app/JsonApi/V2/Users/UserResource.php index 44d5be0d18..137325e65d 100644 --- a/app/JsonApi/V3/Users/UserResource.php +++ b/app/JsonApi/V2/Users/UserResource.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3\Users; +namespace FireflyIII\JsonApi\V2\Users; use FireflyIII\Models\User; use Illuminate\Http\Request; diff --git a/app/JsonApi/V3/Users/UserSchema.php b/app/JsonApi/V2/Users/UserSchema.php similarity index 96% rename from app/JsonApi/V3/Users/UserSchema.php rename to app/JsonApi/V2/Users/UserSchema.php index f503151f30..8a32b34676 100644 --- a/app/JsonApi/V3/Users/UserSchema.php +++ b/app/JsonApi/V2/Users/UserSchema.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace FireflyIII\JsonApi\V3\Users; +namespace FireflyIII\JsonApi\V2\Users; use FireflyIII\User; use LaravelJsonApi\Eloquent\Contracts\Paginator; diff --git a/app/Models/Account.php b/app/Models/Account.php index df6f4ae9c4..8bfdc2a192 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -28,6 +28,7 @@ use Eloquent; use FireflyIII\Support\Models\ReturnsIntegerIdTrait; use FireflyIII\Support\Models\ReturnsIntegerUserIdTrait; use FireflyIII\User; +use GeneaLabs\LaravelModelCaching\Traits\Cachable; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Collection; @@ -95,22 +96,22 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @method static Builder|Account withTrashed() * @method static Builder|Account withoutTrashed() * - * @property Carbon $lastActivityDate - * @property string $startBalance - * @property string $endBalance - * @property string $difference - * @property string $interest - * @property string $interestPeriod - * @property string $accountTypeString - * @property Location $location - * @property string $liability_direction - * @property string $current_debt - * @property int $user_group_id + * @property Carbon $lastActivityDate + * @property string $startBalance + * @property string $endBalance + * @property string $difference + * @property string $interest + * @property string $interestPeriod + * @property string $accountTypeString + * @property Location $location + * @property string $liability_direction + * @property string $current_debt + * @property int $user_group_id * * @method static EloquentBuilder|Account whereUserGroupId($value) * - * @property null|UserGroup $userGroup - * @property mixed $account_id + * @property null|UserGroup $userGroup + * @property mixed $account_id * * @mixin Eloquent */ @@ -120,9 +121,10 @@ class Account extends Model use ReturnsIntegerIdTrait; use ReturnsIntegerUserIdTrait; use SoftDeletes; + use Cachable; protected $casts - = [ + = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', 'user_id' => 'integer', @@ -131,9 +133,9 @@ class Account extends Model 'encrypted' => 'boolean', ]; - protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban']; + protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban']; - protected $hidden = ['encrypted']; + protected $hidden = ['encrypted']; private bool $joinedAccountTypes = false; /** @@ -144,13 +146,13 @@ class Account extends Model public static function routeBinder(string $value): self { if (auth()->check()) { - $accountId = (int)$value; + $accountId = (int) $value; /** @var User $user */ - $user = auth()->user(); + $user = auth()->user(); /** @var null|Account $account */ - $account = $user->accounts()->with(['accountType'])->find($accountId); + $account = $user->accounts()->with(['accountType'])->find($accountId); if (null !== $account) { return $account; } @@ -181,9 +183,8 @@ class Account extends Model { /** @var null|AccountMeta $metaValue */ $metaValue = $this->accountMeta() - ->where('name', 'account_number') - ->first() - ; + ->where('name', 'account_number') + ->first(); return null !== $metaValue ? $metaValue->data : ''; } @@ -246,7 +247,7 @@ class Account extends Model public function setVirtualBalanceAttribute(mixed $value): void { - $value = (string)$value; + $value = (string) $value; if ('' === $value) { $value = null; } @@ -266,7 +267,7 @@ class Account extends Model protected function accountId(): Attribute { return Attribute::make( - get: static fn ($value) => (int)$value, + get: static fn($value) => (int) $value, ); } @@ -276,21 +277,21 @@ class Account extends Model protected function accountTypeId(): Attribute { return Attribute::make( - get: static fn ($value) => (int)$value, + get: static fn($value) => (int) $value, ); } protected function iban(): Attribute { return Attribute::make( - get: static fn ($value) => null === $value ? null : trim(str_replace(' ', '', (string)$value)), + get: static fn($value) => null === $value ? null : trim(str_replace(' ', '', (string) $value)), ); } protected function order(): Attribute { return Attribute::make( - get: static fn ($value) => (int)$value, + get: static fn($value) => (int) $value, ); } @@ -300,7 +301,7 @@ class Account extends Model protected function virtualBalance(): Attribute { return Attribute::make( - get: static fn ($value) => (string)$value, + get: static fn($value) => (string) $value, ); } } diff --git a/composer.json b/composer.json index 8e721952af..c0148abbd6 100644 --- a/composer.json +++ b/composer.json @@ -84,6 +84,7 @@ "bacon/bacon-qr-code": "2.*", "diglactic/laravel-breadcrumbs": "^9", "gdbots/query-parser": "^3.0", + "genealabs/laravel-model-caching": "^11.0", "guzzlehttp/guzzle": "^7.8", "jc5/google2fa-laravel": "^2.0", "jc5/recovery": "^2", diff --git a/composer.lock b/composer.lock index 9f731b90fe..8903d56f49 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a3648ab093343dd83bf7e728034ab46c", + "content-hash": "9d828d17b38cf563cd5cfc14c906c08f", "packages": [ { "name": "bacon/bacon-qr-code", @@ -1045,6 +1045,130 @@ }, "time": "2021-12-05T19:44:35+00:00" }, + { + "name": "genealabs/laravel-model-caching", + "version": "11.0.1", + "source": { + "type": "git", + "url": "https://github.com/mikebronner/laravel-model-caching.git", + "reference": "2a38f0f1ed3554cf2da272d66c4d08a7885f196b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mikebronner/laravel-model-caching/zipball/2a38f0f1ed3554cf2da272d66c4d08a7885f196b", + "reference": "2a38f0f1ed3554cf2da272d66c4d08a7885f196b", + "shasum": "" + }, + "require": { + "genealabs/laravel-pivot-events": "^10.0|^11.0", + "illuminate/cache": "^10.0|^11.0", + "illuminate/config": "^10.0|^11.0", + "illuminate/console": "^10.0|^11.0", + "illuminate/container": "^10.0|^11.0", + "illuminate/database": "^10.0|^11.0", + "illuminate/http": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", + "php": ">=8.1" + }, + "require-dev": { + "doctrine/dbal": "^3.3", + "fakerphp/faker": "^1.11", + "laravel/legacy-factories": "^1.3", + "laravel/nova": "^4.0", + "orchestra/testbench": "^8.0|^9.0", + "orchestra/testbench-browser-kit": "^8.0", + "php-coveralls/php-coveralls": "^2.2", + "phpunit/phpunit": "^10.0", + "slevomat/coding-standard": "^7.0|^8.14", + "squizlabs/php_codesniffer": "^3.6", + "symfony/thanks": "^1.2" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "GeneaLabs\\LaravelModelCaching\\Providers\\Service" + ] + } + }, + "autoload": { + "psr-4": { + "GeneaLabs\\LaravelModelCaching\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike Bronner", + "email": "hello@genealabs.com" + } + ], + "description": "Automatic caching for Eloquent models.", + "support": { + "issues": "https://github.com/mikebronner/laravel-model-caching/issues", + "source": "https://github.com/mikebronner/laravel-model-caching/tree/11.0.1" + }, + "time": "2024-03-14T23:34:57+00:00" + }, + { + "name": "genealabs/laravel-pivot-events", + "version": "11.0.0", + "source": { + "type": "git", + "url": "https://github.com/mikebronner/laravel-pivot-events.git", + "reference": "16e974d80160774641f4323f5ffb757b79f300d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mikebronner/laravel-pivot-events/zipball/16e974d80160774641f4323f5ffb757b79f300d3", + "reference": "16e974d80160774641f4323f5ffb757b79f300d3", + "shasum": "" + }, + "require": { + "illuminate/database": "^8.0|^9.0|^10.0|^11.0", + "illuminate/support": "^8.0|^9.0|^10.0|^11.0" + }, + "require-dev": { + "orchestra/testbench": "^9.0", + "phpunit/phpunit": "^10.5", + "symfony/thanks": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "GeneaLabs\\LaravelPivotEvents\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike Bronner", + "email": "hello@genealabs.com", + "homepage": "https://genealabs.com", + "role": "Developer" + } + ], + "description": "This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.", + "homepage": "https://github.com/mikebronner/laravel-pivot-events", + "keywords": [ + "eloquent events", + "eloquent extra events", + "laravel BelongsToMany events", + "laravel pivot events", + "laravel sync events" + ], + "support": { + "issues": "https://github.com/mikebronner/laravel-pivot-events/issues", + "source": "https://github.com/mikebronner/laravel-pivot-events" + }, + "time": "2024-03-14T23:24:54+00:00" + }, { "name": "graham-campbell/result-type", "version": "v1.1.3", diff --git a/config/jsonapi.php b/config/jsonapi.php index 498c1545a2..4047db0651 100644 --- a/config/jsonapi.php +++ b/config/jsonapi.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use FireflyIII\JsonApi\V3\Server; +use FireflyIII\JsonApi\V2\Server; return [ /* @@ -30,6 +30,6 @@ return [ | class name of the server class. */ 'servers' => [ - 'v3' => Server::class, + 'v2' => Server::class, ], ]; diff --git a/config/laravel-model-caching.php b/config/laravel-model-caching.php new file mode 100644 index 0000000000..cda02fbe7a --- /dev/null +++ b/config/laravel-model-caching.php @@ -0,0 +1,11 @@ + '', + + 'enabled' => env('MODEL_CACHE_ENABLED', true), + + 'use-database-keying' => env('MODEL_CACHE_USE_DATABASE_KEYING', true), + + 'store' => env('MODEL_CACHE_STORE'), +]; diff --git a/routes/api.php b/routes/api.php index 1a5bc447f4..be94da8681 100644 --- a/routes/api.php +++ b/routes/api.php @@ -22,14 +22,27 @@ declare(strict_types=1); -use FireflyIII\Http\Controllers\Api\V3\Controllers\AccountController; +use FireflyIII\Http\Controllers\Api\V2\Controllers\AccountController; use LaravelJsonApi\Laravel\Facades\JsonApiRoute; use LaravelJsonApi\Laravel\Http\Controllers\JsonApiController; -use LaravelJsonApi\Laravel\Routing\ActionRegistrar; use LaravelJsonApi\Laravel\Routing\Relationships; use LaravelJsonApi\Laravel\Routing\ResourceRegistrar; -// V2 auto complete controller(s) +/* + * + * ____ ____ ___ .______ ______ __ __ .___________. _______ _______. + * \ \ / / |__ \ | _ \ / __ \ | | | | | || ____| / | + * \ \/ / ) | | |_) | | | | | | | | | `---| |----`| |__ | (----` + * \ / / / | / | | | | | | | | | | | __| \ \ + * \ / / /_ | |\ \----.| `--' | | `--' | | | | |____.----) | + * \__/ |____| | _| `._____| \______/ \______/ |__| |_______|_______/ + */ + + + +/** + * AUTOCOMPLETE ROUTES + */ Route::group( [ 'namespace' => 'FireflyIII\Api\V2\Controllers\Autocomplete', @@ -37,7 +50,6 @@ Route::group( 'as' => 'api.v2.autocomplete.', ], static function (): void { - // Auto complete routes Route::get('accounts', ['uses' => 'AccountController@accounts', 'as' => 'accounts']); Route::get('categories', ['uses' => 'CategoryController@categories', 'as' => 'categories']); Route::get('tags', ['uses' => 'TagController@tags', 'as' => 'tags']); @@ -45,7 +57,9 @@ Route::group( } ); -// V2 API routes for charts +/** + * CHART ROUTES + */ Route::group( [ 'namespace' => 'FireflyIII\Api\V2\Controllers\Chart', @@ -54,27 +68,13 @@ Route::group( ], static function (): void { Route::get('account/dashboard', ['uses' => 'AccountController@dashboard', 'as' => 'account.dashboard']); - // Route::get('budget/dashboard', ['uses' => 'BudgetController@dashboard', 'as' => 'budget.dashboard']); - // Route::get('category/dashboard', ['uses' => 'CategoryController@dashboard', 'as' => 'category.dashboard']); + Route::get('budget/dashboard', ['uses' => 'BudgetController@dashboard', 'as' => 'budget.dashboard']); + Route::get('category/dashboard', ['uses' => 'CategoryController@dashboard', 'as' => 'category.dashboard']); Route::get('balance/balance', ['uses' => 'BalanceController@balance', 'as' => 'balance.balance']); } ); -// JsonApiRoute::server('v3') -// ->prefix('v3') -// ->resources(function (ResourceRegistrar $server) { -// $server->resource('accounts', AccountController::class)->readOnly()->relationships(function (Relationships $relations) { -// $relations->hasOne('user')->readOnly(); -// //$relations->hasMany('account_balances')->readOnly(); -// }) -// ->actions(function (ActionRegistrar $actions) { -// $actions->withId()->get('account-balances', 'readAccountBalances'); // non-eloquent pseudo relation -// }); -// $server->resource('users', JsonApiController::class)->readOnly()->relationships(function (Relationships $relations) { -// $relations->hasMany('accounts')->readOnly(); -// }); -// $server->resource('account-balances', JsonApiController::class); -// }); + // V2 API route for Summary boxes // BASIC @@ -121,19 +121,19 @@ Route::group( } ); -// V2 API route for accounts. -Route::group( - [ - 'namespace' => 'FireflyIII\Api\V2\Controllers\Model\Account', - 'prefix' => 'v2/accounts', - 'as' => 'api.v2.accounts.', - ], - static function (): void { - Route::get('', ['uses' => 'IndexController@index', 'as' => 'index']); - Route::get('{account}', ['uses' => 'ShowController@show', 'as' => 'show']); - Route::put('{account}', ['uses' => 'UpdateController@update', 'as' => 'update']); - } -); +//// V2 API route for accounts. +//Route::group( +// [ +// 'namespace' => 'FireflyIII\Api\V2\Controllers\Model\Account', +// 'prefix' => 'v2/accounts', +// 'as' => 'api.v2.accounts.', +// ], +// static function (): void { +// Route::get('', ['uses' => 'IndexController@index', 'as' => 'index']); +// Route::get('{account}', ['uses' => 'ShowController@show', 'as' => 'show']); +// Route::put('{account}', ['uses' => 'UpdateController@update', 'as' => 'update']); +// } +//); // V2 API route for subscriptions. Route::group( @@ -247,7 +247,34 @@ Route::group( } ); -// down here is v1 +/** + * V2 JSON API ROUTES + */ +JsonApiRoute::server('v2')->prefix('v2') + ->resources(function (ResourceRegistrar $server) { + /** + * ACCOUNTS + */ + $server->resource('accounts', AccountController::class)->readOnly()->relationships(function (Relationships $relations) { + $relations->hasOne('user')->readOnly(); + }); + + /** + * USERS + */ + $server->resource('users', JsonApiController::class)->readOnly()->relationships(function (Relationships $relations) { + $relations->hasMany('accounts')->readOnly(); + }); + }); + +/* + * ____ ____ __ .______ ______ __ __ .___________. _______ _______. + * \ \ / / /_ | | _ \ / __ \ | | | | | || ____| / | + * \ \/ / | | | |_) | | | | | | | | | `---| |----`| |__ | (----` + * \ / | | | / | | | | | | | | | | | __| \ \ + * \ / | | | |\ \----.| `--' | | `--' | | | | |____.----) | + * \__/ |_| | _| `._____| \______/ \______/ |__| |_______|_______/ + */ // Autocomplete controllers Route::group( @@ -278,7 +305,7 @@ Route::group( ); // CHART ROUTES. -// Accounts +// Chart accounts Route::group( [ 'namespace' => 'FireflyIII\Api\V1\Controllers\Chart',