커뮤니티 게시물 좋아요 로직 수정
This commit is contained in:
		| @@ -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() | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user