mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-26 05:26:17 +00:00
improved request handling
This commit is contained in:
@@ -71,40 +71,40 @@ class ShowController extends Controller
|
||||
public function index(ShowRequest $request): JsonResponse
|
||||
{
|
||||
$manager = $this->getManager();
|
||||
$params = $request->getParameters();
|
||||
$this->parameters->set('type', $params['type']);
|
||||
|
||||
// types to get, page size:
|
||||
$types = $this->mapAccountTypes($params['type']);
|
||||
[
|
||||
'types' => $types,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'offset' => $offset,
|
||||
'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, $params['sort']);
|
||||
$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(($this->parameters->get('page') - 1) * $params['limit'], $params['limit']);
|
||||
|
||||
// #11007 go to the end of the previous day.
|
||||
$this->parameters->set('start', $this->parameters->get('start')?->subSecond());
|
||||
// #11018 also end of the day.
|
||||
$this->parameters->set('end', $this->parameters->get('end')?->endOfDay());
|
||||
$accounts = $collection->slice($offset, $limit);
|
||||
|
||||
// enrich
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
$enrichment = new AccountEnrichment();
|
||||
$enrichment->setSort($params['sort']);
|
||||
$enrichment->setDate($this->parameters->get('date'));
|
||||
$enrichment->setStart($this->parameters->get('start'));
|
||||
$enrichment->setEnd($this->parameters->get('end'));
|
||||
$enrichment->setSort($sort);
|
||||
$enrichment->setDate($date);
|
||||
$enrichment->setStart($start);
|
||||
$enrichment->setEnd($end);
|
||||
$enrichment->setUser($admin);
|
||||
$accounts = $enrichment->enrich($accounts);
|
||||
|
||||
// make paginator:
|
||||
$paginator = new LengthAwarePaginator($accounts, $count, $params['limit'], $this->parameters->get('page'));
|
||||
$paginator = new LengthAwarePaginator($accounts, $count, $limit, $page);
|
||||
$paginator->setPath(route('api.v1.accounts.index').$this->buildParams());
|
||||
|
||||
/** @var AccountTransformer $transformer */
|
||||
@@ -129,19 +129,19 @@ class ShowController extends Controller
|
||||
$this->repository->resetAccountOrder();
|
||||
$account->refresh();
|
||||
$manager = $this->getManager();
|
||||
|
||||
// #11007 go to the end of the previous day.
|
||||
$this->parameters->set('start', $this->parameters->get('start')?->subSecond());
|
||||
// #11018 also end of the day.
|
||||
$this->parameters->set('end', $this->parameters->get('end')?->endOfDay());
|
||||
[
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'date' => $date,
|
||||
] = $request->attributes->all();
|
||||
|
||||
// enrich
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
$enrichment = new AccountEnrichment();
|
||||
$enrichment->setDate($this->parameters->get('date'));
|
||||
$enrichment->setStart($this->parameters->get('start'));
|
||||
$enrichment->setEnd($this->parameters->get('end'));
|
||||
$enrichment->setDate($date);
|
||||
$enrichment->setStart($start);
|
||||
$enrichment->setEnd($end);
|
||||
$enrichment->setUser($admin);
|
||||
$account = $enrichment->enrichSingle($account);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Api\V1\Controllers\Models\UserGroup;
|
||||
|
||||
use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Api\V1\Requests\Data\DateRequest;
|
||||
use FireflyIII\Api\V1\Requests\PaginationRequest;
|
||||
use FireflyIII\Repositories\UserGroup\UserGroupRepositoryInterface;
|
||||
use FireflyIII\Transformers\UserGroupTransformer;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -52,16 +52,20 @@ class IndexController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
public function index(DateRequest $request): JsonResponse
|
||||
public function index(PaginationRequest $request): JsonResponse
|
||||
{
|
||||
$administrations = $this->repository->get();
|
||||
$pageSize = $this->parameters->get('limit');
|
||||
[
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'offset' => $offset,
|
||||
] = $request->attributes->all();
|
||||
$count = $administrations->count();
|
||||
$administrations = $administrations->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
|
||||
$paginator = new LengthAwarePaginator($administrations, $count, $pageSize, $this->parameters->get('page'));
|
||||
$administrations = $administrations->slice($offset, $limit);
|
||||
$paginator = new LengthAwarePaginator($administrations, $count, $limit, $page);
|
||||
$transformer = new UserGroupTransformer();
|
||||
|
||||
$transformer->setParameters($this->parameters); // give params to transformer
|
||||
$transformer->setParameters($request->attributes); // give params to transformer
|
||||
|
||||
return response()
|
||||
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
|
||||
|
||||
Reference in New Issue
Block a user