커뮤니티 게시글 조회

- 응답값에 가격, 구매여부 추가
This commit is contained in:
Klaus 2024-05-23 12:32:22 +09:00
parent d241b4fa7a
commit 87f22f45aa
7 changed files with 154 additions and 46 deletions

View File

@ -86,7 +86,7 @@ class AdminContentService(
?: throw SodaException("없는 콘텐츠 입니다.")
if (request.isDefaultCoverImage) {
audioContent.coverImage = "profile/default_profile.png"
audioContent.coverImage = "`profile/default_profile.png`"
}
if (request.isActive != null) {

View File

@ -3,6 +3,7 @@ package kr.co.vividnext.sodalive.can.use
import kr.co.vividnext.sodalive.common.BaseEntity
import kr.co.vividnext.sodalive.content.AudioContent
import kr.co.vividnext.sodalive.content.order.Order
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.CreatorCommunity
import kr.co.vividnext.sodalive.live.room.LiveRoom
import kr.co.vividnext.sodalive.member.Member
import javax.persistence.CascadeType
@ -42,10 +43,14 @@ data class UseCan(
@JoinColumn(name = "order_id", nullable = true)
var order: Order? = null
@OneToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "content_id", nullable = true)
var audioContent: AudioContent? = null
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "creator_community_id", nullable = true)
var communityPost: CreatorCommunity? = null
@OneToMany(mappedBy = "useCan", cascade = [CascadeType.ALL])
val useCanCalculates: MutableList<UseCanCalculate> = mutableListOf()
}

View File

@ -1,7 +1,28 @@
package kr.co.vividnext.sodalive.can.use
import com.querydsl.jpa.impl.JPAQueryFactory
import kr.co.vividnext.sodalive.can.use.QUseCan.useCan
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface UseCanRepository : JpaRepository<UseCan, Long>
interface UseCanRepository : JpaRepository<UseCan, Long>, UseCanQueryRepository
interface UseCanQueryRepository {
fun isExistOrdered(postId: Long, memberId: Long): Boolean
}
class UseCanQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : UseCanQueryRepository {
override fun isExistOrdered(postId: Long, memberId: Long): Boolean {
val useCanId = queryFactory.select(useCan.id)
.from(useCan)
.where(
useCan.member.id.eq(memberId)
.and(useCan.isRefund.isFalse)
.and(useCan.communityPost.id.eq(postId))
)
.fetchFirst()
return useCanId != null && useCanId > 0
}
}

View File

@ -20,10 +20,10 @@ interface CreatorCommunityQueryRepository {
offset: Long,
limit: Long,
isAdult: Boolean
): List<CreatorCommunity>
): List<SelectCommunityPostResponse>
fun findByIdAndActive(postId: Long, isAdult: Boolean): CreatorCommunity?
fun getLatestPostListFromCreatorsYouFollow(memberId: Long, isAdult: Boolean): List<CreatorCommunity>
fun getLatestPostListFromCreatorsYouFollow(memberId: Long, isAdult: Boolean): List<SelectCommunityPostResponse>
}
class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CreatorCommunityQueryRepository {
@ -42,7 +42,7 @@ class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFact
offset: Long,
limit: Long,
isAdult: Boolean
): List<CreatorCommunity> {
): List<SelectCommunityPostResponse> {
var where = creatorCommunity.member.id.eq(creatorId)
.and(creatorCommunity.isActive.isTrue)
@ -51,7 +51,20 @@ class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFact
}
return queryFactory
.selectFrom(creatorCommunity)
.select(
QSelectCommunityPostResponse(
creatorCommunity.id,
creatorCommunity.member.id,
creatorCommunity.member.nickname,
creatorCommunity.member.profileImage.coalesce("profile/default_profile.png"),
creatorCommunity.imagePath,
creatorCommunity.content,
creatorCommunity.createdAt,
creatorCommunity.isCommentAvailable,
creatorCommunity.price
)
)
.from(creatorCommunity)
.innerJoin(creatorCommunity.member, member)
.where(where)
.offset(offset)
@ -74,7 +87,10 @@ class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFact
.fetchFirst()
}
override fun getLatestPostListFromCreatorsYouFollow(memberId: Long, isAdult: Boolean): List<CreatorCommunity> {
override fun getLatestPostListFromCreatorsYouFollow(
memberId: Long,
isAdult: Boolean
): List<SelectCommunityPostResponse> {
val creatorCommunity = QCreatorCommunity.creatorCommunity
val latest = QCreatorCommunity.creatorCommunity
@ -110,7 +126,21 @@ class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFact
)
return queryFactory
.selectFrom(creatorCommunity)
.select(
QSelectCommunityPostResponse(
creatorCommunity.id,
creatorCommunity.member.id,
creatorCommunity.member.nickname,
creatorCommunity.member.profileImage.coalesce("profile/default_profile.png"),
creatorCommunity.imagePath,
creatorCommunity.content,
creatorCommunity.createdAt,
creatorCommunity.isCommentAvailable,
creatorCommunity.price
)
)
.from(creatorCommunity)
.innerJoin(creatorCommunity.member, member)
.where(where)
.orderBy(creatorCommunity.createdAt.desc())
.limit(10)

View File

@ -3,6 +3,7 @@ package kr.co.vividnext.sodalive.explorer.profile.creatorCommunity
import com.amazonaws.services.s3.model.ObjectMetadata
import com.fasterxml.jackson.databind.ObjectMapper
import kr.co.vividnext.sodalive.aws.s3.S3Uploader
import kr.co.vividnext.sodalive.can.use.UseCanRepository
import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment.CreatorCommunityComment
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.comment.CreatorCommunityCommentRepository
@ -32,6 +33,7 @@ class CreatorCommunityService(
private val blockMemberRepository: BlockMemberRepository,
private val likeRepository: CreatorCommunityLikeRepository,
private val commentRepository: CreatorCommunityCommentRepository,
private val useCanRepository: UseCanRepository,
private val s3Uploader: S3Uploader,
private val objectMapper: ObjectMapper,
@ -138,6 +140,10 @@ class CreatorCommunityService(
limit: Long,
isAdult: Boolean
): List<GetCommunityPostListResponse> {
if (blockMemberRepository.isBlocked(blockedMemberId = memberId, memberId = creatorId)) {
return listOf()
}
val postList = repository.getCommunityPostList(
creatorId = creatorId,
offset = offset,
@ -147,18 +153,12 @@ class CreatorCommunityService(
return postList
.asSequence()
.filter {
!blockMemberRepository.isBlocked(
blockedMemberId = memberId,
memberId = creatorId
)
}
.map {
val isLike =
likeRepository.findByPostIdAndMemberId(postId = it.id!!, memberId = memberId)?.isActive ?: false
val likeCount = likeRepository.totalCountCommunityPostLikeByPostId(it.id!!)
val isLike = likeRepository.findByPostIdAndMemberId(postId = it.id, memberId = memberId)?.isActive
?: false
val likeCount = likeRepository.totalCountCommunityPostLikeByPostId(it.id)
val commentCount = if (it.isCommentAvailable) {
commentRepository.totalCountCommentByPostId(postId = it.id!!)
commentRepository.totalCountCommentByPostId(postId = it.id)
} else {
0
}
@ -166,7 +166,7 @@ class CreatorCommunityService(
commentRepository.findByPostId(
cloudFrontHost = imageHost,
timezone = timezone,
id = it.id!!,
id = it.id,
offset = 0,
limit = 1
)
@ -180,25 +180,35 @@ class CreatorCommunityService(
null
}
GetCommunityPostListResponse(
postId = it.id!!,
creatorId = it.member!!.id!!,
creatorNickname = it.member!!.nickname,
creatorProfileUrl = if (it.member!!.profileImage != null) {
"$imageHost/${it.member!!.profileImage}"
val existOrdered = useCanRepository.isExistOrdered(postId = it.id, memberId = memberId)
val content = if (it.price > 0) {
if (existOrdered) {
it.content
} else {
"$imageHost/profile/default-profile.png"
},
it.content.substring(0, 5).plus("...")
}
} else {
it.content
}
GetCommunityPostListResponse(
postId = it.id,
creatorId = it.creatorId,
creatorNickname = it.creatorNickname,
creatorProfileUrl = "$imageHost/${it.creatorProfileUrl}",
imageUrl = if (it.imagePath != null) {
"$imageHost/${it.imagePath!!}"
"$imageHost/${it.imagePath}"
} else {
null
},
content = it.content,
date = getTimeAgoString(it.createdAt!!),
content = content,
price = it.price,
date = getTimeAgoString(it.date),
isCommentAvailable = it.isCommentAvailable,
isAdult = it.isAdult,
isAdult = false,
isLike = isLike,
existOrdered = existOrdered,
likeCount = likeCount,
commentCount = commentCount,
firstComment = firstComment
@ -244,6 +254,18 @@ class CreatorCommunityService(
null
}
val existOrdered = useCanRepository.isExistOrdered(postId = post.id!!, memberId = memberId)
val content = if (post.price > 0) {
if (existOrdered) {
post.content
} else {
post.content.substring(0, 5).plus("...")
}
} else {
post.content
}
return GetCommunityPostListResponse(
postId = post.id!!,
creatorId = post.member!!.id!!,
@ -258,11 +280,13 @@ class CreatorCommunityService(
} else {
null
},
content = post.content,
content = content,
price = post.price,
date = getTimeAgoString(post.createdAt!!),
isCommentAvailable = post.isCommentAvailable,
isAdult = post.isAdult,
isLike = isLike,
existOrdered = existOrdered,
likeCount = likeCount,
commentCount = commentCount,
firstComment = firstComment
@ -392,7 +416,7 @@ class CreatorCommunityService(
.filter {
!blockMemberRepository.isBlocked(
blockedMemberId = memberId,
memberId = it.member!!.id!!
memberId = it.creatorId
)
}
.map {
@ -422,25 +446,35 @@ class CreatorCommunityService(
null
}
GetCommunityPostListResponse(
postId = it.id!!,
creatorId = it.member!!.id!!,
creatorNickname = it.member!!.nickname,
creatorProfileUrl = if (it.member!!.profileImage != null) {
"$imageHost/${it.member!!.profileImage}"
val existOrdered = useCanRepository.isExistOrdered(postId = it.id, memberId = memberId)
val content = if (it.price > 0) {
if (existOrdered) {
it.content
} else {
"$imageHost/profile/default-profile.png"
},
it.content.substring(0, 5).plus("...")
}
} else {
it.content
}
GetCommunityPostListResponse(
postId = it.id,
creatorId = it.creatorId,
creatorNickname = it.creatorNickname,
creatorProfileUrl = "$imageHost/${it.creatorProfileUrl}",
imageUrl = if (it.imagePath != null) {
"$imageHost/${it.imagePath!!}"
"$imageHost/${it.imagePath}"
} else {
null
},
content = it.content,
date = getTimeAgoString(it.createdAt!!),
content = content,
price = it.price,
date = getTimeAgoString(it.date),
isCommentAvailable = it.isCommentAvailable,
isAdult = it.isAdult,
isAdult = false,
isLike = isLike,
existOrdered = existOrdered,
likeCount = likeCount,
commentCount = commentCount,
firstComment = firstComment

View File

@ -10,10 +10,12 @@ data class GetCommunityPostListResponse @QueryProjection constructor(
val creatorProfileUrl: String,
val imageUrl: String?,
val content: String,
val price: Int,
val date: String,
val isCommentAvailable: Boolean,
val isAdult: Boolean,
val isLike: Boolean,
val existOrdered: Boolean,
val likeCount: Int,
val commentCount: Int,
val firstComment: GetCommunityPostCommentListItem?

View File

@ -0,0 +1,16 @@
package kr.co.vividnext.sodalive.explorer.profile.creatorCommunity
import com.querydsl.core.annotations.QueryProjection
import java.time.LocalDateTime
data class SelectCommunityPostResponse @QueryProjection constructor(
val id: Long,
val creatorId: Long,
val creatorNickname: String,
val creatorProfileUrl: String,
val imagePath: String?,
val content: String,
val date: LocalDateTime,
val isCommentAvailable: Boolean,
val price: Int
)