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 348bed8..3d42e9d 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 @@ -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() + ) + ) + } } 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 5bff567..2916c97 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 @@ -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) + } } 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 265d9d1..ee46c5a 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 @@ -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 } class CreatorCommunityCommentQueryRepositoryImpl( @@ -89,4 +97,45 @@ class CreatorCommunityCommentQueryRepositoryImpl( .fetch() .size } + + override fun getCommunityCommentReplyList( + cloudFrontHost: String, + commentId: Long, + timezone: String, + offset: Long, + limit: Long + ): List { + 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() + } }