fix: 커뮤니티 댓글 조회
- 크리에이터가 아닌 경우 내가 쓴 비밀댓글 + 일반댓글만 조회되도록 수정
This commit is contained in:
parent
8e01ced1f5
commit
6d2f48f86d
|
@ -159,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()
|
||||
|
|
|
@ -28,6 +28,8 @@ interface CreatorCommunityQueryRepository {
|
|||
fun getLatestPostListFromCreatorsYouFollow(memberId: Long, isAdult: Boolean): List<SelectCommunityPostResponse>
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -401,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)
|
||||
}
|
||||
|
||||
|
@ -424,7 +440,6 @@ class CreatorCommunityService(
|
|||
limit: Long
|
||||
): GetCommunityPostCommentListResponse {
|
||||
val commentList = commentRepository.getCommunityCommentReplyList(
|
||||
cloudFrontHost = imageHost,
|
||||
commentId = commentId,
|
||||
timezone = timezone,
|
||||
offset = offset,
|
||||
|
@ -454,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
|
||||
)
|
||||
|
@ -525,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
|
||||
)
|
||||
|
|
|
@ -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<CreatorCommunityComment, Long>, CreatorCommunityCommentQueryRepository
|
||||
|
||||
interface CreatorCommunityCommentQueryRepository {
|
||||
fun findByPostId(
|
||||
cloudFrontHost: String,
|
||||
timezone: String,
|
||||
id: Long,
|
||||
memberId: Long,
|
||||
isContentCreator: Boolean,
|
||||
timezone: String,
|
||||
offset: Long,
|
||||
limit: Long
|
||||
): List<GetCommunityPostCommentListItem>
|
||||
|
||||
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,64 @@ 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<GetCommunityPostCommentListItem> {
|
||||
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(imageHost),
|
||||
creatorCommunityComment.comment,
|
||||
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 +109,60 @@ 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<GetCommunityPostCommentListItem> {
|
||||
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(imageHost),
|
||||
creatorCommunityComment.comment,
|
||||
formattedDate,
|
||||
Expressions.constant(0)
|
||||
)
|
||||
)
|
||||
.from(creatorCommunityComment)
|
||||
.where(
|
||||
creatorCommunityComment.isActive.isTrue
|
||||
.and(creatorCommunityComment.parent.isNotNull)
|
||||
|
@ -117,26 +172,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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
package kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment
|
||||
|
||||
import com.querydsl.core.annotations.QueryProjection
|
||||
|
||||
data class GetCommunityPostCommentListResponse(
|
||||
val totalCount: Int,
|
||||
val items: List<GetCommunityPostCommentListItem>
|
||||
)
|
||||
|
||||
data class GetCommunityPostCommentListItem(
|
||||
data class GetCommunityPostCommentListItem @QueryProjection constructor(
|
||||
val id: Long,
|
||||
val writerId: Long,
|
||||
val nickname: String,
|
||||
val profileUrl: String,
|
||||
val comment: String,
|
||||
val date: String,
|
||||
val replyCount: Int
|
||||
var replyCount: Int
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue