-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Se implementaron clases para consumir una nueva api
- Loading branch information
1 parent
4abcab1
commit 4cbd6cd
Showing
10 changed files
with
131 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/app/ExchangeRates/controller/FinnHubApi/QuoteController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.app.ExchangeRates.controller.FinnHubApi; | ||
|
||
import com.app.ExchangeRates.model.FinnHub.Quote; | ||
import com.app.ExchangeRates.service.FinnHubApi.QuoteService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/exchanges/stock-price") | ||
public class QuoteController { | ||
@Autowired | ||
private QuoteService quoteService; | ||
@GetMapping("/{symbol}") | ||
ResponseEntity<Quote> getQuote(@PathVariable String symbol){ | ||
return ResponseEntity.status(HttpStatus.OK).body(quoteService.getQuote(symbol)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/app/ExchangeRates/mapper/FinnHubApi/QuoteMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.app.ExchangeRates.mapper.FinnHubApi; | ||
|
||
import com.app.ExchangeRates.model.FinnHub.Quote; | ||
import lombok.experimental.UtilityClass; | ||
|
||
@UtilityClass | ||
public class QuoteMapper { | ||
public Quote buildQuoteDto(Quote quote){ | ||
return Quote.builder() | ||
.openPriceOfTheDay(quote.getOpenPriceOfTheDay()) | ||
.percentChange(quote.getPercentChange()) | ||
.currentPrice(quote.getCurrentPrice()) | ||
.build(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/app/ExchangeRates/model/FinnHub/Quote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.app.ExchangeRates.model.FinnHub; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.*; | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Data | ||
public class Quote { | ||
@JsonProperty("c") | ||
private Double currentPrice; | ||
@JsonProperty("dp") | ||
private Double percentChange; | ||
@JsonProperty("o") | ||
private Double openPriceOfTheDay; | ||
|
||
/* { | ||
"c": 191.24, | ||
"d": 1.29, | ||
"dp": 0.6791, | ||
"h": 191.555, | ||
"l": 189.23, | ||
"o": 190.33, | ||
"pc": 189.95, | ||
"t": 1701464401 | ||
}*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/app/ExchangeRates/service/FinnHubApi/QuoteService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.app.ExchangeRates.service.FinnHubApi; | ||
|
||
import com.app.ExchangeRates.model.FinnHub.Quote; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public interface QuoteService { | ||
Quote getQuote(String symbol); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/app/ExchangeRates/service/FinnHubApi/QuoteServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.app.ExchangeRates.service.FinnHubApi; | ||
|
||
import com.app.ExchangeRates.model.FinnHub.Quote; | ||
import com.app.ExchangeRates.service.util.ApiUtil; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
@Service | ||
public class QuoteServiceImpl implements QuoteService { | ||
@Autowired | ||
private ApiUtil apiUtil; | ||
@Value("${finnhub.base-url}") | ||
String baseUrl; | ||
@Value("${finnhub.token}") | ||
String token; | ||
@Override | ||
public Quote getQuote(String symbol) { | ||
String uri = baseUrl+"/quote?symbol="+symbol+"&token="+token; | ||
return apiUtil.buildQuoteDTO(apiUtil.getForEntity(uri,Quote.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
apidolar.base-url= https://dolarapi.com/v1 | ||
finnhub.base-url=https://finnhub.io/api/v1 | ||
finnhub.token=cljvmhhr01ql1cbg8bf0cljvmhhr01ql1cbg8bfg | ||
|