Split category repository into two repositories. One for database calls for single categories, the other pertaining all categories.

This commit is contained in:
James Cole
2015-12-29 22:44:13 +01:00
parent 35154dc7a3
commit 95f4a83f41
7 changed files with 542 additions and 529 deletions

View File

@@ -5,6 +5,7 @@ use Carbon\Carbon;
use FireflyIII\Http\Requests\CategoryFormRequest;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
@@ -68,12 +69,12 @@ class CategoryController extends Controller
}
/**
* @param CategoryRepositoryInterface $repository
* @param Category $category
* @param SingleCategoryRepositoryInterface $repository
* @param Category $category
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(CategoryRepositoryInterface $repository, Category $category)
public function destroy(SingleCategoryRepositoryInterface $repository, Category $category)
{
$name = $category->name;
@@ -107,17 +108,18 @@ class CategoryController extends Controller
}
/**
* @param CategoryRepositoryInterface $repository
* @param CategoryRepositoryInterface $repository
* @param SingleCategoryRepositoryInterface $singleRepository
*
* @return \Illuminate\View\View
*/
public function index(CategoryRepositoryInterface $repository)
public function index(CategoryRepositoryInterface $repository, SingleCategoryRepositoryInterface $singleRepository)
{
$categories = $repository->getCategories();
$categories->each(
function (Category $category) use ($repository) {
$category->lastActivity = $repository->getLatestActivity($category);
function (Category $category) use ($singleRepository) {
$category->lastActivity = $singleRepository->getLatestActivity($category);
}
);
@@ -143,14 +145,14 @@ class CategoryController extends Controller
}
/**
* @param CategoryRepositoryInterface $repository
* @param SingleCategoryRepositoryInterface $repository
* @param Category $category
*
* @param $date
*
* @return \Illuminate\View\View
*/
public function showWithDate(CategoryRepositoryInterface $repository, Category $category, $date)
public function showWithDate(SingleCategoryRepositoryInterface $repository, Category $category, $date)
{
$carbon = new Carbon($date);
$range = Preferences::get('viewRange', '1M')->data;
@@ -170,12 +172,12 @@ class CategoryController extends Controller
}
/**
* @param CategoryRepositoryInterface $repository
* @param SingleCategoryRepositoryInterface $repository
* @param Category $category
*
* @return \Illuminate\View\View
*/
public function show(CategoryRepositoryInterface $repository, Category $category)
public function show(SingleCategoryRepositoryInterface $repository, Category $category)
{
$hideCategory = true; // used in list.
$page = intval(Input::get('page'));
@@ -226,11 +228,11 @@ class CategoryController extends Controller
/**
* @param CategoryFormRequest $request
* @param CategoryRepositoryInterface $repository
* @param SingleCategoryRepositoryInterface $repository
*
* @return \Illuminate\Http\RedirectResponse
*/
public function store(CategoryFormRequest $request, CategoryRepositoryInterface $repository)
public function store(CategoryFormRequest $request, SingleCategoryRepositoryInterface $repository)
{
$categoryData = [
'name' => $request->input('name'),
@@ -253,12 +255,12 @@ class CategoryController extends Controller
/**
* @param CategoryFormRequest $request
* @param CategoryRepositoryInterface $repository
* @param SingleCategoryRepositoryInterface $repository
* @param Category $category
*
* @return \Illuminate\Http\RedirectResponse
*/
public function update(CategoryFormRequest $request, CategoryRepositoryInterface $repository, Category $category)
public function update(CategoryFormRequest $request, SingleCategoryRepositoryInterface $repository, Category $category)
{
$categoryData = [
'name' => $request->input('name'),

View File

@@ -7,6 +7,7 @@ use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Navigation;
@@ -38,12 +39,12 @@ class CategoryController extends Controller
/**
* Show an overview for a category for all time, per month/week/year.
*
* @param CategoryRepositoryInterface $repository
* @param Category $category
* @param SingleCategoryRepositoryInterface $repository
* @param Category $category
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function all(CategoryRepositoryInterface $repository, Category $category)
public function all(SingleCategoryRepositoryInterface $repository, Category $category)
{
// oldest transaction in category:
$start = $repository->getFirstActivityDate($category);
@@ -137,8 +138,13 @@ class CategoryController extends Controller
*
* @return \Illuminate\Http\JsonResponse
*/
public function multiYear(CategoryRepositoryInterface $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts, Collection $categories)
public function multiYear($reportType, Carbon $start, Carbon $end, Collection $accounts, Collection $categories)
{
/** @var CategoryRepositoryInterface $repository */
$repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
/** @var SingleCategoryRepositoryInterface $singleRepository */
$singleRepository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');
// chart properties for cache:
$cache = new CacheProperties();
$cache->addProperty($reportType);
@@ -180,8 +186,8 @@ class CategoryController extends Controller
$earned = $repository->earnedNoCategoryForAccounts($accounts, $currentStart, $currentEnd);
} else {
$name = $category->name;
$spent = $repository->spentInPeriodForAccounts($category, $accounts, $currentStart, $currentEnd);
$earned = $repository->earnedInPeriodForAccounts($category, $accounts, $currentStart, $currentEnd);
$spent = $singleRepository->spentInPeriodForAccounts($category, $accounts, $currentStart, $currentEnd);
$earned = $singleRepository->earnedInPeriodForAccounts($category, $accounts, $currentStart, $currentEnd);
}
// save to array:
@@ -206,12 +212,12 @@ class CategoryController extends Controller
}
/**
* @param CategoryRepositoryInterface $repository
* @param SingleCategoryRepositoryInterface $repository
* @param Category $category
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function currentPeriod(CategoryRepositoryInterface $repository, Category $category)
public function currentPeriod(SingleCategoryRepositoryInterface $repository, Category $category)
{
$start = clone Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
@@ -246,14 +252,14 @@ class CategoryController extends Controller
}
/**
* @param CategoryRepositoryInterface $repository
* @param SingleCategoryRepositoryInterface $repository
* @param Category $category
*
* @param $date
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, $date)
public function specificPeriod(SingleCategoryRepositoryInterface $repository, Category $category, $date)
{
$carbon = new Carbon($date);
$range = Preferences::get('viewRange', '1M')->data;