Auto commit for release 'develop' on 2024-08-05

This commit is contained in:
github-actions
2024-08-05 05:06:53 +02:00
parent d2e9b64bf5
commit ed265f68ba
32 changed files with 574 additions and 564 deletions

View File

@@ -29,28 +29,28 @@ class AccountCollectionQuery extends ResourceQuery
'array',
JsonApiRule::fieldSets(),
],
'userGroupId' => [
'userGroupId' => [
'nullable',
'integer',
new IsAllowedGroupAction(Account::class, request()->method()),
],
'startPeriod' => [
'startPeriod' => [
'nullable',
'date',
new IsDateOrTime(),
new isValidDateRange(),
new IsValidDateRange(),
],
'endPeriod' => [
'endPeriod' => [
'nullable',
'date',
new IsDateOrTime(),
new isValidDateRange(),
new IsValidDateRange(),
],
'filter' => [
'nullable',
'array',
JsonApiRule::filter($validFilters),
new IsValidAccountType()
new IsValidAccountType(),
],
'include' => [
'nullable',

View File

@@ -29,10 +29,8 @@ use FireflyIII\Support\JsonApi\Enrichments\AccountEnrichment;
use Illuminate\Support\Facades\Log;
use LaravelJsonApi\Contracts\Store\CreatesResources;
use LaravelJsonApi\Contracts\Store\QueriesAll;
use LaravelJsonApi\Contracts\Store\QueryOneBuilder;
use LaravelJsonApi\NonEloquent\AbstractRepository;
use LaravelJsonApi\NonEloquent\Capabilities\CrudRelations;
use LaravelJsonApi\NonEloquent\Capabilities\CrudResource;
use LaravelJsonApi\NonEloquent\Concerns\HasCrudCapability;
use LaravelJsonApi\NonEloquent\Concerns\HasRelationsCapability;
@@ -52,26 +50,25 @@ class AccountRepository extends AbstractRepository implements QueriesAll, Create
use HasRelationsCapability;
use UsergroupAware;
/**
* SiteRepository constructor.
*/
public function __construct() {
public function __construct()
{
Log::debug(__METHOD__);
}
public function exists(string $resourceId): bool
{
$result = null !== Account::find((int) $resourceId);
Log::debug(sprintf('%s: %s',__METHOD__, var_export($result, true)));
Log::debug(sprintf('%s: %s', __METHOD__, var_export($result, true)));
return $result;
}
public function find(string $resourceId): ?object
{
die(__METHOD__);
exit(__METHOD__);
Log::debug(__METHOD__);
// throw new \RuntimeException('trace me');
$account = Account::find((int) $resourceId);
@@ -98,12 +95,14 @@ class AccountRepository extends AbstractRepository implements QueriesAll, Create
protected function crud(): Capabilities\CrudAccount
{
Log::debug(__METHOD__);
return Capabilities\CrudAccount::make();
}
protected function relations(): CrudRelations
{
Log::debug(__METHOD__);
return Capabilities\CrudAccountRelations::make();
}
}

View File

@@ -1,28 +1,27 @@
<?php
declare(strict_types=1);
namespace FireflyIII\JsonApi\V2\Accounts;
use FireflyIII\Rules\BelongsUser;
use Illuminate\Support\Facades\Log;
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
{
Log::debug(__METHOD__);
die('am i used');
exit('am i used');
return [
'type' => [
new BelongsUser()
new BelongsUser(),
],
'name' => [
'nullable',
@@ -31,5 +30,4 @@ class AccountRequest extends ResourceRequest
],
];
}
}

View File

@@ -29,7 +29,7 @@ class AccountResource extends JsonApiResource
*/
public function attributes($request): iterable
{
//Log::debug(__METHOD__);
// Log::debug(__METHOD__);
return [
'created_at' => $this->resource->created_at,
@@ -63,7 +63,6 @@ class AccountResource extends JsonApiResource
// other things
'last_activity' => $this->resource->last_activity,
// object group
'object_group_id' => $this->resource->object_group_id,
'object_group_title' => $this->resource->object_group_title,

View File

@@ -28,7 +28,7 @@ class AccountSchema extends Schema
*/
public function fields(): array
{
Log::debug(__METHOD__);
Log::debug(__METHOD__);
return [
ID::make(),
@@ -87,6 +87,7 @@ class AccountSchema extends Schema
foreach ($config as $entry) {
$array[] = Filter::make($entry);
}
return $array;
}
@@ -94,18 +95,18 @@ class AccountSchema extends Schema
{
Log::debug(__METHOD__);
$this->setUserGroup($this->server->getUsergroup());
return AccountRepository::make()
->withServer($this->server)
->withSchema($this)
->withUserGroup($this->userGroup);
->withServer($this->server)
->withSchema($this)
->withUserGroup($this->userGroup)
;
}
/**
* @inheritDoc
*/
public function pagination(): EnumerablePagination
{
Log::debug(__METHOD__);
return EnumerablePagination::make();
}
}

View File

@@ -41,16 +41,16 @@ use LaravelJsonApi\NonEloquent\Capabilities\QueryAll;
class AccountQuery extends QueryAll implements HasPagination
{
use AccountFilter;
use CollectsCustomParameters;
use ExpandsQuery;
use FiltersPagination;
use SortsCollection;
use SortsQueryResults;
use UsergroupAware;
use ValidateSortParameters;
use CollectsCustomParameters;
use AccountFilter;
use SortsQueryResults;
//use PaginatesEnumerables;
// use PaginatesEnumerables;
#[\Override]
/**
@@ -62,49 +62,46 @@ class AccountQuery extends QueryAll implements HasPagination
{
Log::debug(__METHOD__);
// collect sort options
$sort = $this->queryParameters->sortFields();
$sort = $this->queryParameters->sortFields();
// collect pagination based on the page
$pagination = $this->filtersPagination($this->queryParameters->page());
$pagination = $this->filtersPagination($this->queryParameters->page());
// check if we need all accounts, regardless of pagination
// This is necessary when the user wants to sort on specific params.
$needsAll = $this->needsFullDataset(Account::class, $sort);
$needsAll = $this->needsFullDataset(Account::class, $sort);
// params that were not recognised, may be my own custom stuff.
$otherParams = $this->getOtherParams($this->queryParameters->unrecognisedParameters());
// start the query
$query = $this->userGroup->accounts();
$query = $this->userGroup->accounts();
// add sort and filter parameters to the query.
$query = $this->addSortParams(Account::class, $query, $sort);
$query = $this->addFilterParams(Account::class, $query, $this->queryParameters->filter());
$query = $this->addSortParams(Account::class, $query, $sort);
$query = $this->addFilterParams(Account::class, $query, $this->queryParameters->filter());
// collect the result.
$collection = $query->get(['accounts.*']);
$collection = $query->get(['accounts.*']);
// sort the data after the query, and return it right away.
$collection = $this->sortCollection(Account::class, $collection, $sort);
$collection = $this->sortCollection(Account::class, $collection, $sort);
// if the entire collection needs to be enriched and sorted, do so now:
$totalCount = $collection->count();
$totalCount = $collection->count();
Log::debug(sprintf('Total is %d', $totalCount));
if ($needsAll) {
Log::debug('Needs the entire collection');
// enrich the entire collection
$enrichment = new AccountEnrichment();
$enrichment = new AccountEnrichment();
$enrichment->setStart($otherParams['start'] ?? null);
$enrichment->setEnd($otherParams['end'] ?? null);
$collection = $enrichment->enrich($collection);
$collection = $enrichment->enrich($collection);
// TODO sort the set based on post-query sort options:
$collection = $this->postQuerySort(Account::class, $collection, $sort);
$collection = $this->postQuerySort(Account::class, $collection, $sort);
// take the current page from the enriched set.
$currentPage = $collection->skip(($pagination['number'] - 1) * $pagination['size'])->take($pagination['size']);
}
if (!$needsAll) {
Log::debug('Needs only partial collection');
@@ -112,38 +109,33 @@ class AccountQuery extends QueryAll implements HasPagination
$currentPage = $collection->skip(($pagination['number'] - 1) * $pagination['size'])->take($pagination['size']);
// enrich only the current page.
$enrichment = new AccountEnrichment();
$enrichment = new AccountEnrichment();
$enrichment->setStart($otherParams['start'] ?? null);
$enrichment->setEnd($otherParams['end'] ?? null);
$currentPage = $enrichment->enrich($currentPage);
}
// get current page?
Log::debug(sprintf('Skip %d, take %d', ($pagination['number'] - 1) * $pagination['size'], $pagination['size']));
//$currentPage = $collection->skip(($pagination['number'] - 1) * $pagination['size'])->take($pagination['size']);
// $currentPage = $collection->skip(($pagination['number'] - 1) * $pagination['size'])->take($pagination['size']);
Log::debug(sprintf('New collection size: %d', $currentPage->count()));
// TODO add filters after the query, if there are filters that cannot be applied to the database
// TODO same for sort things.
return new LengthAwarePaginator($currentPage, $totalCount, $pagination['size'], $pagination['number']);
}
/**
* @inheritDoc
*/
#[\Override] public function paginate(array $page): Page
#[\Override]
public function paginate(array $page): Page
{
die('here weare');
exit('here weare');
// TODO: Implement paginate() method.
}
/**
* @inheritDoc
*/
#[\Override] public function getOrPaginate(?array $page): iterable
#[\Override]
public function getOrPaginate(?array $page): iterable
{
die('here weare');
exit('here weare');
// TODO: Implement getOrPaginate() method.
}
}

View File

@@ -42,17 +42,17 @@ class CrudAccount extends CrudResource
Log::debug(__METHOD__);
// enrich the collected data
$enrichment = new AccountEnrichment();
$enrichment = new AccountEnrichment();
// set start and date, if present.
$enrichment->setStart($otherParams['start'] ?? null);
$enrichment->setEnd($otherParams['end'] ?? null);
return $enrichment->enrichSingle($account);
}
public function create(array $validatedData): Account {
die('here we are');
public function create(array $validatedData): Account
{
exit('here we are');
}
}