From e525960320a8420d0d59a0a7a9ca1776cdd1fd5f Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 30 Aug 2019 07:49:08 +0200 Subject: [PATCH] Move method to correct repository. --- app/Api/V1/Controllers/BudgetLimitController.php | 9 ++++++++- .../Budget/BudgetLimitRepository.php | 16 ++++++++++++++++ .../Budget/BudgetLimitRepositoryInterface.php | 8 ++++++++ app/Repositories/Budget/BudgetRepository.php | 14 -------------- .../Budget/BudgetRepositoryInterface.php | 9 ++------- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/app/Api/V1/Controllers/BudgetLimitController.php b/app/Api/V1/Controllers/BudgetLimitController.php index b212ab5472..9b408c8917 100644 --- a/app/Api/V1/Controllers/BudgetLimitController.php +++ b/app/Api/V1/Controllers/BudgetLimitController.php @@ -28,6 +28,7 @@ use FireflyIII\Api\V1\Requests\BudgetLimitRequest; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Models\BudgetLimit; +use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Support\Http\Api\TransactionFilter; use FireflyIII\Transformers\BudgetLimitTransformer; @@ -53,6 +54,10 @@ class BudgetLimitController extends Controller /** @var BudgetRepositoryInterface The budget repository */ private $repository; + /** @var BudgetLimitRepositoryInterface */ + private $blRepository; + + /** * BudgetLimitController constructor. * @@ -66,7 +71,9 @@ class BudgetLimitController extends Controller /** @var User $user */ $user = auth()->user(); $this->repository = app(BudgetRepositoryInterface::class); + $this->blRepository = app(BudgetLimitRepositoryInterface::class); $this->repository->setUser($user); + $this->blRepository->setUser($user); return $next($request); } @@ -83,7 +90,7 @@ class BudgetLimitController extends Controller */ public function delete(BudgetLimit $budgetLimit): JsonResponse { - $this->repository->destroyBudgetLimit($budgetLimit); + $this->blRepository->destroyBudgetLimit($budgetLimit); return response()->json([], 204); } diff --git a/app/Repositories/Budget/BudgetLimitRepository.php b/app/Repositories/Budget/BudgetLimitRepository.php index 713529a571..01ab99ca3c 100644 --- a/app/Repositories/Budget/BudgetLimitRepository.php +++ b/app/Repositories/Budget/BudgetLimitRepository.php @@ -24,6 +24,8 @@ declare(strict_types=1); namespace FireflyIII\Repositories\Budget; +use Exception; +use FireflyIII\Models\BudgetLimit; use FireflyIII\User; use Log; @@ -47,6 +49,20 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface } } + /** + * Destroy a budget limit. + * + * @param BudgetLimit $budgetLimit + */ + public function destroyBudgetLimit(BudgetLimit $budgetLimit): void + { + try { + $budgetLimit->delete(); + } catch (Exception $e) { + Log::info(sprintf('Could not delete budget limit: %s', $e->getMessage())); + } + } + /** * @param User $user */ diff --git a/app/Repositories/Budget/BudgetLimitRepositoryInterface.php b/app/Repositories/Budget/BudgetLimitRepositoryInterface.php index ecd9f6a6dc..88a90122ef 100644 --- a/app/Repositories/Budget/BudgetLimitRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetLimitRepositoryInterface.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Repositories\Budget; +use FireflyIII\Models\BudgetLimit; use FireflyIII\User; /** @@ -30,6 +31,13 @@ use FireflyIII\User; */ interface BudgetLimitRepositoryInterface { + /** + * Destroy a budget limit. + * + * @param BudgetLimit $budgetLimit + */ + public function destroyBudgetLimit(BudgetLimit $budgetLimit): void; + /** * @param User $user */ diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 9e1ab8ab72..45ef4bcaf5 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -110,20 +110,6 @@ class BudgetRepository implements BudgetRepositoryInterface return true; } - /** - * Destroy a budget limit. - * - * @param BudgetLimit $budgetLimit - */ - public function destroyBudgetLimit(BudgetLimit $budgetLimit): void - { - try { - $budgetLimit->delete(); - } catch (Exception $e) { - Log::info(sprintf('Could not delete budget limit: %s', $e->getMessage())); - } - } - /** * @param int|null $budgetId * @param string|null $budgetName diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php index 5a6a0b7f6b..6487888765 100644 --- a/app/Repositories/Budget/BudgetRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetRepositoryInterface.php @@ -47,13 +47,6 @@ interface BudgetRepositoryInterface */ public function destroy(Budget $budget): bool; - /** - * Destroy a budget limit. - * - * @param BudgetLimit $budgetLimit - */ - public function destroyBudgetLimit(BudgetLimit $budgetLimit): void; - /** * @param int|null $budgetId * @param string|null $budgetName @@ -72,6 +65,8 @@ interface BudgetRepositoryInterface public function findByName(?string $name): ?Budget; /** + * TODO refactor to "find" + * * @param int|null $budgetId * * @return Budget|null