Expand API with v2 summary endpoint.

This commit is contained in:
James Cole
2023-08-06 07:04:09 +02:00
parent 46412bdc66
commit ffd8aef35f
14 changed files with 1073 additions and 7 deletions

View File

@@ -148,8 +148,13 @@ trait ConvertsExchangeRates
$cache = new CacheProperties();
$cache->addProperty($key);
if ($cache->has()) {
return $cache->get();
$rate = $cache->get();
if ('' === $rate) {
return null;
}
return $rate;
}
app('log')->debug(sprintf('Going to get rate #%d->#%d (%s) from DB.', $from, $to, $date));
/** @var CurrencyExchangeRate $result */
$result = auth()->user()
@@ -159,12 +164,12 @@ trait ConvertsExchangeRates
->where('date', '<=', $date)
->orderBy('date', 'DESC')
->first();
if (null !== $result) {
$rate = (string)$result->rate;
$cache->store($rate);
return $rate;
$rate = (string)$result?->rate;
$cache->store($rate);
if ('' === $rate) {
return null;
}
return null;
return $rate;
}
/**

View File

@@ -34,6 +34,21 @@ class ExchangeRateConverter
{
use ConvertsExchangeRates;
/**
* @param TransactionCurrency $from
* @param TransactionCurrency $to
* @param Carbon $date
* @param string $amount
*
* @return string
* @throws FireflyException
*/
public function convert(TransactionCurrency $from, TransactionCurrency $to, Carbon $date, string $amount): string
{
$rate = $this->getCurrencyRate($from, $to, $date);
return bcmul($amount, $rate);
}
/**
* @param TransactionCurrency $from
* @param TransactionCurrency $to