diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCanRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCanRepository.kt index eeac478..07bdce1 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCanRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCanRepository.kt @@ -9,17 +9,18 @@ import org.springframework.stereotype.Repository interface UseCanRepository : JpaRepository, UseCanQueryRepository interface UseCanQueryRepository { - fun isExistOrdered(postId: Long, memberId: Long): Boolean + fun isExistCommunityPostOrdered(postId: Long, memberId: Long): Boolean } class UseCanQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : UseCanQueryRepository { - override fun isExistOrdered(postId: Long, memberId: Long): Boolean { + override fun isExistCommunityPostOrdered(postId: Long, memberId: Long): Boolean { val useCanId = queryFactory.select(useCan.id) .from(useCan) .where( useCan.member.id.eq(memberId) .and(useCan.isRefund.isFalse) .and(useCan.communityPost.id.eq(postId)) + .and(useCan.canUsage.eq(CanUsage.PAID_COMMUNITY_POST)) ) .fetchFirst() diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityController.kt index 85c61b8..62ce8ca 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityController.kt @@ -129,6 +129,7 @@ class CreatorCommunityController(private val service: CreatorCommunityService) { comment = request.comment, postId = request.postId, parentId = request.parentId, + isSecret = request.isSecret, member = member ) ) 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 7e483f9..06a7c96 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 @@ -212,7 +212,7 @@ class CreatorCommunityService( null } - val existOrdered = useCanRepository.isExistOrdered(postId = it.id, memberId = memberId) + val existOrdered = useCanRepository.isExistCommunityPostOrdered(postId = it.id, memberId = memberId) val audioUrl = if ( ( @@ -285,7 +285,7 @@ class CreatorCommunityService( null } - val existOrdered = useCanRepository.isExistOrdered(postId = post.id, memberId = memberId) + val existOrdered = useCanRepository.isExistCommunityPostOrdered(postId = post.id, memberId = memberId) val audioUrl = if ((post.price <= 0 || existOrdered) && post.audioPath != null) { audioContentCloudFront.generateSignedURL( @@ -347,11 +347,22 @@ class CreatorCommunityService( } @Transactional - fun createCommunityPostComment(comment: String, postId: Long, parentId: Long?, member: Member) { + fun createCommunityPostComment( + member: Member, + comment: String, + postId: Long, + parentId: Long? = null, + isSecret: Boolean = false + ) { val post = repository.findByIdOrNull(id = postId) ?: throw SodaException("잘못된 게시물 입니다.\n다시 시도해 주세요.") + val isExistOrdered = useCanRepository.isExistCommunityPostOrdered(postId = postId, memberId = member.id!!) - val postComment = CreatorCommunityComment(comment = comment) + if (isSecret && !isExistOrdered) { + throw SodaException("게시글을 구매 후 비밀댓글을 등록할 수 있습니다.") + } + + val postComment = CreatorCommunityComment(comment = comment, isSecret = isSecret) postComment.creatorCommunity = post postComment.member = member @@ -465,7 +476,7 @@ class CreatorCommunityService( null } - val existOrdered = useCanRepository.isExistOrdered(postId = it.id, memberId = memberId) + val existOrdered = useCanRepository.isExistCommunityPostOrdered(postId = it.id, memberId = memberId) it.toCommunityPostListResponse( imageHost = imageHost, @@ -499,7 +510,7 @@ class CreatorCommunityService( val isBlocked = blockMemberRepository.isBlocked(blockedMemberId = memberId, memberId = post.member!!.id!!) if (isBlocked) throw SodaException("${post.member!!.nickname}님의 요청으로 접근이 제한됩니다.") - val existOrdered = useCanRepository.isExistOrdered(postId = postId, memberId = memberId) + val existOrdered = useCanRepository.isExistCommunityPostOrdered(postId = postId, memberId = memberId) if (!existOrdered) { canPaymentService.spendCan( diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreateCommunityPostCommentRequest.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreateCommunityPostCommentRequest.kt index 5e833d6..bd01576 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreateCommunityPostCommentRequest.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreateCommunityPostCommentRequest.kt @@ -1,3 +1,8 @@ package kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment -data class CreateCommunityPostCommentRequest(val comment: String, val postId: Long, val parentId: Long?) +data class CreateCommunityPostCommentRequest( + val comment: String, + val postId: Long, + val parentId: Long?, + val isSecret: Boolean = false +) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreatorCommunityComment.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreatorCommunityComment.kt index 6e65c0a..84af1c1 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreatorCommunityComment.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreatorCommunityComment.kt @@ -14,6 +14,7 @@ import javax.persistence.OneToMany data class CreatorCommunityComment( @Column(columnDefinition = "TEXT", nullable = false) var comment: String, + val isSecret: Boolean = false, var isActive: Boolean = true ) : BaseEntity() { @ManyToOne(fetch = FetchType.LAZY)