fix: Double to BigDecimal
This commit is contained in:
parent
b11607088a
commit
f42dcce74b
15 changed files with 93 additions and 57 deletions
|
@ -8,6 +8,7 @@ import org.springframework.http.HttpStatusCode;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Clock;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
|
@ -30,11 +31,11 @@ public class NbpService {
|
|||
|
||||
private final ConcurrentMap<String, RatesCache> cache = new ConcurrentHashMap<>(1);
|
||||
|
||||
public double getSellRate(String currency) {
|
||||
public BigDecimal getSellRate(String currency) {
|
||||
return getCurrency(currency.toUpperCase()).sell();
|
||||
}
|
||||
|
||||
public double getBuyRate(String currency) {
|
||||
public BigDecimal getBuyRate(String currency) {
|
||||
return getCurrency(currency.toUpperCase()).buy();
|
||||
}
|
||||
|
||||
|
@ -43,7 +44,7 @@ public class NbpService {
|
|||
var cacheObject = cache.get(currency);
|
||||
if (cacheObject == null || cacheObject.date().isBefore(today)) {
|
||||
var fresh = fetchData(currency, dtf.format(today));
|
||||
var rate = fresh.getRates().get(0);
|
||||
var rate = fresh.getRates().getFirst();
|
||||
cacheObject = new RatesCache(
|
||||
LocalDate.parse(rate.getEffectiveDate(), dtf),
|
||||
rate.getBid(),
|
||||
|
@ -82,7 +83,7 @@ public class NbpService {
|
|||
|| today.getDayOfWeek() == DayOfWeek.SUNDAY;
|
||||
}
|
||||
|
||||
private record RatesCache(LocalDate date, double buy, double sell) {
|
||||
private record RatesCache(LocalDate date, BigDecimal buy, BigDecimal sell) {
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue