diff --git a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsServiceImpl.java b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsServiceImpl.java index 1c21c0d..d6ebc42 100644 --- a/src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsServiceImpl.java +++ b/src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsServiceImpl.java @@ -3,6 +3,7 @@ import com.umc.naoman.domain.member.entity.Member; import com.umc.naoman.domain.photo.elasticsearch.document.PhotoEs; import com.umc.naoman.domain.photo.elasticsearch.repository.PhotoEsClientRepository; +import com.umc.naoman.domain.shareGroup.entity.ShareGroup; import com.umc.naoman.domain.shareGroup.service.ShareGroupService; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -10,6 +11,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.stream.Collectors; + @Service @RequiredArgsConstructor public class PhotoEsServiceImpl implements PhotoEsService { @@ -29,7 +32,17 @@ public Page getPhotoEsListByShareGroupIdAndFaceTag(Long shareGroupId, L @Transactional(readOnly = true) public Page getAllPhotoEsListByShareGroupId(Long shareGroupId, Member member, Pageable pageable) { validateShareGroupAndProfile(shareGroupId, member); - return photoEsClientRepository.findPhotoEsByShareGroupId(shareGroupId, pageable); + Page photoEsList = photoEsClientRepository.findPhotoEsByShareGroupId(shareGroupId, pageable); + + final ShareGroup shareGroup = shareGroupService.findShareGroup(shareGroupId); + if (shareGroup.getImage() == null) { + photoEsList.stream() + .filter(photoEs -> photoEs.getFaceTag().size() >= shareGroup.getMemberCount()) + .findFirst() + .ifPresent(photoEs -> shareGroup.updateImage(photoEs.getUrl())); + } + + return photoEsList; } @Override diff --git a/src/main/java/com/umc/naoman/domain/shareGroup/entity/ShareGroup.java b/src/main/java/com/umc/naoman/domain/shareGroup/entity/ShareGroup.java index e833966..549aa0b 100644 --- a/src/main/java/com/umc/naoman/domain/shareGroup/entity/ShareGroup.java +++ b/src/main/java/com/umc/naoman/domain/shareGroup/entity/ShareGroup.java @@ -53,4 +53,8 @@ public void delete() { } super.delete(); } + + public void updateImage(String image) { + this.image = image; + } }