Introduce missing methods

This commit is contained in:
James Cole
2023-10-28 14:59:16 +02:00
parent 1d138eed8d
commit fa920fed4e
15 changed files with 79 additions and 42 deletions

View File

@@ -38,7 +38,8 @@ use FireflyIII\Models\RuleAction;
use FireflyIII\Models\RuleTrigger;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepository;
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
use FireflyIII\Services\Internal\Destroy\BudgetDestroyService;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
@@ -429,6 +430,7 @@ class BudgetRepository implements BudgetRepositoryInterface
// set or update the currency.
if (array_key_exists('currency_id', $data) || array_key_exists('currency_code', $data)) {
/** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class);
$currencyId = (int)($data['currency_id'] ?? 0);
$currencyCode = (string)($data['currency_code'] ?? '');
@@ -837,6 +839,7 @@ class BudgetRepository implements BudgetRepositoryInterface
$type = AutoBudget::AUTO_BUDGET_ADJUSTED;
}
/** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class);
$currency = null;
if (array_key_exists('currency_id', $data)) {

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Currency;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\User;

View File

@@ -173,6 +173,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
/**
* Get the user group's currencies.
*
* @return Collection
*/
public function get(): Collection
@@ -291,7 +292,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
*
* @return TransactionCurrency|null
*/
private function findByCode(string $currencyCode): ?TransactionCurrency
public function findByCode(string $currencyCode): ?TransactionCurrency
{
return TransactionCurrency::where('code', $currencyCode)->first();
}
@@ -307,6 +308,16 @@ class CurrencyRepository implements CurrencyRepositoryInterface
$currency->save();
}
/**
* @param array $ids
*
* @return Collection
*/
public function getByIds(array $ids): Collection
{
return TransactionCurrency::orderBy('code', 'ASC')->whereIn('id', $ids)->get();
}
/**
* @inheritDoc
*/

View File

@@ -55,6 +55,13 @@ interface CurrencyRepositoryInterface
*/
public function find(int $currencyId): ?TransactionCurrency;
/**
* @param string $currencyCode
*
* @return TransactionCurrency|null
*/
public function findByCode(string $currencyCode): ?TransactionCurrency;
/**
* Find by object, ID or code. Returns user default or system default.
*
@@ -89,6 +96,13 @@ interface CurrencyRepositoryInterface
*/
public function getAll(): Collection;
/**
* @param array $ids
*
* @return Collection
*/
public function getByIds(array $ids): Collection;
/**
* @param TransactionCurrency $currency
*