커뮤니티 게시물 좋아요 로직 수정

This commit is contained in:
Klaus 2023-12-20 03:47:14 +09:00
parent 0df0d71660
commit 25022e4909
2 changed files with 18 additions and 5 deletions

View File

@ -137,7 +137,8 @@ class CreatorCommunityService(
return postList
.asSequence()
.map {
val isLike = likeRepository.findByIdAndMemberId(id = it.id!!, memberId = memberId)?.isActive ?: false
val isLike =
likeRepository.findByPostIdAndMemberId(postId = it.id!!, memberId = memberId)?.isActive ?: false
val likeCount = likeRepository.totalCountCommunityPostLikeByPostId(it.id!!)
val commentCount = if (it.isCommentAvailable) {
commentRepository.totalCountCommentByPostId(postId = it.id!!)
@ -197,7 +198,7 @@ class CreatorCommunityService(
@Transactional
fun communityPostLike(request: PostCommunityPostLikeRequest, member: Member): PostCommunityPostLikeResponse {
var postLike = likeRepository.findByIdAndMemberId(id = request.postId, memberId = member.id!!)
var postLike = likeRepository.findByPostIdAndMemberId(postId = request.postId, memberId = member.id!!)
if (postLike == null) {
postLike = CreatorCommunityLike()

View File

@ -1,21 +1,33 @@
package kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.like
import com.querydsl.jpa.impl.JPAQueryFactory
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.QCreatorCommunity.creatorCommunity
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.like.QCreatorCommunityLike.creatorCommunityLike
import org.springframework.data.jpa.repository.JpaRepository
interface CreatorCommunityLikeRepository :
JpaRepository<CreatorCommunityLike, Long>, CreatorCommunityLikeQueryRepository {
fun findByIdAndMemberId(id: Long, memberId: Long): CreatorCommunityLike?
}
JpaRepository<CreatorCommunityLike, Long>, CreatorCommunityLikeQueryRepository
interface CreatorCommunityLikeQueryRepository {
fun findByPostIdAndMemberId(postId: Long, memberId: Long): CreatorCommunityLike?
fun totalCountCommunityPostLikeByPostId(postId: Long): Int
}
class CreatorCommunityLikeQueryRepositoryImpl(
private val queryFactory: JPAQueryFactory
) : CreatorCommunityLikeQueryRepository {
override fun findByPostIdAndMemberId(postId: Long, memberId: Long): CreatorCommunityLike? {
return queryFactory
.selectFrom(creatorCommunityLike)
.innerJoin(creatorCommunityLike.creatorCommunity, creatorCommunity)
.where(
creatorCommunityLike.creatorCommunity.id.eq(postId)
.and(creatorCommunityLike.member.id.eq(memberId))
)
.fetchFirst()
}
override fun totalCountCommunityPostLikeByPostId(postId: Long): Int {
return queryFactory
.select(creatorCommunityLike.id)