From 0474f3a0d43de3c9b17a6690d6bcbd9a6cf26ae0 Mon Sep 17 00:00:00 2001 From: bflykky Date: Thu, 22 Aug 2024 02:52:54 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EA=B3=B5=EC=9C=A0=20=EA=B7=B8?= =?UTF-8?q?=EB=A3=B9=EC=9D=98=20=EB=8C=80=ED=91=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EC=B4=88=EA=B8=B0=ED=99=94=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../elasticsearch/service/PhotoEsServiceImpl.java | 15 ++++++++++++++- .../domain/shareGroup/entity/ShareGroup.java | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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; + } } From 3b9a93baf5fef7e953f1e30ba8c9023dc3837481 Mon Sep 17 00:00:00 2001 From: bflykky Date: Thu, 22 Aug 2024 02:54:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20readOnly=20=3D=20true=20=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/photo/elasticsearch/service/PhotoEsServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d6ebc42..07e3231 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 @@ -29,7 +29,7 @@ public Page getPhotoEsListByShareGroupIdAndFaceTag(Long shareGroupId, L } @Override - @Transactional(readOnly = true) + @Transactional public Page getAllPhotoEsListByShareGroupId(Long shareGroupId, Member member, Pageable pageable) { validateShareGroupAndProfile(shareGroupId, member); Page photoEsList = photoEsClientRepository.findPhotoEsByShareGroupId(shareGroupId, pageable);