|
|
@@ -47,8 +47,8 @@ public class PortfolioService {
|
|
|
return repository.findAllPortfolioIds();
|
|
|
}
|
|
|
|
|
|
- public List<Portfolio> getByUser(String username, String currency) {
|
|
|
- return repository.findAllByUsername(username).stream()
|
|
|
+ public List<Portfolio> getByUser(String userId, String currency) {
|
|
|
+ return repository.findAllByUser(userId).stream()
|
|
|
.map(entity -> get(entity.getId(), currency))
|
|
|
.toList();
|
|
|
}
|
|
|
@@ -94,7 +94,7 @@ public class PortfolioService {
|
|
|
PortfolioEntity toSave = PortfolioEntity.builder()
|
|
|
.id(id)
|
|
|
.stocks(emptyList())
|
|
|
- .username(UserContextHolder.get().getUsername())
|
|
|
+ .user(UserContextHolder.get().getId())
|
|
|
.createdAt(now())
|
|
|
.updatedAt(now())
|
|
|
.build();
|
|
|
@@ -106,7 +106,7 @@ public class PortfolioService {
|
|
|
log.info("Updating portfolio [{}]", id);
|
|
|
PortfolioEntity toUpdate = repository.findById(id).orElseThrow(() -> new NotFoundException("Failed to update portfolio with id: " + id));
|
|
|
|
|
|
- if (!Objects.equals(toUpdate.getUsername(), UserContextHolder.get().getUsername())) {
|
|
|
+ if (!Objects.equals(toUpdate.getUser(), UserContextHolder.get().getId()) || UserContextHolder.isAdmin()) {
|
|
|
throw new UnauthorizedException("You do not have permission to update portfolio");
|
|
|
}
|
|
|
|
|
|
@@ -133,9 +133,7 @@ public class PortfolioService {
|
|
|
|
|
|
public void cleanup() {
|
|
|
repository.findAll().forEach(portfolio -> {
|
|
|
- if ((ObjectUtils.isEmpty(portfolio.getEncryptedStocks()) && ObjectUtils.isEmpty(portfolio.getStocks().isEmpty()))
|
|
|
- || portfolio.getUsername() == null
|
|
|
- || portfolio.getUsername().contains("test")) {
|
|
|
+ if ((ObjectUtils.isEmpty(portfolio.getEncryptedStocks()))) {
|
|
|
log.info("Removing empty portfolio [{}]", portfolio.getId());
|
|
|
repository.deleteById(portfolio.getId());
|
|
|
}
|