Match exchange rate API with API docs.

This commit is contained in:
James Cole
2025-08-15 11:28:23 +02:00
parent 1305fafd38
commit 9b2263c7bb
11 changed files with 216 additions and 42 deletions

View File

@@ -55,20 +55,17 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface, UserGro
// orderBy('date', 'DESC')->toRawSql();
return
$this->userGroup->currencyExchangeRates()
->where(function (Builder $q1) use ($from, $to): void {
$q1->where(function (Builder $q) use ($from, $to): void {
$q->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id)
;
})->orWhere(function (Builder $q) use ($from, $to): void {
$q->where('from_currency_id', $to->id)
->where('to_currency_id', $from->id)
;
});
})
->orderBy('date', 'DESC')
->get(['currency_exchange_rates.*'])
;
->where(function (Builder $q1) use ($from, $to): void {
$q1->where(function (Builder $q) use ($from, $to): void {
$q->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id);
})->orWhere(function (Builder $q) use ($from, $to): void {
$q->where('from_currency_id', $to->id)
->where('to_currency_id', $from->id);
});
})
->orderBy('date', 'DESC')
->get(['currency_exchange_rates.*']);
}
@@ -78,11 +75,10 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface, UserGro
/** @var null|CurrencyExchangeRate */
return
$this->userGroup->currencyExchangeRates()
->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id)
->where('date', $date->format('Y-m-d'))
->first()
;
->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id)
->where('date', $date->format('Y-m-d'))
->first();
}
#[Override]
@@ -112,4 +108,12 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface, UserGro
return $object;
}
public function deleteRates(TransactionCurrency $from, TransactionCurrency $to): void
{
$this->userGroup->currencyExchangeRates()
->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id)
->delete();
}
}

View File

@@ -46,6 +46,7 @@ use Illuminate\Support\Collection;
interface ExchangeRateRepositoryInterface
{
public function deleteRate(CurrencyExchangeRate $rate): void;
public function deleteRates(TransactionCurrency $from, TransactionCurrency $to): void;
public function getAll(): Collection;