Files
firefly-iii/app/JsonApi/V2/Accounts/AccountSchema.php

62 lines
1.3 KiB
PHP
Raw Normal View History

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'),
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
}