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

View File

@ -63,7 +63,6 @@ class AccountController extends Controller
}
/**
* TODO add limit
* @param AutocompleteRequest $request
*
* @return JsonResponse
@ -78,7 +77,7 @@ class AccountController extends Controller
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$return = [];
$result = $repository->searchAccount((string) $query, $types);
$result = $repository->searchAccount((string) $query, $types, $data['limit']);
$defaultCurrency = app('amount')->getDefaultCurrency();
/** @var Account $account */

View File

@ -559,10 +559,11 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @param string $query
* @param array $types
* @param int $limit
*
* @return Collection
*/
public function searchAccount(string $query, array $types): Collection
public function searchAccount(string $query, array $types, int $limit): Collection
{
$dbQuery = $this->user->accounts()
->where('active', 1)
@ -582,7 +583,7 @@ class AccountRepository implements AccountRepositoryInterface
$dbQuery->whereIn('account_types.type', $types);
}
return $dbQuery->get(['accounts.*']);
return $dbQuery->take($limit)->get(['accounts.*']);
}
/**

View File

@ -276,10 +276,11 @@ interface AccountRepositoryInterface
/**
* @param string $query
* @param array $types
* @param int $limit
*
* @return Collection
*/
public function searchAccount(string $query, array $types): Collection;
public function searchAccount(string $query, array $types, int $limit): Collection;
/**
* @param User $user

View File

@ -214,7 +214,7 @@ class Search implements SearchInterface
case 'source':
// source can only be asset, liability or revenue account:
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::REVENUE];
$accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes);
$accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes, 25);
if ($accounts->count() > 0) {
$totalAccounts = $accounts->merge($totalAccounts);
}
@ -223,7 +223,7 @@ class Search implements SearchInterface
case 'destination':
// source can only be asset, liability or expense account:
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE];
$accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes);
$accounts = $this->accountRepository->searchAccount($modifier['value'], $searchTypes, 25);
if ($accounts->count() > 0) {
$totalAccounts = $accounts->merge($totalAccounts);
}