mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Fix sort params
This commit is contained in:
@@ -41,13 +41,16 @@ trait ExpandsQuery
|
||||
return $query->skip($skip)->take($pagination['size']);
|
||||
}
|
||||
|
||||
final protected function addSortParams(Builder $query, ?SortFields $sort): Builder
|
||||
final protected function addSortParams(string $class, Builder $query, ?SortFields $sort): Builder
|
||||
{
|
||||
$config = config('api.valid_query_sort')[$class] ?? [];
|
||||
if (null === $sort) {
|
||||
return $query;
|
||||
}
|
||||
foreach ($sort->all() as $sortField) {
|
||||
$query->orderBy($sortField->name(), $sortField->isAscending() ? 'ASC' : 'DESC');
|
||||
if (in_array($sortField->name(), $config, true)) {
|
||||
$query->orderBy($sortField->name(), $sortField->isAscending() ? 'ASC' : 'DESC');
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
@@ -24,17 +24,23 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\JsonApi;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use LaravelJsonApi\Core\Query\SortFields;
|
||||
|
||||
trait SortsCollection
|
||||
{
|
||||
protected function sortCollection(Collection $collection, ?SortFields $sortFields): Collection
|
||||
protected function sortCollection(string $class, Collection $collection, ?SortFields $sortFields): Collection
|
||||
{
|
||||
Log::debug(__METHOD__);
|
||||
$config = config('api.valid_api_sort')[$class] ?? [];
|
||||
if (null === $sortFields) {
|
||||
return $collection;
|
||||
}
|
||||
foreach ($sortFields->all() as $sortField) {
|
||||
$collection = $sortField->isAscending() ? $collection->sortBy($sortField->name()) : $collection->sortByDesc($sortField->name());
|
||||
if (in_array($sortField->name(), $config, true)) {
|
||||
Log::debug(sprintf('Sort collection by "%s"', $sortField->name()));
|
||||
$collection = $sortField->isAscending() ? $collection->sortBy($sortField->name()) : $collection->sortByDesc($sortField->name());
|
||||
}
|
||||
}
|
||||
|
||||
return $collection;
|
||||
|
@@ -23,12 +23,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Support\JsonApi;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use LaravelJsonApi\Core\Query\SortFields;
|
||||
|
||||
trait ValidateSortParameters
|
||||
{
|
||||
public function needsFullDataset(string $class, ?SortFields $params): bool
|
||||
{
|
||||
Log::debug(__METHOD__);
|
||||
if (null === $params) {
|
||||
return false;
|
||||
}
|
||||
@@ -37,6 +39,7 @@ trait ValidateSortParameters
|
||||
|
||||
foreach ($params->all() as $field) {
|
||||
if (in_array($field->name(), $config, true)) {
|
||||
Log::debug('TRUE');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user