Add limit to object groups #3150

This commit is contained in:
James Cole 2020-07-21 06:30:37 +02:00
parent bb841e66c7
commit f777abdeb1
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
3 changed files with 6 additions and 5 deletions

View File

@ -57,7 +57,6 @@ class ObjectGroupController extends Controller
}
/**
* TODO add limit
* @param AutocompleteRequest $request
*
* @return JsonResponse
@ -66,7 +65,7 @@ class ObjectGroupController extends Controller
{
$data = $request->getData();
$return = [];
$result = $this->repository->search($data['query']);
$result = $this->repository->search($data['query'], $data['limit']);
/** @var ObjectGroup $account */
foreach ($result as $objectGroup) {

View File

@ -61,10 +61,11 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
/**
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function search(string $query): Collection
public function search(string $query, int $limit): Collection
{
$dbQuery = $this->user->objectGroups()->orderBy('order', 'ASC')->orderBy('title', 'ASC');
if ('' !== $query) {
@ -77,7 +78,7 @@ class ObjectGroupRepository implements ObjectGroupRepositoryInterface
}
return $dbQuery->get(['object_groups.*']);
return $dbQuery->take($limit)->get(['object_groups.*']);
}
/**

View File

@ -39,10 +39,11 @@ interface ObjectGroupRepositoryInterface
/**
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function search(string $query): Collection;
public function search(string $query, int $limit): Collection;
/**
* Delete empty ones.