Move CRUD method count() to account repository

This commit is contained in:
James Cole 2016-10-09 08:18:47 +02:00
parent 3f40751a1a
commit 1d2d3523d6
6 changed files with 27 additions and 23 deletions

View File

@ -52,18 +52,6 @@ class AccountCrud implements AccountCrudInterface
$this->user = $user;
}
/**
* @param array $types
*
* @return int
*/
public function count(array $types):int
{
$count = $this->user->accounts()->accountTypeIn($types)->count();
return $count;
}
/**
* @param Account $account
* @param Account $moveTo

View File

@ -24,13 +24,6 @@ use Illuminate\Support\Collection;
*/
interface AccountCrudInterface
{
/**
* @param array $types
*
* @return int
*/
public function count(array $types):int;
/**
* @param Account $account
* @param Account $moveTo

View File

@ -123,7 +123,7 @@ class HomeController extends Controller
{
$types = config('firefly.accountTypesByIdentifier.asset');
$count = $crud->count($types);
$count = $repository->count($types);
if ($count == 0) {
return redirect(route('new-user.index'));

View File

@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Crud\Account\AccountCrudInterface;
use FireflyIII\Http\Requests\NewUserFormRequest;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Preferences;
use Session;
use View;
@ -36,11 +37,11 @@ class NewUserController extends Controller
/**
* @param AccountCrudInterface $crud
* @param AccountRepositoryInterface $repository
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*/
public function index(AccountCrudInterface $crud)
public function index(AccountRepositoryInterface $repository)
{
View::share('title', trans('firefly.welcome'));
@ -48,7 +49,7 @@ class NewUserController extends Controller
$types = config('firefly.accountTypesByIdentifier.asset');
$count = $crud->count($types);
$count = $repository->count($types);
if ($count > 0) {
return redirect(route('index'));

View File

@ -50,6 +50,20 @@ class AccountRepository implements AccountRepositoryInterface
$this->user = $user;
}
/**
* Moved here from account CRUD
*
* @param array $types
*
* @return int
*/
public function count(array $types):int
{
$count = $this->user->accounts()->accountTypeIn($types)->count();
return $count;
}
/**
* This method will call AccountRepositoryInterface::journalsInPeriod and get all withdrawaks made from the given $accounts,
* as well as the transfers that move away from those $accounts. This is a slightly sharper selection

View File

@ -26,6 +26,14 @@ use Illuminate\Support\Collection;
*/
interface AccountRepositoryInterface
{
/**
* Moved here from account CRUD.
*
* @param array $types
*
* @return int
*/
public function count(array $types): int;
/**
* This method will call AccountRepositoryInterface::journalsInPeriod and get all withdrawaks made from the given $accounts,