|
|
@@ -2,6 +2,7 @@ package com.danielbohry.stocks.repository;
|
|
|
|
|
|
import com.danielbohry.stocks.client.StockClient;
|
|
|
import com.danielbohry.stocks.domain.Quote;
|
|
|
+import com.danielbohry.stocks.exception.NotFoundException;
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
import feign.FeignException;
|
|
|
@@ -32,23 +33,25 @@ public class StockRepository {
|
|
|
this.key = key;
|
|
|
}
|
|
|
|
|
|
- public List<Quote> findAll() {
|
|
|
- return repository.findAll();
|
|
|
- }
|
|
|
-
|
|
|
public List<Quote> findLike(String query) {
|
|
|
return repository.findByNameContaining(query);
|
|
|
}
|
|
|
|
|
|
public Quote findByCode(String code) {
|
|
|
- Optional<Quote> quote = repository.findLatestByCode(code).stream().findFirst();
|
|
|
- return quote.orElseGet(() -> repository.save(getStockQuote(code)));
|
|
|
+// Optional<Quote> quote = repository.findLatestByCode(code).stream().findFirst();
|
|
|
+// return quote.orElseGet(() -> repository.save(getStockQuote(code)));
|
|
|
+ return repository.findLatestByCode(code).stream().findFirst()
|
|
|
+ .orElseThrow(() -> new NotFoundException("No stock found"));
|
|
|
}
|
|
|
|
|
|
public List<Quote> update(List<Quote> quote) {
|
|
|
return repository.saveAll(quote);
|
|
|
}
|
|
|
|
|
|
+ public void deleteAll() {
|
|
|
+ repository.deleteAll();
|
|
|
+ }
|
|
|
+
|
|
|
public boolean isValid(String code) {
|
|
|
Quote quote = repository.findLatestByCode(code).stream().findFirst().orElse(null);
|
|
|
|