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..c84e587 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 ) ) @@ -158,6 +159,7 @@ class CreatorCommunityController(private val service: CreatorCommunityService) { ApiResponse.ok( service.getCommunityPostCommentList( postId = postId, + memberId = member.id!!, timezone = timezone, offset = pageable.offset, limit = pageable.pageSize.toLong() diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityRepository.kt index 1b31eec..f10b368 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityRepository.kt @@ -28,6 +28,8 @@ interface CreatorCommunityQueryRepository { fun getLatestPostListFromCreatorsYouFollow(memberId: Long, isAdult: Boolean): List fun getCommunityPost(postId: Long, isAdult: Boolean): SelectCommunityPostResponse? + + fun isCommunityCreator(postId: Long, memberId: Long): Boolean } class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CreatorCommunityQueryRepository { @@ -195,4 +197,17 @@ class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFact .where(where) .fetchFirst() } + + override fun isCommunityCreator(postId: Long, memberId: Long): Boolean { + return queryFactory + .select(member.id) + .from(creatorCommunity) + .innerJoin(creatorCommunity.member, member) + .where( + creatorCommunity.id.eq(postId) + .and(creatorCommunity.isActive.isTrue) + .and(member.id.eq(memberId)) + ) + .fetchFirst() != null + } } 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..b8e5415 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 @@ -190,15 +190,20 @@ class CreatorCommunityService( ?: false val likeCount = likeRepository.totalCountCommunityPostLikeByPostId(it.id) val commentCount = if (it.isCommentAvailable) { - commentRepository.totalCountCommentByPostId(postId = it.id) + commentRepository.totalCountCommentByPostId( + postId = it.id, + memberId = memberId, + isContentCreator = it.creatorId == memberId + ) } else { 0 } val commentList = if (it.isCommentAvailable) { commentRepository.findByPostId( - cloudFrontHost = imageHost, - timezone = timezone, id = it.id, + memberId = memberId, + isContentCreator = it.creatorId == memberId, + timezone = timezone, offset = 0, limit = 1 ) @@ -212,7 +217,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 ( ( @@ -263,15 +268,20 @@ class CreatorCommunityService( val isLike = likeRepository.findByPostIdAndMemberId(postId = post.id, memberId = memberId)?.isActive ?: false val likeCount = likeRepository.totalCountCommunityPostLikeByPostId(post.id) val commentCount = if (post.isCommentAvailable) { - commentRepository.totalCountCommentByPostId(postId = post.id) + commentRepository.totalCountCommentByPostId( + postId = post.id, + memberId = memberId, + isContentCreator = post.creatorId == memberId + ) } else { 0 } val commentList = if (post.isCommentAvailable) { commentRepository.findByPostId( - cloudFrontHost = imageHost, - timezone = timezone, id = post.id, + memberId = memberId, + isContentCreator = post.creatorId == memberId, + timezone = timezone, offset = 0, limit = 1 ) @@ -285,7 +295,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 +357,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 @@ -390,19 +411,25 @@ class CreatorCommunityService( fun getCommunityPostCommentList( postId: Long, + memberId: Long, timezone: String, offset: Long, limit: Long ): GetCommunityPostCommentListResponse { val commentList = commentRepository.findByPostId( - cloudFrontHost = imageHost, - timezone = timezone, id = postId, + memberId = memberId, + isContentCreator = repository.isCommunityCreator(postId, memberId), + timezone = timezone, offset = offset, limit = limit ) - val totalCount = commentRepository.totalCountCommentByPostId(postId = postId) + val totalCount = commentRepository.totalCountCommentByPostId( + postId = postId, + memberId = memberId, + isContentCreator = repository.isCommunityCreator(postId, memberId) + ) return GetCommunityPostCommentListResponse(totalCount = totalCount, items = commentList) } @@ -413,7 +440,6 @@ class CreatorCommunityService( limit: Long ): GetCommunityPostCommentListResponse { val commentList = commentRepository.getCommunityCommentReplyList( - cloudFrontHost = imageHost, commentId = commentId, timezone = timezone, offset = offset, @@ -443,15 +469,20 @@ class CreatorCommunityService( 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) + commentRepository.totalCountCommentByPostId( + postId = it.id, + memberId = memberId, + isContentCreator = it.creatorId == memberId + ) } else { 0 } val commentList = if (it.isCommentAvailable) { commentRepository.findByPostId( - cloudFrontHost = imageHost, - timezone = timezone, id = it.id, + memberId = memberId, + isContentCreator = it.creatorId == memberId, + timezone = timezone, offset = 0, limit = 1 ) @@ -465,7 +496,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 +530,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( @@ -514,15 +545,20 @@ class CreatorCommunityService( val isLike = likeRepository.findByPostIdAndMemberId(postId = post.id!!, memberId = memberId)?.isActive ?: false val likeCount = likeRepository.totalCountCommunityPostLikeByPostId(post.id!!) val commentCount = if (post.isCommentAvailable) { - commentRepository.totalCountCommentByPostId(postId = post.id!!) + commentRepository.totalCountCommentByPostId( + postId = post.id!!, + memberId = memberId, + isContentCreator = false + ) } else { 0 } val commentList = if (post.isCommentAvailable) { commentRepository.findByPostId( - cloudFrontHost = imageHost, - timezone = timezone, id = post.id!!, + memberId = memberId, + isContentCreator = false, + timezone = timezone, offset = 0, limit = 1 ) 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) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreatorCommunityCommentRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreatorCommunityCommentRepository.kt index 2ee60bd..d6390ff 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreatorCommunityCommentRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/CreatorCommunityCommentRepository.kt @@ -1,29 +1,34 @@ package kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment +import com.querydsl.core.types.dsl.Expressions import com.querydsl.jpa.impl.JPAQueryFactory import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment.QCreatorCommunityComment.creatorCommunityComment +import org.springframework.beans.factory.annotation.Value import org.springframework.data.jpa.repository.JpaRepository -import java.time.ZoneId -import java.time.format.DateTimeFormatter +import java.time.LocalDateTime interface CreatorCommunityCommentRepository : JpaRepository, CreatorCommunityCommentQueryRepository interface CreatorCommunityCommentQueryRepository { fun findByPostId( - cloudFrontHost: String, - timezone: String, id: Long, + memberId: Long, + isContentCreator: Boolean, + timezone: String, offset: Long, limit: Long ): List fun commentReplyCountByCommentId(commentId: Long): Int - fun totalCountCommentByPostId(postId: Long): Int + fun totalCountCommentByPostId( + postId: Long, + memberId: Long, + isContentCreator: Boolean + ): Int fun getCommunityCommentReplyList( - cloudFrontHost: String, commentId: Long, timezone: String, offset: Long, @@ -32,47 +37,65 @@ interface CreatorCommunityCommentQueryRepository { } class CreatorCommunityCommentQueryRepositoryImpl( - private val queryFactory: JPAQueryFactory + private val queryFactory: JPAQueryFactory, + + @Value("\${cloud.aws.cloud-front.host}") + private val imageHost: String ) : CreatorCommunityCommentQueryRepository { override fun findByPostId( - cloudFrontHost: String, - timezone: String, id: Long, + memberId: Long, + isContentCreator: Boolean, + timezone: String, offset: Long, limit: Long ): List { - return queryFactory - .selectFrom(creatorCommunityComment) - .where( - creatorCommunityComment.isActive.isTrue - .and(creatorCommunityComment.creatorCommunity.id.eq(id)) - .and(creatorCommunityComment.parent.isNull) + val formattedDate = Expressions.stringTemplate( + "DATE_FORMAT({0}, {1})", + Expressions.dateTimeTemplate( + LocalDateTime::class.java, + "CONVERT_TZ({0},{1},{2})", + creatorCommunityComment.createdAt, + "UTC", + timezone + ), + "%Y.%m.%d %W %h:%i %p" + ) + + var where = creatorCommunityComment.isActive.isTrue + .and(creatorCommunityComment.creatorCommunity.id.eq(id)) + .and(creatorCommunityComment.parent.isNull) + + if (!isContentCreator) { + where = where.and( + creatorCommunityComment.isSecret.isFalse + .or(creatorCommunityComment.member.id.eq(memberId)) ) + } + + return queryFactory + .select( + QGetCommunityPostCommentListItem( + creatorCommunityComment.id, + creatorCommunityComment.member.id, + creatorCommunityComment.member.nickname, + creatorCommunityComment.member.profileImage.prepend("/").prepend(imageHost), + creatorCommunityComment.comment, + creatorCommunityComment.isSecret, + formattedDate, + Expressions.constant(0) + ) + ) + .from(creatorCommunityComment) + .where(where) .offset(offset) .limit(limit) .orderBy(creatorCommunityComment.createdAt.desc()) .fetch() - .asSequence() .map { - val date = it.createdAt!! - .atZone(ZoneId.of("UTC")) - .withZoneSameInstant(ZoneId.of(timezone)) - - GetCommunityPostCommentListItem( - id = it.id!!, - writerId = it.member!!.id!!, - nickname = it.member!!.nickname, - profileUrl = if (it.member!!.profileImage != null) { - "$cloudFrontHost/${it.member!!.profileImage}" - } else { - "$cloudFrontHost/profile/default-profile.png" - }, - comment = it.comment, - date = date.format(DateTimeFormatter.ofPattern("yyyy.MM.dd E hh:mm a")), - replyCount = commentReplyCountByCommentId(it.id!!) - ) + it.replyCount = commentReplyCountByCommentId(it.id) + it } - .toList() } override fun commentReplyCountByCommentId(commentId: Long): Int { @@ -87,27 +110,61 @@ class CreatorCommunityCommentQueryRepositoryImpl( .size } - override fun totalCountCommentByPostId(postId: Long): Int { + override fun totalCountCommentByPostId( + postId: Long, + memberId: Long, + isContentCreator: Boolean + ): Int { + var where = creatorCommunityComment.creatorCommunity.id.eq(postId) + .and(creatorCommunityComment.isActive.isTrue) + .and(creatorCommunityComment.parent.isNull) + + if (!isContentCreator) { + where = where.and( + creatorCommunityComment.isSecret.isFalse + .or(creatorCommunityComment.member.id.eq(memberId)) + ) + } + return queryFactory.select(creatorCommunityComment.id) .from(creatorCommunityComment) - .where( - creatorCommunityComment.creatorCommunity.id.eq(postId) - .and(creatorCommunityComment.isActive.isTrue) - .and(creatorCommunityComment.parent.isNull) - ) + .where(where) .fetch() .size } override fun getCommunityCommentReplyList( - cloudFrontHost: String, commentId: Long, timezone: String, offset: Long, limit: Long ): List { + val formattedDate = Expressions.stringTemplate( + "DATE_FORMAT({0}, {1})", + Expressions.dateTimeTemplate( + LocalDateTime::class.java, + "CONVERT_TZ({0},{1},{2})", + creatorCommunityComment.createdAt, + "UTC", + timezone + ), + "%Y.%m.%d %W %h:%i %p" + ) + return queryFactory - .selectFrom(creatorCommunityComment) + .select( + QGetCommunityPostCommentListItem( + creatorCommunityComment.id, + creatorCommunityComment.member.id, + creatorCommunityComment.member.nickname, + creatorCommunityComment.member.profileImage.prepend("/").prepend(imageHost), + creatorCommunityComment.comment, + creatorCommunityComment.isSecret, + formattedDate, + Expressions.constant(0) + ) + ) + .from(creatorCommunityComment) .where( creatorCommunityComment.isActive.isTrue .and(creatorCommunityComment.parent.isNotNull) @@ -117,26 +174,5 @@ class CreatorCommunityCommentQueryRepositoryImpl( .limit(limit) .orderBy(creatorCommunityComment.createdAt.desc()) .fetch() - .asSequence() - .map { - val date = it.createdAt!! - .atZone(ZoneId.of("UTC")) - .withZoneSameInstant(ZoneId.of(timezone)) - - GetCommunityPostCommentListItem( - id = it.id!!, - writerId = it.member!!.id!!, - nickname = it.member!!.nickname, - profileUrl = if (it.member!!.profileImage != null) { - "$cloudFrontHost/${it.member!!.profileImage}" - } else { - "$cloudFrontHost/profile/default-profile.png" - }, - comment = it.comment, - date = date.format(DateTimeFormatter.ofPattern("yyyy.MM.dd E hh:mm a")), - replyCount = commentReplyCountByCommentId(it.id!!) - ) - } - .toList() } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/GetCommunityPostCommentListResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/GetCommunityPostCommentListResponse.kt index 58c15a4..2d24d08 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/GetCommunityPostCommentListResponse.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/comment/GetCommunityPostCommentListResponse.kt @@ -1,16 +1,19 @@ package kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment +import com.querydsl.core.annotations.QueryProjection + data class GetCommunityPostCommentListResponse( val totalCount: Int, val items: List ) -data class GetCommunityPostCommentListItem( +data class GetCommunityPostCommentListItem @QueryProjection constructor( val id: Long, val writerId: Long, val nickname: String, val profileUrl: String, val comment: String, + val isSecret: Boolean, val date: String, - val replyCount: Int + var replyCount: Int )