feat(community): 채널 커뮤니티 좋아요 조회를 추가한다
This commit is contained in:
@@ -186,6 +186,7 @@ class DefaultCreatorChannelCommunityQueryRepository(
|
|||||||
val postIds = map { it.postId }
|
val postIds = map { it.postId }
|
||||||
val orderedPostIds = orderedCommunityPostIds(creatorId, viewerId, postIds)
|
val orderedPostIds = orderedCommunityPostIds(creatorId, viewerId, postIds)
|
||||||
val likeCounts = communityLikeCounts(postIds)
|
val likeCounts = communityLikeCounts(postIds)
|
||||||
|
val likedPostIds = likedCommunityPostIds(viewerId, postIds)
|
||||||
val commentAvailablePostIds = filter { it.isCommentAvailable }.map { it.postId }
|
val commentAvailablePostIds = filter { it.isCommentAvailable }.map { it.postId }
|
||||||
val commentCounts = communityCommentCounts(commentAvailablePostIds, creatorId, viewerId)
|
val commentCounts = communityCommentCounts(commentAvailablePostIds, creatorId, viewerId)
|
||||||
|
|
||||||
@@ -206,7 +207,8 @@ class DefaultCreatorChannelCommunityQueryRepository(
|
|||||||
isCommentAvailable = row.isCommentAvailable,
|
isCommentAvailable = row.isCommentAvailable,
|
||||||
likeCount = likeCounts[postId] ?: 0,
|
likeCount = likeCounts[postId] ?: 0,
|
||||||
commentCount = commentCounts[postId] ?: 0,
|
commentCount = commentCounts[postId] ?: 0,
|
||||||
isPinned = isPinned
|
isPinned = isPinned,
|
||||||
|
isLiked = postId in likedPostIds
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,6 +235,22 @@ class DefaultCreatorChannelCommunityQueryRepository(
|
|||||||
.toSet()
|
.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> {
|
private fun communityLikeCounts(postIds: List<Long>): Map<Long, Int> {
|
||||||
if (postIds.isEmpty()) return emptyMap()
|
if (postIds.isEmpty()) return emptyMap()
|
||||||
|
|
||||||
|
|||||||
@@ -153,22 +153,33 @@ class DefaultCreatorChannelCommunityQueryRepositoryTest @Autowired constructor(
|
|||||||
val inactiveLiker = saveMember("inactive-liker", MemberRole.USER)
|
val inactiveLiker = saveMember("inactive-liker", MemberRole.USER)
|
||||||
val commenter = saveMember("unavailable-commenter", MemberRole.USER)
|
val commenter = saveMember("unavailable-commenter", MemberRole.USER)
|
||||||
val post = saveCommunity(creator, isFixed = false, price = 0, isCommentAvailable = false)
|
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(activeLiker, post, isActive = true)
|
||||||
|
saveCommunityLike(viewer, post, isActive = true)
|
||||||
|
saveCommunityLike(activeLiker, otherMemberOnlyLikedPost, isActive = true)
|
||||||
saveCommunityLike(inactiveLiker, post, isActive = false)
|
saveCommunityLike(inactiveLiker, post, isActive = false)
|
||||||
|
saveCommunityLike(viewer, inactiveViewerLikedPost, isActive = false)
|
||||||
saveCommunityComment(commenter, post, isActive = true)
|
saveCommunityComment(commenter, post, isActive = true)
|
||||||
flushAndClear()
|
flushAndClear()
|
||||||
|
|
||||||
val record = repository.findCommunityPosts(
|
val records = repository.findCommunityPosts(
|
||||||
creatorId = creator.id!!,
|
creatorId = creator.id!!,
|
||||||
viewerId = viewer.id!!,
|
viewerId = viewer.id!!,
|
||||||
canViewAdultContent = true,
|
canViewAdultContent = true,
|
||||||
offset = 0,
|
offset = 0,
|
||||||
limit = 10
|
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)
|
assertEquals(0, record.commentCount)
|
||||||
assertFalse(record.isCommentAvailable)
|
assertFalse(record.isCommentAvailable)
|
||||||
|
assertTrue(record.isLiked)
|
||||||
|
assertFalse(otherMemberOnlyLikedRecord.isLiked)
|
||||||
|
assertFalse(inactiveViewerLikedRecord.isLiked)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -276,6 +287,7 @@ class DefaultCreatorChannelCommunityQueryRepositoryTest @Autowired constructor(
|
|||||||
val pinned = saveCommunity(creator, isFixed = true, fixedAt = now.minusHours(1), price = 0)
|
val pinned = saveCommunity(creator, isFixed = true, fixedAt = now.minusHours(1), price = 0)
|
||||||
val normal = saveCommunity(creator, isFixed = false, price = 0)
|
val normal = saveCommunity(creator, isFixed = false, price = 0)
|
||||||
val adultPinned = saveCommunity(creator, isFixed = true, fixedAt = now, price = 0, isAdult = true)
|
val adultPinned = saveCommunity(creator, isFixed = true, fixedAt = now, price = 0, isAdult = true)
|
||||||
|
saveCommunityLike(viewer, normal, isActive = true)
|
||||||
flushAndClear()
|
flushAndClear()
|
||||||
updateCreatedAt("CreatorCommunity", normal.id!!, now.minusDays(1))
|
updateCreatedAt("CreatorCommunity", normal.id!!, now.minusDays(1))
|
||||||
flushAndClear()
|
flushAndClear()
|
||||||
@@ -300,6 +312,7 @@ class DefaultCreatorChannelCommunityQueryRepositoryTest @Autowired constructor(
|
|||||||
assertFalse(adultPinned.id in pinnedPosts.map { it.postId })
|
assertFalse(adultPinned.id in pinnedPosts.map { it.postId })
|
||||||
assertTrue(pinnedPosts.single().isPinned)
|
assertTrue(pinnedPosts.single().isPinned)
|
||||||
assertFalse(normalPosts.single().isPinned)
|
assertFalse(normalPosts.single().isPinned)
|
||||||
|
assertTrue(normalPosts.single().isLiked)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user