Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
-Documentación de la api utilizando SpringDoc
-Creación de README
  • Loading branch information
Marc0Franc0 committed Dec 15, 2023
1 parent 4cbd6cd commit 34bce50
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 10 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# [ExchangesRatesApi](https://github.com/Marc0Franc0/ExchangesRatesApi#exchangesratesapi)

El proyecto tiene la posibilidad de consumir diferentes APIS con el objetivo de obtener los tipos de cambios en argentina y precios del mercado en dólares.

## Características
- Consumo de APIS externas

## Tecnologías
- Spring Boot 3.0
- Maven

## Ejecución
1. Clonar repositorio: git clone https://github.com/Marc0Franc0/ExchangesRatesApi
2. Ir al directorio del proyecto: cd ExchangesRatesApi
3. Seguir pasos para ejecución con Maven

## Requerimientos para ejecutar con Maven

Para construir y ejecutar la aplicación necesita:

- [JDK 21+](https://www.oracle.com/java/technologies/downloads/#java21)
- [Maven 3+](https://maven.apache.org)

Configurar datos de la base de datos MySQL: [application.properties](https://github.com/Marc0Franc0/Forum/blob/main/src/main/resources/application-dev.properties)

Ejecutar localmente

```shell
mvn clean install
```
```shell
mvn spring-boot:run
```

Dirigirse a:
- [Documentación en formato JSON](http://localhost:8080/api/v3/api-docs)
- [Documentación Swagger con interfaz gráfica](http://localhost:8080/doc/swagger-ui/index.html)
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.app</groupId>
<artifactId>ExchangeRates</artifactId>
<artifactId>ExchangeRatesApi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ExchangeRates</name>
<description>Demo project for Spring Boot</description>
Expand Down Expand Up @@ -43,6 +43,11 @@
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.app.ExchangeRates.config.documentation;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.function.RouterFunction;
import java.util.List;
import static org.springdoc.webmvc.core.fn.SpringdocRouteBuilder.route;

@OpenAPIDefinition
@Configuration
public class OpenApiConfiguration {
@Bean
public OpenAPI customOpenAPI (
@Value("${openapi.service.title}") String serviceTitle,
@Value("${openapi.service.version}") String serviceVersion,
@Value ("${openapi.service.url}") String url) {
return new OpenAPI ()
.servers(List.of( new Server().url(url)))
.info( new Info().title(serviceTitle ).version(serviceVersion));
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.app.ExchangeRates.controller.ApiDolar;

import com.app.ExchangeRates.model.DolarApi.Money;
import com.app.ExchangeRates.model.DolarApi.MoneyDTO;
import com.app.ExchangeRates.service.DolarApi.DolarService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -14,30 +19,66 @@
public class DolarController {
@Autowired
private DolarService dolarService;
@Operation(summary = "Get Official Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/official")
ResponseEntity<Money>getOfficialDollar(){
return ResponseEntity.status(HttpStatus.OK).body(dolarService.getOfficialDollar());
}
@Operation(summary = "Get Blue Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/blue")
ResponseEntity<Money> getBlueDollar(){
return ResponseEntity.status(HttpStatus.OK).body(dolarService.getBlueDollar());
}
@Operation(summary = "Get CCL Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/ccl")
ResponseEntity<Money> getCCLDollar(){
return ResponseEntity.status(HttpStatus.OK).body(dolarService.getCCLDollar());
}
@Operation(summary = "Get Card Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/card")
ResponseEntity<Money> getDollarCard(){
return ResponseEntity.status(HttpStatus.OK).body(dolarService.getDollarCard());
}
@Operation(summary = "Get StockMarket Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/stock-market")
ResponseEntity<Money> getStockMarketDollar(){
return ResponseEntity.status(HttpStatus.OK).body(dolarService.getStockMarketDollar());
}
@Operation(summary = "Get Solidarity Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/solidarity")
ResponseEntity<Money> getSolidarityDollar(){
return ResponseEntity.status(HttpStatus.OK).body(dolarService.getSolidarityDollar());
}
@Operation(summary = "Get Wholesale Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/wholesale")
ResponseEntity<Money> getWholesaleDollar(){
return ResponseEntity.status(HttpStatus.OK).body(dolarService.getWholesaleDollar());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.app.ExchangeRates.controller.ApiDolar;

import com.app.ExchangeRates.model.DolarApi.Money;
import com.app.ExchangeRates.model.DolarApi.MoneyDTO;
import com.app.ExchangeRates.model.FinnHub.Quote;
import com.app.ExchangeRates.service.DolarApi.DolarService;
import com.app.ExchangeRates.service.DolarApi.OtherCurrenciesService;
import com.app.ExchangeRates.service.FinnHubApi.QuoteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -19,18 +24,38 @@ public class OtherCurrenciesController {
private OtherCurrenciesService otherCurrenciesService;
@Autowired
private QuoteService quoteService;
@Operation(summary = "Get Euro", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/euro")
ResponseEntity<Money> getEuro(){
return ResponseEntity.status(HttpStatus.OK).body(otherCurrenciesService.getEuro());
}
@Operation(summary = "Get Brazilian Real", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/bzl")
ResponseEntity<Money> getBrazilianReal(){
return ResponseEntity.status(HttpStatus.OK).body(otherCurrenciesService.getBrazilianReal());
}
@Operation(summary = "Get Chilean Peso", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/clp")
ResponseEntity<Money> getChileanPeso(){
return ResponseEntity.status(HttpStatus.OK).body(otherCurrenciesService.getChileanPeso());
}
@Operation(summary = "Get Uruguayan Peso", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/uyu")
ResponseEntity<Money> getUruguayanPeso(){
return ResponseEntity.status(HttpStatus.OK).body(otherCurrenciesService.getUruguayanPeso());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.app.ExchangeRates.controller.FinnHubApi;

import com.app.ExchangeRates.model.FinnHub.Quote;
import com.app.ExchangeRates.model.FinnHub.QuoteDTO;
import com.app.ExchangeRates.service.FinnHubApi.QuoteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -15,6 +20,11 @@
public class QuoteController {
@Autowired
private QuoteService quoteService;
@Operation(summary = "Get prices from the foreign market at the dollar price", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = QuoteDTO.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/{symbol}")
ResponseEntity<Quote> getQuote(@PathVariable String symbol){
return ResponseEntity.status(HttpStatus.OK).body(quoteService.getQuote(symbol));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public Quote buildQuoteDto(Quote quote){
return Quote.builder()
.openPriceOfTheDay(quote.getOpenPriceOfTheDay())
.percentChange(quote.getPercentChange())
.currentPrice(quote.getCurrentPrice())
.currencyPrice(quote.getCurrencyPrice())
.build();
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/app/ExchangeRates/model/DolarApi/MoneyDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.app.ExchangeRates.model.DolarApi;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class MoneyDTO {
String money;
String name;
Double buyValue;
Double saleValue;
}
7 changes: 3 additions & 4 deletions src/main/java/com/app/ExchangeRates/model/FinnHub/Quote.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.app.ExchangeRates.model.FinnHub;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.*;
import lombok.*;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Quote {
@JsonProperty("c")
private Double currentPrice;
private Double currencyPrice;
@JsonProperty("dp")
private Double percentChange;
@JsonProperty("o")
private Double openPriceOfTheDay;

/* {
/* {
"c": 191.24,
"d": 1.29,
"dp": 0.6791,
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/app/ExchangeRates/model/FinnHub/QuoteDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.app.ExchangeRates.model.FinnHub;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class QuoteDTO {
private Double currencyPrice;
private Double percentChange;
private Double openPriceOfTheDay;

}
4 changes: 0 additions & 4 deletions src/main/resources/application.properties

This file was deleted.

17 changes: 17 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiDolar:
baseUrl: https://dolarapi.com/v1
finnHub:
baseUrl: https://finnhub.io/api/v1
token: cljvmhhr01ql1cbg8bf0cljvmhhr01ql1cbg8bfg
openapi:
service:
title: ExchangeRatesApi doc #title
version: 1.0.0
url: http://localhost:8080
springDoc:
apiDocs:
enabled: true
path: /api/v3/api-docs
swaggerUi:
enabled: true
path: /doc/swagger-ui.html

0 comments on commit 34bce50

Please sign in to comment.