This repository was archived by the owner on Mar 4, 2023. It is now read-only.
File tree 3 files changed +50
-26
lines changed
courtage-application-springboot/src/main/java/devoxx/lab/archihexa/courtage/application/springboot 3 files changed +50
-26
lines changed Original file line number Diff line number Diff line change
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
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11
11
import org .springframework .web .bind .annotation .*;
12
12
import org .springframework .web .servlet .support .ServletUriComponentsBuilder ;
13
13
14
- import java .math .BigDecimal ;
15
14
import java .net .URI ;
16
15
import java .util .stream .Collectors ;
17
16
@@ -57,11 +56,12 @@ public ResponseEntity<String> ajoutActionsDansPortefeuille(
57
56
58
57
@ GetMapping ("/portefeuilles/{nomPortefeuille}/valorisation" )
59
58
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
+ }
64
61
62
+ @ GetMapping ("/portefeuilles/avoirs" )
63
+ public ResponseEntity <String > valeurEnsemblePortefeuilles () {
64
+ return ResponseEntity .ok (serviceCourtage .calculerValeurEnsemblePortefeuilles ().toString ());
65
65
}
66
66
67
67
@ ExceptionHandler (MethodArgumentNotValidException .class )
You can’t perform that action at this time.
0 commit comments