Skip to content

Commit

Permalink
Merge pull request #130 from Na-o-man/feature/#129/shareGroup-update-…
Browse files Browse the repository at this point in the history
…image

[FEAT] 공유 그룹의 대표 이미지를 초기화하는 로직 추가
  • Loading branch information
bflykky authored Aug 21, 2024
2 parents 98302da + 3b9a93b commit 7956e78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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 @@ -26,10 +29,20 @@ public Page<PhotoEs> getPhotoEsListByShareGroupIdAndFaceTag(Long shareGroupId, L
}

@Override
@Transactional(readOnly = true)
@Transactional
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 7956e78

Please sign in to comment.