|
@@ -17,6 +17,7 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -49,10 +50,13 @@ public class CollectionService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public List<CollectionDTO> toDTO(List<Collection> collections) {
|
|
public List<CollectionDTO> toDTO(List<Collection> collections) {
|
|
|
|
|
+ List<Like> likes = new ArrayList<>();
|
|
|
|
|
+ if (SecurityUtils.getAuthenticatedUser() != null) {
|
|
|
|
|
+ likes.addAll(likeRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId()));
|
|
|
|
|
+ }
|
|
|
return collections.stream().parallel().map(collection -> {
|
|
return collections.stream().parallel().map(collection -> {
|
|
|
CollectionDTO dto = toDTO(collection, false);
|
|
CollectionDTO dto = toDTO(collection, false);
|
|
|
- if (SecurityUtils.getAuthenticatedUser() != null) {
|
|
|
|
|
- List<Like> likes = likeRepo.findByUserId(SecurityUtils.getAuthenticatedUser().getId());
|
|
|
|
|
|
|
+ if (!likes.isEmpty()) {
|
|
|
dto.setLiked(likes.stream().anyMatch(l -> l.getCollectionId().equals(collection.getId())));
|
|
dto.setLiked(likes.stream().anyMatch(l -> l.getCollectionId().equals(collection.getId())));
|
|
|
}
|
|
}
|
|
|
return dto;
|
|
return dto;
|