Add limit to bills. #3150

This commit is contained in:
James Cole 2020-07-21 06:22:29 +02:00
parent 62fd701808
commit 858158d886
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
4 changed files with 7 additions and 5 deletions

View File

@ -65,7 +65,7 @@ class BillController extends Controller
public function bills(AutocompleteRequest $request): JsonResponse
{
$data = $request->getData();
$result = $this->repository->searchBill($data['query']);
$result = $this->repository->searchBill($data['query'], $data['limit']);
$filtered = $result->map(
static function (Bill $item) {
return [

View File

@ -661,14 +661,15 @@ class BillRepository implements BillRepositoryInterface
/**
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function searchBill(string $query): Collection
public function searchBill(string $query, int $limit): Collection
{
$query = sprintf('%%%s%%', $query);
return $this->user->bills()->where('name', 'LIKE', $query)->get();
return $this->user->bills()->where('name', 'LIKE', $query)->take($limit)->get();
}
/**

View File

@ -287,10 +287,11 @@ interface BillRepositoryInterface
/**
* @param string $query
* @param int $limit
*
* @return Collection
*/
public function searchBill(string $query): Collection;
public function searchBill(string $query, int $limit): Collection;
/**
* @param User $user

View File

@ -235,7 +235,7 @@ class Search implements SearchInterface
}
break;
case 'bill':
$result = $this->billRepository->searchBill($modifier['value']);
$result = $this->billRepository->searchBill($modifier['value'], 25);
if ($result->count() > 0) {
$collector->setBills($result);
}