From a4801b2e63155e781ad6986854e6255e226eff9f Mon Sep 17 00:00:00 2001 From: Denis Kolovorotnyi Date: Fri, 14 Jul 2023 13:10:39 +0200 Subject: [PATCH] [fix]: Fixed bug with friends photos --- .../com/rangiffler/service/PhotoService.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/rangiffler-gateway/src/main/java/com/rangiffler/service/PhotoService.java b/rangiffler-gateway/src/main/java/com/rangiffler/service/PhotoService.java index c8ff2e7..43518b3 100644 --- a/rangiffler-gateway/src/main/java/com/rangiffler/service/PhotoService.java +++ b/rangiffler-gateway/src/main/java/com/rangiffler/service/PhotoService.java @@ -1,10 +1,12 @@ package com.rangiffler.service; -import com.rangiffler.model.*; +import com.rangiffler.model.CountryJson; +import com.rangiffler.model.FriendStatus; +import com.rangiffler.model.PhotoJson; +import com.rangiffler.model.PhotoServiceJson; import com.rangiffler.service.configuration.PhotoServiceClient; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -42,17 +44,12 @@ public PhotoJson editPhoto(PhotoJson photoJson, UUID id) { } public List getAllFriendsPhotos(String username) { - List friendsPhoto = new ArrayList<>(); - List friends = userService.receivePeopleAround(username) + return userService.receivePeopleAround(username) .stream() .filter(userJson -> userJson.getFriendStatus() == FriendStatus.FRIEND) - .toList(); - - for (UserJson userJson : friends) { - friendsPhoto.addAll(getAllUserPhotos(userJson.getUsername())); - } - - return friendsPhoto; + .map(userJson -> getAllUserPhotos(userJson.getUsername())) + .findFirst() + .orElseGet(ArrayList::new); } public void deletePhoto(UUID photoId) {