커뮤니티 게시물 조회 상세 API 추가
This commit is contained in:
		| @@ -85,6 +85,24 @@ class CreatorCommunityController(private val service: CreatorCommunityService) { | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/{id}") | ||||
|     fun getCommunityPostDetail( | ||||
|         @PathVariable("id") postId: Long, | ||||
|         @RequestParam timezone: String, | ||||
|         @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? | ||||
|     ) = run { | ||||
|         if (member == null) throw SodaException("로그인 정보를 확인해주세요.") | ||||
|  | ||||
|         ApiResponse.ok( | ||||
|             service.getCommunityPostDetail( | ||||
|                 postId = postId, | ||||
|                 memberId = member.id!!, | ||||
|                 timezone = timezone, | ||||
|                 isAdult = member.auth != null | ||||
|             ) | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|     @PostMapping("/like") | ||||
|     fun communityPostLike( | ||||
|         @RequestBody request: PostCommunityPostLikeRequest, | ||||
|   | ||||
| @@ -17,7 +17,7 @@ interface CreatorCommunityQueryRepository { | ||||
|         isAdult: Boolean | ||||
|     ): List<CreatorCommunity> | ||||
|  | ||||
|     fun findByIdAndActive(postId: Long): CreatorCommunity? | ||||
|     fun findByIdAndActive(postId: Long, isAdult: Boolean): CreatorCommunity? | ||||
| } | ||||
|  | ||||
| class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CreatorCommunityQueryRepository { | ||||
| @@ -54,13 +54,17 @@ class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFact | ||||
|             .fetch() | ||||
|     } | ||||
|  | ||||
|     override fun findByIdAndActive(postId: Long): CreatorCommunity? { | ||||
|     override fun findByIdAndActive(postId: Long, isAdult: Boolean): CreatorCommunity? { | ||||
|         var where = creatorCommunity.id.eq(postId) | ||||
|             .and(creatorCommunity.isActive.isTrue) | ||||
|  | ||||
|         if (!isAdult) { | ||||
|             where = where.and(creatorCommunity.isAdult.isFalse) | ||||
|         } | ||||
|  | ||||
|         return queryFactory | ||||
|             .selectFrom(creatorCommunity) | ||||
|             .where( | ||||
|                 creatorCommunity.id.eq(postId) | ||||
|                     .and(creatorCommunity.isActive.isTrue) | ||||
|             ) | ||||
|             .where(where) | ||||
|             .fetchFirst() | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -178,6 +178,8 @@ class CreatorCommunityService( | ||||
|                     }, | ||||
|                     content = it.content, | ||||
|                     date = getTimeAgoString(it.createdAt!!), | ||||
|                     isCommentAvailable = it.isCommentAvailable, | ||||
|                     isAdult = it.isAdult, | ||||
|                     isLike = isLike, | ||||
|                     likeCount = likeCount, | ||||
|                     commentCount = commentCount, | ||||
| @@ -187,6 +189,60 @@ class CreatorCommunityService( | ||||
|             .toList() | ||||
|     } | ||||
|  | ||||
|     fun getCommunityPostDetail( | ||||
|         postId: Long, | ||||
|         memberId: Long, | ||||
|         timezone: String, | ||||
|         isAdult: Boolean | ||||
|     ): GetCommunityPostListResponse { | ||||
|         val post = repository.findByIdAndActive(postId, isAdult = isAdult) | ||||
|             ?: throw SodaException("잘못된 요청입니다.\n다시 시도해 주세요.") | ||||
|  | ||||
|         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!!) | ||||
|         } else { | ||||
|             0 | ||||
|         } | ||||
|         val commentList = commentRepository.findByPostId( | ||||
|             cloudFrontHost = imageHost, | ||||
|             timezone = timezone, | ||||
|             id = post.id!!, | ||||
|             offset = 0, | ||||
|             limit = 1 | ||||
|         ) | ||||
|  | ||||
|         val firstComment = if (commentList.isNotEmpty()) { | ||||
|             commentList[0] | ||||
|         } else { | ||||
|             null | ||||
|         } | ||||
|  | ||||
|         return GetCommunityPostListResponse( | ||||
|             postId = post.id!!, | ||||
|             creatorNickname = post.member!!.nickname, | ||||
|             creatorProfileUrl = if (post.member!!.profileImage != null) { | ||||
|                 "$imageHost/${post.member!!.profileImage}" | ||||
|             } else { | ||||
|                 "$imageHost/profile/default-profile.png" | ||||
|             }, | ||||
|             imageUrl = if (post.imagePath != null) { | ||||
|                 "$imageHost/${post.imagePath!!}" | ||||
|             } else { | ||||
|                 null | ||||
|             }, | ||||
|             content = post.content, | ||||
|             date = getTimeAgoString(post.createdAt!!), | ||||
|             isCommentAvailable = post.isCommentAvailable, | ||||
|             isAdult = post.isAdult, | ||||
|             isLike = isLike, | ||||
|             likeCount = likeCount, | ||||
|             commentCount = commentCount, | ||||
|             firstComment = firstComment | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|     private fun getTimeAgoString(dateTime: LocalDateTime): String { | ||||
|         val now = LocalDateTime.now() | ||||
|         val duration = Duration.between(dateTime, now) | ||||
| @@ -208,7 +264,7 @@ class CreatorCommunityService( | ||||
|             postLike = CreatorCommunityLike() | ||||
|             postLike.member = member | ||||
|  | ||||
|             val post = repository.findByIdAndActive(request.postId) | ||||
|             val post = repository.findByIdAndActive(request.postId, isAdult = member.auth != null) | ||||
|                 ?: throw SodaException("잘못된 요청입니다.\n다시 시도해 주세요.") | ||||
|  | ||||
|             postLike.creatorCommunity = post | ||||
|   | ||||
| @@ -10,6 +10,8 @@ data class GetCommunityPostListResponse @QueryProjection constructor( | ||||
|     val imageUrl: String?, | ||||
|     val content: String, | ||||
|     val date: String, | ||||
|     val isCommentAvailable: Boolean, | ||||
|     val isAdult: Boolean, | ||||
|     val isLike: Boolean, | ||||
|     val likeCount: Int, | ||||
|     val commentCount: Int, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user