mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-09 11:18:10 +00:00
Expand currency endpoint.
This commit is contained in:
@@ -92,6 +92,7 @@ class CurrencyExchangeRateController extends Controller
|
|||||||
$this->parameters->set('from', $fromCurrency->code);
|
$this->parameters->set('from', $fromCurrency->code);
|
||||||
$this->parameters->set('to', $toCurrency->code);
|
$this->parameters->set('to', $toCurrency->code);
|
||||||
$this->parameters->set('date', $dateObj->format('Y-m-d'));
|
$this->parameters->set('date', $dateObj->format('Y-m-d'));
|
||||||
|
$this->parameters->set('amount', $request->get('amount'));
|
||||||
|
|
||||||
$rate = $this->repository->getExchangeRate($fromCurrency, $toCurrency, $dateObj);
|
$rate = $this->repository->getExchangeRate($fromCurrency, $toCurrency, $dateObj);
|
||||||
if (null === $rate) {
|
if (null === $rate) {
|
||||||
|
|||||||
@@ -55,12 +55,25 @@ class CurrencyExchangeRateTransformer extends TransformerAbstract
|
|||||||
*/
|
*/
|
||||||
public function transform(CurrencyExchangeRate $rate): array
|
public function transform(CurrencyExchangeRate $rate): array
|
||||||
{
|
{
|
||||||
|
$result = round((float)$rate->rate * (float)$this->parameters->get('amount'), $rate->toCurrency->decimal_places);
|
||||||
|
$result = 0.0 === $result ? null : $result;
|
||||||
$data = [
|
$data = [
|
||||||
'id' => (int)$rate->id,
|
'id' => (int)$rate->id,
|
||||||
'updated_at' => $rate->updated_at->toAtomString(),
|
'updated_at' => $rate->updated_at->toAtomString(),
|
||||||
'created_at' => $rate->created_at->toAtomString(),
|
'created_at' => $rate->created_at->toAtomString(),
|
||||||
|
'from_currency_id' => $rate->fromCurrency->id,
|
||||||
|
'from_currency_name' => $rate->fromCurrency->name,
|
||||||
|
'from_currency_code' => $rate->fromCurrency->code,
|
||||||
|
'from_currency_symbol' => $rate->fromCurrency->symbol,
|
||||||
|
'from_currency_dp' => $rate->fromCurrency->decimal_places,
|
||||||
|
'to_currency_id' => $rate->toCurrency->id,
|
||||||
|
'to_currency_name' => $rate->toCurrency->name,
|
||||||
|
'to_currency_code' => $rate->toCurrency->code,
|
||||||
|
'to_currency_symbol' => $rate->toCurrency->symbol,
|
||||||
|
'to_currency_dp' => $rate->toCurrency->decimal_places,
|
||||||
'date' => $rate->date->format('Y-m-d'),
|
'date' => $rate->date->format('Y-m-d'),
|
||||||
'rate' => (float)$rate->rate,
|
'rate' => (float)$rate->rate,
|
||||||
|
'amount' => $result,
|
||||||
'links' => [
|
'links' => [
|
||||||
[
|
[
|
||||||
'rel' => 'self',
|
'rel' => 'self',
|
||||||
|
|||||||
Reference in New Issue
Block a user