|
@@ -12,11 +12,11 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
+import static java.nio.charset.StandardCharsets.UTF_8;
|
|
|
import static java.time.LocalDateTime.now;
|
|
import static java.time.LocalDateTime.now;
|
|
|
import static java.util.Collections.emptyList;
|
|
import static java.util.Collections.emptyList;
|
|
|
|
|
|
|
@@ -51,14 +51,14 @@ public class StockController {
|
|
|
|
|
|
|
|
@Hidden
|
|
@Hidden
|
|
|
@PostMapping("/upload-csv")
|
|
@PostMapping("/upload-csv")
|
|
|
- public ResponseEntity<StockUploadCSVResponse> uploadCsvFile(@RequestParam("file") MultipartFile file) {
|
|
|
|
|
|
|
+ public ResponseEntity<StockUploadCSVResponse> uploadCsvFile(@RequestParam("file") MultipartFile file, @RequestParam("currency") String currency) {
|
|
|
if (file.isEmpty()) {
|
|
if (file.isEmpty()) {
|
|
|
return ResponseEntity.badRequest().build();
|
|
return ResponseEntity.badRequest().build();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))) {
|
|
|
|
|
|
|
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream(), UTF_8))) {
|
|
|
List<Quote> quotes = reader.lines()
|
|
List<Quote> quotes = reader.lines()
|
|
|
- .map(this::convert)
|
|
|
|
|
|
|
+ .map(r -> convert(r, currency))
|
|
|
.filter(Objects::nonNull)
|
|
.filter(Objects::nonNull)
|
|
|
.toList();
|
|
.toList();
|
|
|
|
|
|
|
@@ -71,7 +71,7 @@ public class StockController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Quote convert(String input) {
|
|
|
|
|
|
|
+ private Quote convert(String input, String currency) {
|
|
|
String[] value = input.split(",");
|
|
String[] value = input.split(",");
|
|
|
|
|
|
|
|
log.info("Importing [{}]", (Object) value);
|
|
log.info("Importing [{}]", (Object) value);
|
|
@@ -79,7 +79,7 @@ public class StockController {
|
|
|
if (value[3] != null && !value[3].equals("#N/A")) {
|
|
if (value[3] != null && !value[3].equals("#N/A")) {
|
|
|
BigDecimal price = new BigDecimal(value[3]);
|
|
BigDecimal price = new BigDecimal(value[3]);
|
|
|
return price.compareTo(BigDecimal.ZERO) > 0
|
|
return price.compareTo(BigDecimal.ZERO) > 0
|
|
|
- ? new Quote(value[0], value[1], price, now())
|
|
|
|
|
|
|
+ ? new Quote(value[0], value[1], currency, price, now())
|
|
|
: null;
|
|
: null;
|
|
|
} else if (value[0] != null && Objects.equals(value[3], "#N/A")) {
|
|
} else if (value[0] != null && Objects.equals(value[3], "#N/A")) {
|
|
|
return null;
|
|
return null;
|