mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-26 00:41:34 -06:00
Remove use of deprecated function.
This commit is contained in:
parent
30d7d5d90e
commit
fb0d31226a
@ -232,31 +232,6 @@ class BudgetController extends Controller
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param BudgetLimitRequest $request
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @throws Exception
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function storeBudgetLimit(BudgetLimitRequest $request, Budget $budget): JsonResponse
|
||||
{
|
||||
$data = $request->getAll();
|
||||
$data['budget'] = $budget;
|
||||
$budgetLimit = $this->blRepository->storeBudgetLimit($data);
|
||||
$manager = $this->getManager();
|
||||
|
||||
/** @var BudgetLimitTransformer $transformer */
|
||||
$transformer = app(BudgetLimitTransformer::class);
|
||||
$transformer->setParameters($this->parameters);
|
||||
|
||||
$resource = new Item($budgetLimit, $transformer, 'budget_limits');
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all transactions.
|
||||
*
|
||||
|
@ -158,21 +158,20 @@ class BudgetLimitController extends Controller
|
||||
*
|
||||
* @param BudgetLimitRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(BudgetLimitRequest $request): JsonResponse
|
||||
{
|
||||
$data = $request->getAll();
|
||||
$budget = $this->repository->findNull($data['budget_id']);
|
||||
if (null === $budget) {
|
||||
throw new FireflyException('200004: Budget does not exist.'); // @codeCoverageIgnore
|
||||
}
|
||||
$data['budget'] = $budget;
|
||||
$budgetLimit = $this->blRepository->storeBudgetLimit($data);
|
||||
$data['start_date'] = $data['start'];
|
||||
$data['end_date'] = $data['end'];
|
||||
|
||||
$budgetLimit = $this->blRepository->store($data);
|
||||
$manager = $this->getManager();
|
||||
|
||||
|
||||
/** @var BudgetLimitTransformer $transformer */
|
||||
$transformer = app(BudgetLimitTransformer::class);
|
||||
$transformer->setParameters($this->parameters);
|
||||
|
@ -35,6 +35,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
class BudgetLimitRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
|
||||
/**
|
||||
* Authorize logged in users.
|
||||
*
|
||||
@ -53,7 +54,7 @@ class BudgetLimitRequest extends FormRequest
|
||||
*/
|
||||
public function getAll(): array
|
||||
{
|
||||
return [
|
||||
$data = [
|
||||
'budget_id' => $this->integer('budget_id'),
|
||||
'start' => $this->date('start'),
|
||||
'end' => $this->date('end'),
|
||||
@ -61,6 +62,12 @@ class BudgetLimitRequest extends FormRequest
|
||||
'currency_id' => $this->integer('currency_id'),
|
||||
'currency_code' => $this->string('currency_code'),
|
||||
];
|
||||
// if request has a budget already, drop the rule.
|
||||
$budget = $this->route()->parameter('budget');
|
||||
if (null !== $budget) {
|
||||
$data['budget_id'] = $budget->id;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,6 +26,7 @@ namespace FireflyIII\Repositories\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
@ -284,23 +285,10 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
* @param array $data
|
||||
*
|
||||
* @return BudgetLimit
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(array $data): BudgetLimit
|
||||
{
|
||||
return BudgetLimit::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return BudgetLimit
|
||||
* @deprecated
|
||||
*/
|
||||
public function storeBudgetLimit(array $data): BudgetLimit
|
||||
{
|
||||
/** @var Budget $budget */
|
||||
$budget = $data['budget'];
|
||||
|
||||
// if no currency has been provided, use the user's default currency:
|
||||
/** @var TransactionCurrencyFactory $factory */
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
@ -308,16 +296,23 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUser($this->user);
|
||||
}
|
||||
$currency->enabled = true;
|
||||
$currency->save();
|
||||
|
||||
// find limit with same date range.
|
||||
// if it exists, return that one.
|
||||
// find the budget:
|
||||
$budget = $this->user->budgets()->find((int) $data['budget_id']);
|
||||
if (null === $budget) {
|
||||
throw new FireflyException('200004: Budget does not exist.'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// find limit with same date range and currency.
|
||||
$limit = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $data['start']->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $data['end']->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.transaction_currency_id', $currency->id)
|
||||
->get(['budget_limits.*'])->first();
|
||||
if (null !== $limit) {
|
||||
return $limit;
|
||||
throw new FireflyException('200027: Budget limit already exists.'); // @codeCoverageIgnore
|
||||
}
|
||||
Log::debug('No existing budget limit, create a new one');
|
||||
|
||||
|
@ -111,14 +111,6 @@ interface BudgetLimitRepositoryInterface
|
||||
*/
|
||||
public function store(array $data): BudgetLimit;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return BudgetLimit
|
||||
* @deprecated
|
||||
*/
|
||||
public function storeBudgetLimit(array $data): BudgetLimit;
|
||||
|
||||
/**
|
||||
* @param BudgetLimit $budgetLimit
|
||||
* @param array $data
|
||||
|
@ -167,7 +167,7 @@ Route::group(
|
||||
Route::get('{budget}', ['uses' => 'BudgetController@show', 'as' => 'show']);
|
||||
Route::put('{budget}', ['uses' => 'BudgetController@update', 'as' => 'update']);
|
||||
Route::delete('{budget}', ['uses' => 'BudgetController@delete', 'as' => 'delete']);
|
||||
Route::post('{budget}/limits', ['uses' => 'BudgetController@storeBudgetLimit', 'as' => 'store_budget_limit']);
|
||||
Route::post('{budget}/limits', ['uses' => 'BudgetLimitController@store', 'as' => 'store_budget_limit']);
|
||||
|
||||
Route::get('{budget}/transactions', ['uses' => 'BudgetController@transactions', 'as' => 'transactions']);
|
||||
Route::get('{budget}/attachments', ['uses' => 'BudgetController@attachments', 'as' => 'attachments']);
|
||||
|
Loading…
Reference in New Issue
Block a user