Browse Source

Code simplification

Daniel Bohry 1 year ago
parent
commit
eceaa0e978
1 changed files with 4 additions and 5 deletions
  1. 4 5
      src/main/java/com/danielbohry/stocks/service/StockService.java

+ 4 - 5
src/main/java/com/danielbohry/stocks/service/StockService.java

@@ -38,7 +38,8 @@ public class StockService {
         quote.setUpdatedAt(now());
         quote.setUpdatedAt(now());
 
 
         if (quote.getName() == null) {
         if (quote.getName() == null) {
-            quote = updateStockInformation(quote);
+            StockInfoResponse info = updateStockInformation(quote.getCode());
+            quote.setName(info.getName());
         }
         }
 
 
         repository.save(quote);
         repository.save(quote);
@@ -46,11 +47,9 @@ public class StockService {
         return quote;
         return quote;
     }
     }
 
 
-    public Quote updateStockInformation(Quote quote) {
+    public StockInfoResponse updateStockInformation(String code) {
         log.info("Current stock's name is null. Requesting latest information...");
         log.info("Current stock's name is null. Requesting latest information...");
-        StockInfoResponse info = client.getStockInfo(quote.getCode(), key);
-        quote.setName(info.getName());
-        return quote;
+        return client.getStockInfo(code, key);
     }
     }
 
 
     private BigDecimal getLastPrice(Quote quote) {
     private BigDecimal getLastPrice(Quote quote) {