Skip to content

Commit

Permalink
🐞Solución de errores y ⚙️Ajustes en la funcionalidad
Browse files Browse the repository at this point in the history
🐞Solución de errores
- Cambios en ApiUtil y Quote para un body correcto de Quote
- Cambios en Obj RestTemplate con un ObjMapper diferente para obtener un body correcto
⚙️Ajustes en la funcionalidad
- Cambios en test unitarios: DolarServiceTest, OtherCurrenciesServiceTest y QuoteServiceTest
- Cambios en test de integración: IntegrationControllerQuoteTest, IntegrationDollarControllerTest y IntegrationOtherCurrenciesControllerTest
- Se agregaron perfiles para la config de spring: prod- dev- test
- Pequeño cambio en los endpoints, se agregro "v1"
  • Loading branch information
Marc0Franc0 committed Oct 28, 2024
1 parent 52f9272 commit fd954ed
Show file tree
Hide file tree
Showing 24 changed files with 574 additions and 266 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ Para construir y ejecutar la aplicación necesita:
Ejecutar localmente

```shell
docker pull marc0franc0/exchange-rates-api:1.3.0
docker pull marc0franc0/exchange-rates-api:1.2.1
```
```shell
docker create -p8080:8080 --name app-exchange-rates marc0franc0/exchange-rates-api:1.3.0
docker create -p8080:8080 --name app-exchange-rates -e SPRING_PROFILES_ACTIVE=dev marc0franc0/exchange-rates-api:1.2.1
```
```shell
docker start app-exchange-rates
```

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)
- Documentación JSON: /api/v3/api-docs
- Documentación Swagger: /doc/swagger-ui/index.html

## Requerimientos para ejecutar con Maven

Expand All @@ -52,5 +52,5 @@ 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)
- Documentación JSON: /api/v3/api-docs
- Documentación Swagger /doc/swagger-ui/index.html
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<groupId>com.app</groupId>
<artifactId>ExchangeRatesApi</artifactId>
<name>ExchangeRatesApi</name>
<version>1.2.1</version>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>21</java.version>
Expand Down Expand Up @@ -52,6 +53,11 @@
<artifactId>junit-jupiter</artifactId>
<version>1.19.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@

import com.app.ExchangeRates.exception.ControllerAdvice;
import com.app.ExchangeRates.service.util.ApiUtil;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

@Configuration
public class ApiConfiguration {
@Bean
public ApiUtil apiUtil(){
return new ApiUtil();
RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
converter.setObjectMapper(objectMapper);
restTemplate.getMessageConverters().add(0, converter);
return restTemplate;
}
@Bean
public ControllerAdvice controllerAdvice(){
return new ControllerAdvice();
public ApiUtil apiUtil(){
return new ApiUtil(restTemplate());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.app.ExchangeRates.config.context;

import com.app.ExchangeRates.exception.ControllerAdvice;
import com.app.ExchangeRates.service.util.ApiUtil;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -14,12 +18,8 @@
@EnableWebMvc
public class AppContext {
@Bean
RestTemplate restTemplate(){
RestTemplate restTemplate = new RestTemplate();
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(new ObjectMapper());
restTemplate.getMessageConverters().add(converter);
return restTemplate;
public ControllerAdvice controllerAdvice(){
return new ControllerAdvice();
}
@Bean
public WebMvcConfigurer corsConfigurer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class OpenApiConfiguration {
@Bean
public OpenAPI customOpenAPI (
@Value("${openapi.service.title}") String serviceTitle,
@Value("${openapi.service.version}") String serviceVersion,
//@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));
.info( new Info().title(serviceTitle ));
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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;
Expand All @@ -16,13 +15,13 @@
import java.util.List;

@RestController
@RequestMapping("/api/exchanges/usd/")
@RequestMapping("/api/v1/exchanges/usd/")
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))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/official")
Expand All @@ -31,7 +30,7 @@ public class DolarController {
}
@Operation(summary = "Get Blue Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/blue")
Expand All @@ -40,7 +39,7 @@ ResponseEntity<Money> getBlueDollar(){
}
@Operation(summary = "Get CCL Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/ccl")
Expand All @@ -49,7 +48,7 @@ ResponseEntity<Money> getCCLDollar(){
}
@Operation(summary = "Get Card Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/card")
Expand All @@ -58,7 +57,7 @@ ResponseEntity<Money> getDollarCard(){
}
@Operation(summary = "Get StockMarket Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/stock-market")
Expand All @@ -78,7 +77,7 @@ ResponseEntity<Money> getSolidarityDollar(){
@Operation(summary = "Get Wholesale Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = MoneyDTO.class))),
schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/wholesale")
Expand All @@ -88,7 +87,7 @@ ResponseEntity<Money> getWholesaleDollar(){
@Operation(summary = "Get Wholesale Dollar", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = MoneyDTO.class))),
schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/cripto")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
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;
Expand All @@ -18,15 +15,15 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/exchanges/")
@RequestMapping("/api/v1/exchanges/")
public class OtherCurrenciesController {
@Autowired
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))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/euro")
Expand All @@ -35,7 +32,7 @@ ResponseEntity<Money> getEuro(){
}
@Operation(summary = "Get Brazilian Real", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/bzl")
Expand All @@ -44,7 +41,7 @@ ResponseEntity<Money> getBrazilianReal(){
}
@Operation(summary = "Get Chilean Peso", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/clp")
Expand All @@ -53,7 +50,7 @@ ResponseEntity<Money> getChileanPeso(){
}
@Operation(summary = "Get Uruguayan Peso", responses = {
@ApiResponse(description = "Successful Operation", responseCode = "200",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MoneyDTO.class))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Money.class))),
@ApiResponse(responseCode = "404", description = "Not found",
content = @Content)})
@GetMapping("/uyu")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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;
Expand All @@ -16,17 +15,17 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/exchanges/stock-price")
@RequestMapping("/api/v1/exchanges/stock-price")
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))),
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Quote.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));
}
}
}

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/com/app/ExchangeRates/model/DolarApi/MoneyDTO.java

This file was deleted.

13 changes: 9 additions & 4 deletions src/main/java/com/app/ExchangeRates/model/FinnHub/Quote.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@

@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Data
public class Quote {
@JsonProperty("c")
@JsonProperty("currencyPrice")
@JsonAlias("c")
private Double currencyPrice;
@JsonProperty("dp")

@JsonProperty("percentChange")
@JsonAlias("dp")
private Double percentChange;
@JsonProperty("o")
private Double openPriceOfTheDay;

@JsonProperty("openPriceOfTheDay")
@JsonAlias("o")
private Double openPriceOfTheDay;
/* {
"c": 191.24,
"d": 1.29,
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/app/ExchangeRates/model/FinnHub/QuoteDTO.java

This file was deleted.

Loading

0 comments on commit fd954ed

Please sign in to comment.