Skip to content

Commit

Permalink
feat: 공유 그룹의 대표 이미지를 초기화하는 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bflykky committed Aug 21, 2024
1 parent 98302da commit 0474f3a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
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;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class PhotoEsServiceImpl implements PhotoEsService {
Expand All @@ -29,7 +32,17 @@ public Page<PhotoEs> getPhotoEsListByShareGroupIdAndFaceTag(Long shareGroupId, L
@Transactional(readOnly = true)
public Page<PhotoEs> getAllPhotoEsListByShareGroupId(Long shareGroupId, Member member, Pageable pageable) {
validateShareGroupAndProfile(shareGroupId, member);
return photoEsClientRepository.findPhotoEsByShareGroupId(shareGroupId, pageable);
Page<PhotoEs> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ public void delete() {
}
super.delete();
}

public void updateImage(String image) {
this.image = image;
}
}

0 comments on commit 0474f3a

Please sign in to comment.