크리에이터 커뮤니티 #102
|
@ -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")
|
@PostMapping("/like")
|
||||||
fun communityPostLike(
|
fun communityPostLike(
|
||||||
@RequestBody request: PostCommunityPostLikeRequest,
|
@RequestBody request: PostCommunityPostLikeRequest,
|
||||||
|
|
|
@ -17,7 +17,7 @@ interface CreatorCommunityQueryRepository {
|
||||||
isAdult: Boolean
|
isAdult: Boolean
|
||||||
): List<CreatorCommunity>
|
): List<CreatorCommunity>
|
||||||
|
|
||||||
fun findByIdAndActive(postId: Long): CreatorCommunity?
|
fun findByIdAndActive(postId: Long, isAdult: Boolean): CreatorCommunity?
|
||||||
}
|
}
|
||||||
|
|
||||||
class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CreatorCommunityQueryRepository {
|
class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CreatorCommunityQueryRepository {
|
||||||
|
@ -54,13 +54,17 @@ class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFact
|
||||||
.fetch()
|
.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
|
return queryFactory
|
||||||
.selectFrom(creatorCommunity)
|
.selectFrom(creatorCommunity)
|
||||||
.where(
|
.where(where)
|
||||||
creatorCommunity.id.eq(postId)
|
|
||||||
.and(creatorCommunity.isActive.isTrue)
|
|
||||||
)
|
|
||||||
.fetchFirst()
|
.fetchFirst()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,6 +178,8 @@ class CreatorCommunityService(
|
||||||
},
|
},
|
||||||
content = it.content,
|
content = it.content,
|
||||||
date = getTimeAgoString(it.createdAt!!),
|
date = getTimeAgoString(it.createdAt!!),
|
||||||
|
isCommentAvailable = it.isCommentAvailable,
|
||||||
|
isAdult = it.isAdult,
|
||||||
isLike = isLike,
|
isLike = isLike,
|
||||||
likeCount = likeCount,
|
likeCount = likeCount,
|
||||||
commentCount = commentCount,
|
commentCount = commentCount,
|
||||||
|
@ -187,6 +189,60 @@ class CreatorCommunityService(
|
||||||
.toList()
|
.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 {
|
private fun getTimeAgoString(dateTime: LocalDateTime): String {
|
||||||
val now = LocalDateTime.now()
|
val now = LocalDateTime.now()
|
||||||
val duration = Duration.between(dateTime, now)
|
val duration = Duration.between(dateTime, now)
|
||||||
|
@ -208,7 +264,7 @@ class CreatorCommunityService(
|
||||||
postLike = CreatorCommunityLike()
|
postLike = CreatorCommunityLike()
|
||||||
postLike.member = member
|
postLike.member = member
|
||||||
|
|
||||||
val post = repository.findByIdAndActive(request.postId)
|
val post = repository.findByIdAndActive(request.postId, isAdult = member.auth != null)
|
||||||
?: throw SodaException("잘못된 요청입니다.\n다시 시도해 주세요.")
|
?: throw SodaException("잘못된 요청입니다.\n다시 시도해 주세요.")
|
||||||
|
|
||||||
postLike.creatorCommunity = post
|
postLike.creatorCommunity = post
|
||||||
|
|
|
@ -10,6 +10,8 @@ data class GetCommunityPostListResponse @QueryProjection constructor(
|
||||||
val imageUrl: String?,
|
val imageUrl: String?,
|
||||||
val content: String,
|
val content: String,
|
||||||
val date: String,
|
val date: String,
|
||||||
|
val isCommentAvailable: Boolean,
|
||||||
|
val isAdult: Boolean,
|
||||||
val isLike: Boolean,
|
val isLike: Boolean,
|
||||||
val likeCount: Int,
|
val likeCount: Int,
|
||||||
val commentCount: Int,
|
val commentCount: Int,
|
||||||
|
|
Loading…
Reference in New Issue