From 29c7d5c6777a990aab30b47ab4f802d2e1a142b1 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 20 Dec 2023 20:27:04 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0=20?= =?UTF-8?q?=EB=8C=93=EA=B8=80=20-=20=EB=8B=B5=EA=B8=80=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreatorCommunityController.kt | 19 +++++++ .../CreatorCommunityService.kt | 18 +++++++ .../CreatorCommunityCommentRepository.kt | 49 +++++++++++++++++++ 3 files changed, 86 insertions(+) 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() + } }