Move method to correct repository.

This commit is contained in:
James Cole 2019-08-30 07:49:08 +02:00
parent 4cdbea2737
commit e525960320
5 changed files with 34 additions and 22 deletions

View File

@ -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);
}

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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

View File

@ -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