Implement currency exchange rate API.

This commit is contained in:
James Cole
2018-06-28 07:32:58 +02:00
parent cfd98a33fe
commit f55d4e32c0
12 changed files with 255 additions and 17 deletions

View File

@@ -265,13 +265,15 @@ class CurrencyRepository implements CurrencyRepositoryInterface
}
/**
* Get currency exchange rate.
*
* @param TransactionCurrency $fromCurrency
* @param TransactionCurrency $toCurrency
* @param Carbon $date
*
* @return CurrencyExchangeRate
* @return CurrencyExchangeRate|null
*/
public function getExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date): CurrencyExchangeRate
public function getExchangeRate(TransactionCurrency $fromCurrency, TransactionCurrency $toCurrency, Carbon $date): ?CurrencyExchangeRate
{
if ($fromCurrency->id === $toCurrency->id) {
$rate = new CurrencyExchangeRate;
@@ -280,7 +282,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return $rate;
}
/** @var CurrencyExchangeRate $rate */
$rate = $this->user->currencyExchangeRates()
->where('from_currency_id', $fromCurrency->id)
->where('to_currency_id', $toCurrency->id)
@@ -291,7 +293,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return $rate;
}
return new CurrencyExchangeRate;
return null;
}
/**