Skip to content

Commit 8a49ad9

Browse files
committed
refactored model
rate and table models refactored (extensions)
1 parent cc973c1 commit 8a49ad9

File tree

11 files changed

+172
-118
lines changed

11 files changed

+172
-118
lines changed

src/main/java/pl/pawelosinski/dynatrace/nbp/task/backend/controller/CurrencyController.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import org.springframework.web.bind.annotation.RequestParam;
88
import org.springframework.web.bind.annotation.RestController;
99
import org.springframework.web.client.HttpClientErrorException;
10-
import pl.pawelosinski.dynatrace.nbp.task.backend.model.CurrencyRateTable;
11-
import pl.pawelosinski.dynatrace.nbp.task.backend.model.MinMaxRate;
12-
import pl.pawelosinski.dynatrace.nbp.task.backend.model.Rate;
10+
import pl.pawelosinski.dynatrace.nbp.task.backend.model.*;
11+
import pl.pawelosinski.dynatrace.nbp.task.backend.model.rate.RateC;
12+
import pl.pawelosinski.dynatrace.nbp.task.backend.model.table.TableA;
1313
import pl.pawelosinski.dynatrace.nbp.task.backend.service.CurrencyService;
1414

1515
import java.util.Optional;
@@ -22,8 +22,8 @@ public class CurrencyController {
2222
@Autowired
2323
private CurrencyService currencyService;
2424

25-
@GetMapping("/averagerate/{date}")
26-
public ResponseEntity<CurrencyRateTable> averageExchangeRate(@RequestParam(value = "currency") String currency, @PathVariable String date) {
25+
@GetMapping(value = "/exchanges/{currency}", produces="application/json")
26+
public ResponseEntity<TableA> averageExchangeRate(@PathVariable String currency, @RequestParam(value = "date") String date) {
2727

2828
try {
2929
return ResponseEntity.status(OK).body(currencyService.getRateFromDay(currency, date));
@@ -40,10 +40,10 @@ public ResponseEntity<CurrencyRateTable> averageExchangeRate(@RequestParam(value
4040
}
4141
}
4242

43-
@GetMapping("/minmaxrate/{n}")
44-
public ResponseEntity<Optional<MinMaxRate>> averageExchangeRate(@RequestParam(value = "currency") String currency, @PathVariable int n) {
43+
@GetMapping(value = "/minmaxrate/{currency}", produces="application/json")
44+
public ResponseEntity<Optional<MinMaxRate>> averageExchangeRate(@PathVariable String currency, @RequestParam(value = "quotations") int quotations) {
4545
try {
46-
return ResponseEntity.status(OK).body(currencyService.getMinMaxFromQuotations(n, currency));
46+
return ResponseEntity.status(OK).body(currencyService.getMinMaxFromQuotations(quotations, currency));
4747
} catch (HttpClientErrorException ex) {
4848
if (ex.getStatusCode() == NOT_FOUND) {
4949
return ResponseEntity.status(NOT_FOUND).build();
@@ -57,10 +57,10 @@ public ResponseEntity<Optional<MinMaxRate>> averageExchangeRate(@RequestParam(va
5757
}
5858
}
5959

60-
@GetMapping("/majordifference/{n}")
61-
public ResponseEntity<Optional<Rate>> majorDifference(@RequestParam(value = "currency") String currency, @PathVariable int n) {
60+
@GetMapping(value = "/majordifference/{currency}", produces="application/json")
61+
public ResponseEntity<Optional<RateC>> majorDifference(@PathVariable String currency, @RequestParam(value = "quotations") int quotations){
6262
try {
63-
return ResponseEntity.status(OK).body(currencyService.getDifferenceFromQuotations(n, currency));
63+
return ResponseEntity.status(OK).body(currencyService.getDifferenceFromQuotations(quotations, currency));
6464
} catch (HttpClientErrorException ex) {
6565
if (ex.getStatusCode() == NOT_FOUND) {
6666
return ResponseEntity.status(NOT_FOUND).build();
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
package pl.pawelosinski.dynatrace.nbp.task.backend.model;
22

3+
import pl.pawelosinski.dynatrace.nbp.task.backend.model.rate.RateA;
4+
35
public class MinMaxRate {
4-
private Rate min;
5-
private Rate max;
6+
private RateA min;
7+
private RateA max;
68

79
public MinMaxRate() {
810
}
911

10-
public MinMaxRate(Rate min, Rate max) {
12+
public MinMaxRate(RateA min, RateA max) {
1113
this.min = min;
1214
this.max = max;
1315
}
1416

15-
public Rate getMin() {
17+
public RateA getMin() {
1618
return min;
1719
}
1820

19-
public void setMin(Rate min) {
21+
public void setMin(RateA min) {
2022
this.min = min;
2123
}
2224

23-
public Rate getMax() {
25+
public RateA getMax() {
2426
return max;
2527
}
2628

27-
public void setMax(Rate max) {
29+
public void setMax(RateA max) {
2830
this.max = max;
2931
}
3032
}

src/main/java/pl/pawelosinski/dynatrace/nbp/task/backend/model/Rate.java

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package pl.pawelosinski.dynatrace.nbp.task.backend.model.rate;
2+
3+
public class Rate {
4+
private String no;
5+
private String effectiveDate;
6+
7+
public Rate() {
8+
}
9+
10+
public Rate(String no, String effectiveDate, double mid, double bid, double ask) {
11+
this.no = no;
12+
this.effectiveDate = effectiveDate;
13+
14+
}
15+
16+
public String getNo() {
17+
return no;
18+
}
19+
20+
public void setNo(String no) {
21+
this.no = no;
22+
}
23+
24+
public String getEffectiveDate() {
25+
return effectiveDate;
26+
}
27+
28+
public void setEffectiveDate(String effectiveDate) {
29+
this.effectiveDate = effectiveDate;
30+
}
31+
32+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package pl.pawelosinski.dynatrace.nbp.task.backend.model.rate;
2+
3+
public class RateA extends Rate{
4+
private double mid;
5+
6+
public double getMid() {
7+
return mid;
8+
}
9+
10+
public void setMid(double mid) {
11+
this.mid = mid;
12+
}
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package pl.pawelosinski.dynatrace.nbp.task.backend.model.rate;
2+
3+
public class RateC extends Rate{
4+
private double ask;
5+
private double bid;
6+
7+
public double getAsk() {
8+
return ask;
9+
}
10+
11+
public void setAsk(double ask) {
12+
this.ask = ask;
13+
}
14+
15+
public double getBid() {
16+
return bid;
17+
}
18+
19+
public void setBid(double bid) {
20+
this.bid = bid;
21+
}
22+
}

src/main/java/pl/pawelosinski/dynatrace/nbp/task/backend/model/CurrencyRateTable.java renamed to src/main/java/pl/pawelosinski/dynatrace/nbp/task/backend/model/table/Table.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
package pl.pawelosinski.dynatrace.nbp.task.backend.model;
1+
package pl.pawelosinski.dynatrace.nbp.task.backend.model.table;
22

3-
import java.util.List;
4-
5-
public class CurrencyRateTable {
3+
public class Table {
64
private String table = "";
75
private String currency = "";
86
private String code = "";
9-
private List<Rate> rates = List.of();
107

11-
public CurrencyRateTable() {
8+
public Table() {
129
}
1310

14-
public CurrencyRateTable(String table, String currency, String code, List<Rate> rates) {
11+
public Table(String table, String currency, String code) {
1512
this.table = table;
1613
this.currency = currency;
1714
this.code = code;
18-
this.rates = rates;
1915
}
2016

2117
public String getTable() {
@@ -42,12 +38,5 @@ public void setCode(String code) {
4238
this.code = code;
4339
}
4440

45-
public List<Rate> getRates() {
46-
return rates;
47-
}
48-
49-
public void setRates(List<Rate> rates) {
50-
this.rates = rates;
51-
}
5241
}
5342

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package pl.pawelosinski.dynatrace.nbp.task.backend.model.table;
2+
3+
import pl.pawelosinski.dynatrace.nbp.task.backend.model.rate.RateA;
4+
5+
import java.util.List;
6+
7+
public class TableA extends Table {
8+
9+
private List<RateA> rates;
10+
11+
public List<RateA> getRates() {
12+
return rates;
13+
}
14+
15+
public void setRates(List<RateA> rates) {
16+
this.rates = rates;
17+
}
18+
19+
public TableA() {
20+
super();
21+
}
22+
23+
public TableA(String table, String currency, String code, List<RateA> rates) {
24+
super(table, currency, code);
25+
this.rates = rates;
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package pl.pawelosinski.dynatrace.nbp.task.backend.model.table;
2+
3+
import pl.pawelosinski.dynatrace.nbp.task.backend.model.rate.RateC;
4+
5+
import java.util.List;
6+
7+
public class TableC extends Table {
8+
9+
private List<RateC> rates;
10+
11+
public List<RateC> getRates() {
12+
return rates;
13+
}
14+
15+
public void setRates(List<RateC> rates) {
16+
this.rates = rates;
17+
}
18+
19+
public TableC() {
20+
super();
21+
}
22+
23+
public TableC(String table, String currency, String code, List<RateC> rates) {
24+
super(table, currency, code);
25+
this.rates = rates;
26+
}
27+
}

0 commit comments

Comments
 (0)