fix: Double to BigDecimal

This commit is contained in:
Piotr Dec 2024-06-10 23:52:47 +02:00
parent b11607088a
commit f42dcce74b
Signed by: stawros
GPG key ID: F89F27AD8F881A91
15 changed files with 93 additions and 57 deletions

View file

@ -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) {
}