Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
-Endpoint para conseguir todos los valores de dolares disponibles.
  • Loading branch information
Marc0Franc0 committed Mar 16, 2024
1 parent 0b49886 commit 52f9272
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
10 changes: 4 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.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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down Expand Up @@ -94,4 +95,14 @@ ResponseEntity<Money> getWholesaleDollar(){
ResponseEntity<Money> 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<List<Money>> getAllDollars(){
return ResponseEntity.status(HttpStatus.OK).body(dolarService.getAllDollars());
}
}
Original file line number Diff line number Diff line change
@@ -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())
Expand All @@ -13,4 +17,8 @@ public Money buildMoneyDto(Money money){
.money(money.getMoney())
.build();
}
public static List<Money> buildMoneyDto(Object body) {
List<Money> bodyList= objectMapper.convertValue(body, ArrayList.class);
return bodyList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -13,4 +14,5 @@ public interface DolarService {
Money getSolidarityDollar();
Money getWholesaleDollar();
Money getCryptoDollar();
List<Money> getAllDollars();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -77,4 +78,12 @@ public Money getCryptoDollar() {
.buildApiDolarDTO(
apiUtil.buildExchange(uri,HttpMethod.GET,new HttpEntity<>(null),Money.class));
}

@Override
public List<Money> getAllDollars() {
String uri = baseUrl+"/dolares";
return apiUtil
.buildListApiDolarDTO(
apiUtil.buildExchange(uri, HttpMethod.GET, new HttpEntity<>(null), List.class));
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/app/ExchangeRates/service/util/ApiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.List;
@Slf4j
public class ApiUtil {

Expand All @@ -30,6 +31,13 @@ public Money buildApiDolarDTO(ResponseEntity<?> response){
}
throw throwError(response);
}
public List<Money> 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){
Expand Down
Binary file modified target/ExchangeRatesApi-3.2.0.jar
Binary file not shown.

0 comments on commit 52f9272

Please sign in to comment.