From 25022e4909926e39e3f8a2ced73881e81983e984 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 20 Dec 2023 03:47:14 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EB=AC=BC=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreatorCommunityService.kt | 5 +++-- .../like/CreatorCommunityLikeRepository.kt | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityService.kt index b69fd08..5bff567 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityService.kt @@ -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() diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/like/CreatorCommunityLikeRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/like/CreatorCommunityLikeRepository.kt index 6d9668d..263548b 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/like/CreatorCommunityLikeRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/like/CreatorCommunityLikeRepository.kt @@ -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, CreatorCommunityLikeQueryRepository { - fun findByIdAndMemberId(id: Long, memberId: Long): CreatorCommunityLike? -} + JpaRepository, 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)