Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit 7907732

Browse files
committed
🍱 Ajout solution étape 7
1 parent 3664d0d commit 7907732

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package devoxx.lab.archihexa.courtage.application.springboot.adapters.rest;
2+
3+
import devoxx.lab.archihexa.courtage.domain.port.secondaire.ServiceBourse;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.stereotype.Service;
6+
import org.springframework.web.client.RestTemplate;
7+
8+
import java.math.BigDecimal;
9+
10+
import static java.util.Optional.ofNullable;
11+
12+
@Service
13+
public class ServiceBourseHttpAdapter implements ServiceBourse {
14+
15+
private final RestTemplate restTemplate;
16+
private final String bourseUri;
17+
18+
public ServiceBourseHttpAdapter(@Value("${application.bourse.baseUri}") String bourseUri) {
19+
this.bourseUri = bourseUri;
20+
this.restTemplate = new RestTemplate();
21+
}
22+
23+
@Override
24+
public BigDecimal recupererCours(String action) {
25+
return ofNullable(
26+
restTemplate
27+
.getForEntity(bourseUri + "/finance/quote/" + action, Quote.class)
28+
.getBody()
29+
)
30+
.map(Quote::getRegularMarketPriceAsBigDecimal)
31+
.orElseThrow();
32+
}
33+
34+
static class Quote {
35+
private String regularMarketPrice;
36+
37+
void setRegularMarketPrice(String regularMarketPrice) {
38+
this.regularMarketPrice = regularMarketPrice;
39+
}
40+
41+
BigDecimal getRegularMarketPriceAsBigDecimal() {
42+
return new BigDecimal(regularMarketPrice);
43+
}
44+
}
45+
}

courtage-application-springboot/src/main/java/devoxx/lab/archihexa/courtage/application/springboot/adapters/rest/ServiceBourseMock.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

courtage-application-springboot/src/main/java/devoxx/lab/archihexa/courtage/application/springboot/controller/CourtageResource.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.springframework.web.bind.annotation.*;
1212
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
1313

14-
import java.math.BigDecimal;
1514
import java.net.URI;
1615
import java.util.stream.Collectors;
1716

@@ -57,11 +56,12 @@ public ResponseEntity<String> ajoutActionsDansPortefeuille(
5756

5857
@GetMapping("/portefeuilles/{nomPortefeuille}/valorisation")
5958
public ResponseEntity<String> calculValorisationPortefeuille(@PathVariable(value = "nomPortefeuille") String nomPortefeuille) throws PortefeuilleNonGereException {
60-
if (!serviceCourtage.gere(nomPortefeuille)) {
61-
throw new PortefeuilleNonGereException();
62-
}
63-
return ResponseEntity.ok(BigDecimal.ZERO.toString());
59+
return ResponseEntity.ok(serviceCourtage.calculerValeurPortefeuille(nomPortefeuille).toString());
60+
}
6461

62+
@GetMapping("/portefeuilles/avoirs")
63+
public ResponseEntity<String> valeurEnsemblePortefeuilles() {
64+
return ResponseEntity.ok(serviceCourtage.calculerValeurEnsemblePortefeuilles().toString());
6565
}
6666

6767
@ExceptionHandler(MethodArgumentNotValidException.class)

0 commit comments

Comments
 (0)