|
|
@@ -6,7 +6,6 @@ import com.danielbohry.stocks.domain.Quote;
|
|
|
import com.danielbohry.stocks.domain.Stock;
|
|
|
import com.danielbohry.stocks.exception.BadRequestException;
|
|
|
import com.danielbohry.stocks.exception.NotFoundException;
|
|
|
-import com.danielbohry.stocks.exception.UnauthorizedException;
|
|
|
import com.danielbohry.stocks.repository.PortfolioRepository;
|
|
|
import com.danielbohry.stocks.service.ExchangeService.ExchangeRateResponse;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -15,10 +14,11 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
-import static java.math.RoundingMode.HALF_UP;
|
|
|
import static java.time.LocalDateTime.now;
|
|
|
import static java.util.Collections.emptyList;
|
|
|
|
|
|
@@ -35,6 +35,10 @@ public class PortfolioService {
|
|
|
return repository.findAll();
|
|
|
}
|
|
|
|
|
|
+ public List<String> getAllIds() {
|
|
|
+ return repository.findAllPortfolioIds();
|
|
|
+ }
|
|
|
+
|
|
|
public List<Portfolio> getByUser(String username, String currency) {
|
|
|
List<Portfolio> portfolios = repository.findAllByUsername(username);
|
|
|
|
|
|
@@ -47,10 +51,6 @@ public class PortfolioService {
|
|
|
Portfolio portfolio = repository.findById(id)
|
|
|
.orElseThrow(() -> new NotFoundException("No portfolio found with id: " + id));
|
|
|
|
|
|
- if (portfolio.getUsername() != null && !Objects.equals(portfolio.getUsername(), UserContextHolder.get().getUsername())) {
|
|
|
- throw new UnauthorizedException("You do not have permission to access this portfolio");
|
|
|
- }
|
|
|
-
|
|
|
ExchangeRateResponse exchangeRate = exchangeService.getCurrentRate(currency);
|
|
|
Map<String, BigDecimal> rates = exchangeRate.getConversionRates();
|
|
|
BigDecimal targetRate = rates.getOrDefault(currency, BigDecimal.ONE);
|