2024-05-10 09:42:09 +02:00
|
|
|
<?php
|
|
|
|
|
2024-07-26 12:52:54 +02:00
|
|
|
namespace FireflyIII\JsonApi\V2\Accounts;
|
2024-05-10 09:42:09 +02:00
|
|
|
|
|
|
|
use FireflyIII\Models\Account;
|
2024-07-27 15:42:43 +02:00
|
|
|
use FireflyIII\Support\JsonApi\Concerns\UsergroupAware;
|
|
|
|
use LaravelJsonApi\Core\Schema\Schema;
|
2024-05-10 09:42:09 +02:00
|
|
|
use LaravelJsonApi\Eloquent\Fields\Relations\HasOne;
|
2024-07-27 15:42:43 +02:00
|
|
|
use LaravelJsonApi\NonEloquent\Fields\Attribute;
|
|
|
|
use LaravelJsonApi\NonEloquent\Fields\ID;
|
|
|
|
use LaravelJsonApi\NonEloquent\Fields\Relation;
|
|
|
|
|
2024-05-10 09:42:09 +02:00
|
|
|
|
|
|
|
class AccountSchema extends Schema
|
|
|
|
{
|
2024-07-27 15:42:43 +02:00
|
|
|
use UsergroupAware;
|
|
|
|
|
2024-05-10 09:42:09 +02:00
|
|
|
/**
|
|
|
|
* The model the schema corresponds to.
|
2024-07-27 15:42:43 +02:00
|
|
|
*
|
|
|
|
* @var string
|
2024-05-10 09:42:09 +02:00
|
|
|
*/
|
|
|
|
public static string $model = Account::class;
|
|
|
|
|
2024-07-27 15:42:43 +02:00
|
|
|
|
2024-05-10 09:42:09 +02:00
|
|
|
/**
|
|
|
|
* Get the resource fields.
|
2024-07-27 15:42:43 +02:00
|
|
|
*
|
|
|
|
* @return array
|
2024-05-10 09:42:09 +02:00
|
|
|
*/
|
|
|
|
public function fields(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
ID::make(),
|
2024-07-27 15:42:43 +02:00
|
|
|
Attribute::make('name'),
|
2024-07-26 18:50:41 +02:00
|
|
|
HasOne::make('user')->readOnly(),
|
2024-05-10 09:42:09 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-07-27 15:42:43 +02:00
|
|
|
* Get the resource filters.
|
|
|
|
*
|
|
|
|
* @return array
|
2024-05-10 09:42:09 +02:00
|
|
|
*/
|
|
|
|
public function filters(): array
|
|
|
|
{
|
|
|
|
return [
|
2024-07-27 15:42:43 +02:00
|
|
|
// Filter::make('id'),
|
2024-05-10 09:42:09 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-07-27 15:42:43 +02:00
|
|
|
public function repository(): AccountRepository
|
2024-05-10 09:42:09 +02:00
|
|
|
{
|
2024-07-27 15:42:43 +02:00
|
|
|
$this->setUserGroup($this->server->getUsergroup());
|
|
|
|
return AccountRepository::make()
|
|
|
|
->withServer($this->server)
|
|
|
|
->withSchema($this)
|
|
|
|
->withUserGroup($this->userGroup);
|
2024-05-10 09:42:09 +02:00
|
|
|
}
|
2024-07-27 15:42:43 +02:00
|
|
|
|
2024-05-10 09:42:09 +02:00
|
|
|
}
|