New API stuff

This commit is contained in:
James Cole 2024-08-02 13:45:41 +02:00
parent 7e37d10016
commit 76a41fec50
5 changed files with 35 additions and 2 deletions

View File

@ -27,6 +27,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Support\JsonApi\Concerns\UsergroupAware;
use FireflyIII\Support\JsonApi\Enrichments\AccountEnrichment;
use Illuminate\Support\Facades\Log;
use LaravelJsonApi\Contracts\Store\CreatesResources;
use LaravelJsonApi\Contracts\Store\QueriesAll;
use LaravelJsonApi\NonEloquent\AbstractRepository;
use LaravelJsonApi\NonEloquent\Capabilities\CrudRelations;
@ -43,12 +44,14 @@ use LaravelJsonApi\NonEloquent\Concerns\HasRelationsCapability;
* This is necessary because the user can't just query all accounts (it would return other user's data)
* and because we also need to collect all kinds of metadata, like the currency and user info.
*/
class AccountRepository extends AbstractRepository implements QueriesAll
class AccountRepository extends AbstractRepository implements QueriesAll, CreatesResources
{
use HasCrudCapability;
use HasRelationsCapability;
use UsergroupAware;
/**
* SiteRepository constructor.
*/

View File

@ -0,0 +1,24 @@
<?php
namespace FireflyIII\JsonApi\V2\Accounts;
use Illuminate\Validation\Rule;
use LaravelJsonApi\Laravel\Http\Requests\ResourceRequest;
use LaravelJsonApi\Validation\Rule as JsonApiRule;
class AccountRequest extends ResourceRequest
{
/**
* Get the validation rules for the resource.
*
* @return array
*/
public function rules(): array
{
return [
// @TODO
];
}
}

View File

@ -39,4 +39,8 @@ class CrudAccount extends CrudResource
return $enrichment->enrichSingle($account);
}
public function create(array $validatedData): Account {
die('here we are');
}
}

View File

@ -33,6 +33,7 @@ class AccountPolicy
*/
public function view(User $user, Account $account): bool
{
die('OK');
return true;
return auth()->check() && $user->id === $account->user_id;
@ -45,6 +46,7 @@ class AccountPolicy
*/
public function viewAny(): bool
{
die('OK');
return true;
return auth()->check();

View File

@ -243,7 +243,7 @@ Route::group(
JsonApiRoute::server('v2')->prefix('v2')
->resources(function (ResourceRegistrar $server): void {
// ACCOUNTS
$server->resource('accounts', AccountController::class)->readOnly()->relationships(function (Relationships $relations): void {
$server->resource('accounts', AccountController::class)->relationships(function (Relationships $relations): void {
$relations->hasOne('user')->readOnly();
});
// $server->resource('accounts', AccountController::class)->readOnly();