커뮤니티 댓글 - 답글 리스트 API 추가
This commit is contained in:
parent
25022e4909
commit
29c7d5c677
|
@ -142,4 +142,23 @@ class CreatorCommunityController(private val service: CreatorCommunityService) {
|
|||
)
|
||||
)
|
||||
}
|
||||
|
||||
@GetMapping("/comment/{id}")
|
||||
fun getCommentReplyList(
|
||||
@PathVariable("id") commentId: Long,
|
||||
@RequestParam timezone: String,
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
|
||||
pageable: Pageable
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(
|
||||
service.getCommentReplyList(
|
||||
commentId = commentId,
|
||||
timezone = timezone,
|
||||
offset = pageable.offset,
|
||||
limit = pageable.pageSize.toLong()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -275,4 +275,22 @@ class CreatorCommunityService(
|
|||
val totalCount = commentRepository.totalCountCommentByPostId(postId = postId)
|
||||
return GetCommunityPostCommentListResponse(totalCount = totalCount, items = commentList)
|
||||
}
|
||||
|
||||
fun getCommentReplyList(
|
||||
commentId: Long,
|
||||
timezone: String,
|
||||
offset: Long,
|
||||
limit: Long
|
||||
): GetCommunityPostCommentListResponse {
|
||||
val commentList = commentRepository.getCommunityCommentReplyList(
|
||||
cloudFrontHost = imageHost,
|
||||
commentId = commentId,
|
||||
timezone = timezone,
|
||||
offset = offset,
|
||||
limit = limit
|
||||
)
|
||||
|
||||
val totalCount = commentRepository.commentReplyCountByCommentId(commentId)
|
||||
return GetCommunityPostCommentListResponse(totalCount = totalCount, items = commentList)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,14 @@ interface CreatorCommunityCommentQueryRepository {
|
|||
fun commentReplyCountByCommentId(commentId: Long): Int
|
||||
|
||||
fun totalCountCommentByPostId(postId: Long): Int
|
||||
|
||||
fun getCommunityCommentReplyList(
|
||||
cloudFrontHost: String,
|
||||
commentId: Long,
|
||||
timezone: String,
|
||||
offset: Long,
|
||||
limit: Long
|
||||
): List<GetCommunityPostCommentListItem>
|
||||
}
|
||||
|
||||
class CreatorCommunityCommentQueryRepositoryImpl(
|
||||
|
@ -89,4 +97,45 @@ class CreatorCommunityCommentQueryRepositoryImpl(
|
|||
.fetch()
|
||||
.size
|
||||
}
|
||||
|
||||
override fun getCommunityCommentReplyList(
|
||||
cloudFrontHost: String,
|
||||
commentId: Long,
|
||||
timezone: String,
|
||||
offset: Long,
|
||||
limit: Long
|
||||
): List<GetCommunityPostCommentListItem> {
|
||||
return queryFactory
|
||||
.selectFrom(creatorCommunityComment)
|
||||
.where(
|
||||
creatorCommunityComment.isActive.isTrue
|
||||
.and(creatorCommunityComment.parent.isNotNull)
|
||||
.and(creatorCommunityComment.parent.id.eq(commentId))
|
||||
)
|
||||
.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!!)
|
||||
)
|
||||
}
|
||||
.toList()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue