feat(community): 채널 커뮤니티 좋아요 조회를 추가한다

This commit is contained in:
2026-06-30 01:09:56 +09:00
parent 16ec1240bb
commit fc7143d0bb
2 changed files with 35 additions and 4 deletions

View File

@@ -186,6 +186,7 @@ class DefaultCreatorChannelCommunityQueryRepository(
val postIds = map { it.postId }
val orderedPostIds = orderedCommunityPostIds(creatorId, viewerId, postIds)
val likeCounts = communityLikeCounts(postIds)
val likedPostIds = likedCommunityPostIds(viewerId, postIds)
val commentAvailablePostIds = filter { it.isCommentAvailable }.map { it.postId }
val commentCounts = communityCommentCounts(commentAvailablePostIds, creatorId, viewerId)
@@ -206,7 +207,8 @@ class DefaultCreatorChannelCommunityQueryRepository(
isCommentAvailable = row.isCommentAvailable,
likeCount = likeCounts[postId] ?: 0,
commentCount = commentCounts[postId] ?: 0,
isPinned = isPinned
isPinned = isPinned,
isLiked = postId in likedPostIds
)
}
}
@@ -233,6 +235,22 @@ class DefaultCreatorChannelCommunityQueryRepository(
.toSet()
}
private fun likedCommunityPostIds(viewerId: Long, postIds: List<Long>): Set<Long> {
if (postIds.isEmpty()) return emptySet()
return queryFactory
.select(creatorCommunityLike.creatorCommunity.id)
.distinct()
.from(creatorCommunityLike)
.where(
creatorCommunityLike.member.id.eq(viewerId),
creatorCommunityLike.creatorCommunity.id.`in`(postIds),
creatorCommunityLike.isActive.isTrue
)
.fetch()
.toSet()
}
private fun communityLikeCounts(postIds: List<Long>): Map<Long, Int> {
if (postIds.isEmpty()) return emptyMap()

View File

@@ -153,22 +153,33 @@ class DefaultCreatorChannelCommunityQueryRepositoryTest @Autowired constructor(
val inactiveLiker = saveMember("inactive-liker", MemberRole.USER)
val commenter = saveMember("unavailable-commenter", MemberRole.USER)
val post = saveCommunity(creator, isFixed = false, price = 0, isCommentAvailable = false)
val otherMemberOnlyLikedPost = saveCommunity(creator, isFixed = false, price = 0, isCommentAvailable = false)
val inactiveViewerLikedPost = saveCommunity(creator, isFixed = false, price = 0, isCommentAvailable = false)
saveCommunityLike(activeLiker, post, isActive = true)
saveCommunityLike(viewer, post, isActive = true)
saveCommunityLike(activeLiker, otherMemberOnlyLikedPost, isActive = true)
saveCommunityLike(inactiveLiker, post, isActive = false)
saveCommunityLike(viewer, inactiveViewerLikedPost, isActive = false)
saveCommunityComment(commenter, post, isActive = true)
flushAndClear()
val record = repository.findCommunityPosts(
val records = repository.findCommunityPosts(
creatorId = creator.id!!,
viewerId = viewer.id!!,
canViewAdultContent = true,
offset = 0,
limit = 10
).single()
)
val record = records.single { it.postId == post.id }
val otherMemberOnlyLikedRecord = records.single { it.postId == otherMemberOnlyLikedPost.id }
val inactiveViewerLikedRecord = records.single { it.postId == inactiveViewerLikedPost.id }
assertEquals(1, record.likeCount)
assertEquals(2, record.likeCount)
assertEquals(0, record.commentCount)
assertFalse(record.isCommentAvailable)
assertTrue(record.isLiked)
assertFalse(otherMemberOnlyLikedRecord.isLiked)
assertFalse(inactiveViewerLikedRecord.isLiked)
}
@Test
@@ -276,6 +287,7 @@ class DefaultCreatorChannelCommunityQueryRepositoryTest @Autowired constructor(
val pinned = saveCommunity(creator, isFixed = true, fixedAt = now.minusHours(1), price = 0)
val normal = saveCommunity(creator, isFixed = false, price = 0)
val adultPinned = saveCommunity(creator, isFixed = true, fixedAt = now, price = 0, isAdult = true)
saveCommunityLike(viewer, normal, isActive = true)
flushAndClear()
updateCreatedAt("CreatorCommunity", normal.id!!, now.minusDays(1))
flushAndClear()
@@ -300,6 +312,7 @@ class DefaultCreatorChannelCommunityQueryRepositoryTest @Autowired constructor(
assertFalse(adultPinned.id in pinnedPosts.map { it.postId })
assertTrue(pinnedPosts.single().isPinned)
assertFalse(normalPosts.single().isPinned)
assertTrue(normalPosts.single().isLiked)
}
@Test