Skip to content

Commit

Permalink
Merge pull request #76 from aVolpe/fix/gnb_url
Browse files Browse the repository at this point in the history
fix: Updates url of gnb exchangeRates
  • Loading branch information
aVolpe authored Mar 4, 2024
2 parents 55dbce4 + 67d3488 commit 8f47f58
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 47 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
<version>1.17.2</version>
</dependency>

<dependency>
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/py/com/volpe/cotizacion/gatherer/GNB.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package py.com.volpe.cotizacion.gatherer;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.RequiredArgsConstructor;
Expand All @@ -14,6 +13,7 @@
import py.com.volpe.cotizacion.domain.QueryResponseDetail;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

Expand All @@ -34,25 +34,24 @@ public List<QueryResponse> doQuery(Place place, List<PlaceBranch> branches) {

QueryResponse toRet = new QueryResponse(place);

List<Root> parsed = getParsedData();
Root parsed = getParsedData();

for (Root info : parsed) {
for (Exchange info : parsed.getExchangeRates()) {
toRet.addDetail(new QueryResponseDetail(
info.getCashBuyPrice(),
info.getCashSellPrice(),
info.getCurrency().getCode()
info.getCashBuyPrice().longValue(),
info.getCashSellPrice().longValue(),
info.getCurrencyCode()
));
}

return Collections.singletonList(toRet);
}

protected List<Root> getParsedData() {
protected Root getParsedData() {
try {
String queryResult = helper.doGet(WS_URL);
return buildMapper()
.readValue(queryResult, new TypeReference<List<Root>>() {
});
.readValue(queryResult, Root.class);
} catch (IOException e) {
throw new AppException(500, "cant parse the result of GNB ws", e);
}
Expand All @@ -76,21 +75,22 @@ protected Long parseAmount(String amount) {

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Currency {
public String code;
public String description;
public static class Root {
private List<Exchange> exchangeRates;
}


@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Root {
public Currency currency;
public int electronicBuyPrice;
public int electronicSellPrice;
public int cashBuyPrice;
public int cashSellPrice;
public int checkBuyPrice;
public int checkSellPrice;
public static class Exchange {
public String currencyCode;
public String currencyDesc;
public BigDecimal electronicBuyPrice;
public BigDecimal electronicSellPrice;
public BigDecimal cashBuyPrice;
public BigDecimal cashSellPrice;
public BigDecimal checkBuyPrice;
public BigDecimal checkSellPrice;
}

}
8 changes: 4 additions & 4 deletions src/test/java/py/com/volpe/cotizacion/gatherer/GNBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ void doQuery() throws Exception {
QueryResponseDetail usd = qr.getDetails().stream().filter(q -> q.getIsoCode().equals("USD")).findFirst().orElse(null);
QueryResponseDetail eur = qr.getDetails().stream().filter(q -> q.getIsoCode().equals("EUR")).findFirst().orElse(null);

assertEquals(6730, usd.getPurchasePrice());
assertEquals(6950, usd.getSalePrice());
assertEquals(7220, usd.getPurchasePrice());
assertEquals(7380, usd.getSalePrice());

assertEquals(7400, eur.getPurchasePrice());
assertEquals(8100, eur.getSalePrice());
assertEquals(7570, eur.getPurchasePrice());
assertEquals(8310, eur.getSalePrice());


}
Expand Down
45 changes: 23 additions & 22 deletions src/test/resources/py/com/volpe/cotizacion/gatherer/gnb_data.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
[
{
"exchangeRates": [
{
"currency": {
"code": "USD",
"description": "DOLAR ESTADOUNIDENSE"
},
"electronicBuyPrice": 6785,
"electronicSellPrice": 6940,
"cashBuyPrice": 6730,
"cashSellPrice": 6950,
"checkBuyPrice": 6770,
"checkSellPrice": 6950
"currencyCode": "USD",
"electronicSellPrice": "7350.00",
"electronicBuyPrice": "7250.00",
"currencyDesc": "DOLAR AMERICANO",
"currencyAbbreviation": "DOLAR",
"cashBuyPrice": "7220.00",
"checkSellPrice": "",
"checkBuyPrice": "",
"cashSellPrice": "7380.00",
"order": 1
},
{
"currency": {
"code": "EUR",
"description": "EURO"
},
"electronicBuyPrice": 7510,
"electronicSellPrice": 7960,
"cashBuyPrice": 7400,
"cashSellPrice": 8100,
"checkBuyPrice": 7480,
"checkSellPrice": 8000
"currencyCode": "EUR",
"electronicSellPrice": "8160.00",
"electronicBuyPrice": "7720.00",
"currencyDesc": "EUR",
"currencyAbbreviation": "EUROS",
"cashBuyPrice": "7570.00",
"checkSellPrice": "",
"checkBuyPrice": "",
"cashSellPrice": "8310.00",
"order": 2
}
]
}

0 comments on commit 8f47f58

Please sign in to comment.