diff --git a/README.md b/README.md index a6e206f..ab1c7f0 100644 --- a/README.md +++ b/README.md @@ -22,18 +22,18 @@ Para construir y ejecutar la aplicación necesita: Ejecutar localmente ```shell -docker pull marc0franc0/exchange-rates-api:1.0.0 +docker pull marc0franc0/exchange-rates-api:1.3.0 ``` ```shell -docker create -p9090:8080 --name app-exchange-rates marc0franc0/exchange-rates-api:1.0.0 +docker create -p8080:8080 --name app-exchange-rates marc0franc0/exchange-rates-api:1.3.0 ``` ```shell docker start app-exchange-rates ``` Dirigirse a: -- [Documentación en formato JSON](http://localhost:9090/api/v3/api-docs) -- [Documentación Swagger con interfaz gráfica](http://localhost:9090/doc/swagger-ui/index.html) +- [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) ## Requerimientos para ejecutar con Maven @@ -42,8 +42,6 @@ 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 diff --git a/src/main/java/com/app/ExchangeRates/controller/ApiDolar/DolarController.java b/src/main/java/com/app/ExchangeRates/controller/ApiDolar/DolarController.java index f6e57dd..3406f8f 100644 --- a/src/main/java/com/app/ExchangeRates/controller/ApiDolar/DolarController.java +++ b/src/main/java/com/app/ExchangeRates/controller/ApiDolar/DolarController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; @RestController @RequestMapping("/api/exchanges/usd/") @@ -94,4 +95,14 @@ ResponseEntity getWholesaleDollar(){ ResponseEntity getCryptoollar(){ return ResponseEntity.status(HttpStatus.OK).body(dolarService.getCryptoDollar()); } + @Operation(summary = "Get all dollars", responses = { + @ApiResponse(description = "Successful Operation", responseCode = "200", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Money.class))), + @ApiResponse(responseCode = "404", description = "Not found", + content = @Content)}) + @GetMapping("/") + ResponseEntity> getAllDollars(){ + return ResponseEntity.status(HttpStatus.OK).body(dolarService.getAllDollars()); + } } \ No newline at end of file diff --git a/src/main/java/com/app/ExchangeRates/mapper/DolarApi/MoneyMapper.java b/src/main/java/com/app/ExchangeRates/mapper/DolarApi/MoneyMapper.java index 0750d1b..38ec281 100644 --- a/src/main/java/com/app/ExchangeRates/mapper/DolarApi/MoneyMapper.java +++ b/src/main/java/com/app/ExchangeRates/mapper/DolarApi/MoneyMapper.java @@ -1,10 +1,14 @@ package com.app.ExchangeRates.mapper.DolarApi; import com.app.ExchangeRates.model.DolarApi.Money; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.experimental.UtilityClass; +import java.util.ArrayList; +import java.util.List; @UtilityClass public class MoneyMapper { + private final ObjectMapper objectMapper = new ObjectMapper(); public Money buildMoneyDto(Money money){ return Money.builder() .name(money.getName()) @@ -13,4 +17,8 @@ public Money buildMoneyDto(Money money){ .money(money.getMoney()) .build(); } + public static List buildMoneyDto(Object body) { + List bodyList= objectMapper.convertValue(body, ArrayList.class); + return bodyList; + } } diff --git a/src/main/java/com/app/ExchangeRates/service/DolarApi/DolarService.java b/src/main/java/com/app/ExchangeRates/service/DolarApi/DolarService.java index 4592d44..5236ec3 100644 --- a/src/main/java/com/app/ExchangeRates/service/DolarApi/DolarService.java +++ b/src/main/java/com/app/ExchangeRates/service/DolarApi/DolarService.java @@ -3,6 +3,7 @@ import com.app.ExchangeRates.model.DolarApi.Money; import org.springframework.stereotype.Service; +import java.util.List; @Service public interface DolarService { Money getOfficialDollar(); @@ -13,4 +14,5 @@ public interface DolarService { Money getSolidarityDollar(); Money getWholesaleDollar(); Money getCryptoDollar(); + List getAllDollars(); } diff --git a/src/main/java/com/app/ExchangeRates/service/DolarApi/DolarServiceImpl.java b/src/main/java/com/app/ExchangeRates/service/DolarApi/DolarServiceImpl.java index fc3f0b9..4ce2966 100644 --- a/src/main/java/com/app/ExchangeRates/service/DolarApi/DolarServiceImpl.java +++ b/src/main/java/com/app/ExchangeRates/service/DolarApi/DolarServiceImpl.java @@ -7,6 +7,7 @@ import org.springframework.http.*; import org.springframework.stereotype.Service; +import java.util.List; @Service public class DolarServiceImpl implements DolarService { @Value("${apidolar.base-url}") @@ -77,4 +78,12 @@ public Money getCryptoDollar() { .buildApiDolarDTO( apiUtil.buildExchange(uri,HttpMethod.GET,new HttpEntity<>(null),Money.class)); } + + @Override + public List getAllDollars() { + String uri = baseUrl+"/dolares"; + return apiUtil + .buildListApiDolarDTO( + apiUtil.buildExchange(uri, HttpMethod.GET, new HttpEntity<>(null), List.class)); + } } diff --git a/src/main/java/com/app/ExchangeRates/service/util/ApiUtil.java b/src/main/java/com/app/ExchangeRates/service/util/ApiUtil.java index fd0be88..3ce6714 100644 --- a/src/main/java/com/app/ExchangeRates/service/util/ApiUtil.java +++ b/src/main/java/com/app/ExchangeRates/service/util/ApiUtil.java @@ -11,6 +11,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; +import java.util.List; @Slf4j public class ApiUtil { @@ -30,6 +31,13 @@ public Money buildApiDolarDTO(ResponseEntity response){ } throw throwError(response); } + public List buildListApiDolarDTO(ResponseEntity response){ + if(response.getStatusCode().value()==200){ + log.info("Request to external api correct: {}", response.getStatusCode()); + return MoneyMapper.buildMoneyDto(response.getBody()); + } + throw throwError(response); + } //se encarga de crear una consulta externa public ResponseEntity buildExchange(String uri, HttpMethod httpMethod, HttpEntity httpEntity, Class returnType){ diff --git a/target/ExchangeRatesApi-3.2.0.jar b/target/ExchangeRatesApi-3.2.0.jar index 73115ff..3e9ae70 100644 Binary files a/target/ExchangeRatesApi-3.2.0.jar and b/target/ExchangeRatesApi-3.2.0.jar differ