mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Small code changes for @ctrl-f5's PR.
- Dropped some "setParameters" calls if unused in transformer. - Add correct copyright - Sprintf instead of string concat - Small ident changes courtesy of phpstorm.
This commit is contained in:
@@ -70,48 +70,48 @@ class ShowController extends Controller
|
||||
*/
|
||||
public function index(ShowRequest $request): JsonResponse
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
$manager = $this->getManager();
|
||||
[
|
||||
'types' => $types,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'types' => $types,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'offset' => $offset,
|
||||
'sort' => $sort,
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'date' => $date,
|
||||
] = $request->attributes->all();
|
||||
'sort' => $sort,
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'date' => $date,
|
||||
]
|
||||
= $request->attributes->all();
|
||||
|
||||
// get list of accounts. Count it and split it.
|
||||
$this->repository->resetAccountOrder();
|
||||
$collection = $this->repository->getAccountsByType($types, $sort);
|
||||
$count = $collection->count();
|
||||
$collection = $this->repository->getAccountsByType($types, $sort);
|
||||
$count = $collection->count();
|
||||
|
||||
// continue sort:
|
||||
// TODO if the user sorts on DB dependent field there must be no slice before enrichment, only after.
|
||||
// TODO still need to figure out how to do this easily.
|
||||
$accounts = $collection->slice($offset, $limit);
|
||||
$accounts = $collection->slice($offset, $limit);
|
||||
|
||||
// enrich
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
$enrichment = new AccountEnrichment();
|
||||
$admin = auth()->user();
|
||||
$enrichment = new AccountEnrichment();
|
||||
$enrichment->setSort($sort);
|
||||
$enrichment->setDate($date);
|
||||
$enrichment->setStart($start);
|
||||
$enrichment->setEnd($end);
|
||||
$enrichment->setUser($admin);
|
||||
$accounts = $enrichment->enrich($accounts);
|
||||
$accounts = $enrichment->enrich($accounts);
|
||||
|
||||
// make paginator:
|
||||
$paginator = new LengthAwarePaginator($accounts, $count, $limit, $page);
|
||||
$paginator->setPath(route('api.v1.accounts.index').$this->buildParams());
|
||||
$paginator = new LengthAwarePaginator($accounts, $count, $limit, $page);
|
||||
$paginator->setPath(route('api.v1.accounts.index') . $this->buildParams());
|
||||
|
||||
/** @var AccountTransformer $transformer */
|
||||
$transformer = app(AccountTransformer::class);
|
||||
$transformer->setParameters($this->parameters);
|
||||
|
||||
$resource = new FractalCollection($accounts, $transformer, self::RESOURCE_KEY);
|
||||
$resource = new FractalCollection($accounts, $transformer, self::RESOURCE_KEY);
|
||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||
@@ -128,27 +128,22 @@ class ShowController extends Controller
|
||||
// get list of accounts. Count it and split it.
|
||||
$this->repository->resetAccountOrder();
|
||||
$account->refresh();
|
||||
$manager = $this->getManager();
|
||||
[
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'date' => $date,
|
||||
] = $request->attributes->all();
|
||||
$manager = $this->getManager();
|
||||
[$start, $end, $date,] = $request->attributes->all();
|
||||
|
||||
// enrich
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
$enrichment = new AccountEnrichment();
|
||||
$admin = auth()->user();
|
||||
$enrichment = new AccountEnrichment();
|
||||
$enrichment->setDate($date);
|
||||
$enrichment->setStart($start);
|
||||
$enrichment->setEnd($end);
|
||||
$enrichment->setUser($admin);
|
||||
$account = $enrichment->enrichSingle($account);
|
||||
$account = $enrichment->enrichSingle($account);
|
||||
|
||||
|
||||
/** @var AccountTransformer $transformer */
|
||||
$transformer = app(AccountTransformer::class);
|
||||
$transformer->setParameters($this->parameters);
|
||||
$resource = new Item($account, $transformer, self::RESOURCE_KEY);
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||
|
@@ -65,8 +65,6 @@ class IndexController extends Controller
|
||||
$paginator = new LengthAwarePaginator($administrations, $count, $limit, $page);
|
||||
$transformer = new UserGroupTransformer();
|
||||
|
||||
$transformer->setParameters($request->attributes); // give params to transformer
|
||||
|
||||
return response()
|
||||
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
|
||||
->header('Content-Type', self::CONTENT_TYPE)
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 james@firefly-iii.org
|
||||
* Copyright (c) 2025 https://github.com/ctrl-f5
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 james@firefly-iii.org
|
||||
* Copyright (c) 2025 https://github.com/ctrl-f5
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 james@firefly-iii.org
|
||||
* Copyright (c) 2025 https://github.com/ctrl-f5
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
@@ -27,14 +27,15 @@ use FireflyIII\Exceptions\ValidationException;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class DateRangeRequest extends ApiRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'start' => 'date|after:1970-01-02|before:2038-01-17|before:end|required_with:end|' . $this->required,
|
||||
'end' => 'date|after:1970-01-02|before:2038-01-17|after:start|required_with:start|' . $this->required,
|
||||
'start' => sprintf('date|after:1970-01-02|before:2038-01-17|before:end|required_with:end|' , $this->required),
|
||||
'end' => sprintf('date|after:1970-01-02|before:2038-01-17|after:start|required_with:start|' , $this->required),
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 james@firefly-iii.org
|
||||
* Copyright (c) 2025 https://github.com/ctrl-f5
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* ShowRequest.php
|
||||
* Copyright (c) 2025 james@firefly-iii.org
|
||||
* AccountTypeApiRequest.php
|
||||
* Copyright (c) 2025 https://github.com/ctrl-f5
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 james@firefly-iii.org
|
||||
* Copyright (c) 2025 https://github.com/ctrl-f5
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
|
@@ -34,11 +34,17 @@ abstract class AbstractTransformer extends TransformerAbstract
|
||||
{
|
||||
protected ParameterBag $parameters;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
final public function getParameters(): ParameterBag
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
final public function setParameters(ParameterBag $parameters): void
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
|
@@ -30,7 +30,6 @@ use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
* Class AccountTransformer
|
||||
@@ -46,7 +45,6 @@ class AccountTransformer extends AbstractTransformer
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->parameters = new ParameterBag();
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
$this->convertToPrimary = Amount::convertToPrimary();
|
||||
$this->primary = Amount::getPrimaryCurrency();
|
||||
|
Reference in New Issue
Block a user