mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add limit to category #3150
This commit is contained in:
parent
723696b971
commit
74ed80aaef
@ -56,7 +56,6 @@ class CategoryController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO add limit
|
||||
* @param AutocompleteRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
@ -64,7 +63,7 @@ class CategoryController extends Controller
|
||||
public function categories(AutocompleteRequest $request): JsonResponse
|
||||
{
|
||||
$data = $request->getData();
|
||||
$result = $this->repository->searchCategory($data['query']);
|
||||
$result = $this->repository->searchCategory($data['query'], $data['limit']);
|
||||
$filtered = $result->map(
|
||||
static function (Category $item) {
|
||||
return [
|
||||
|
@ -217,17 +217,18 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchCategory(string $query): Collection
|
||||
public function searchCategory(string $query, int $limit): Collection
|
||||
{
|
||||
$search = $this->user->categories();
|
||||
if ('' !== $query) {
|
||||
$search->where('name', 'LIKE', sprintf('%%%s%%', $query));
|
||||
}
|
||||
|
||||
return $search->get();
|
||||
return $search->take($limit)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,10 +113,11 @@ interface CategoryRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function searchCategory(string $query): Collection;
|
||||
public function searchCategory(string $query, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
|
@ -229,7 +229,7 @@ class Search implements SearchInterface
|
||||
}
|
||||
break;
|
||||
case 'category':
|
||||
$result = $this->categoryRepository->searchCategory($modifier['value']);
|
||||
$result = $this->categoryRepository->searchCategory($modifier['value'], 25);
|
||||
if ($result->count() > 0) {
|
||||
$collector->setCategories($result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user