diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/content/AdminContentService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/content/AdminContentService.kt index 5b3e8a7..0edf5ab 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/content/AdminContentService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/content/AdminContentService.kt @@ -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) { diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCan.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCan.kt index 683492a..916d4b0 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCan.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCan.kt @@ -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 = mutableListOf() } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCanRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCanRepository.kt index f30429a..eeac478 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCanRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/can/use/UseCanRepository.kt @@ -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 +interface UseCanRepository : JpaRepository, 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 + } +} diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityRepository.kt index d4cd6b5..8c345db 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/CreatorCommunityRepository.kt @@ -20,10 +20,10 @@ interface CreatorCommunityQueryRepository { offset: Long, limit: Long, isAdult: Boolean - ): List + ): List fun findByIdAndActive(postId: Long, isAdult: Boolean): CreatorCommunity? - fun getLatestPostListFromCreatorsYouFollow(memberId: Long, isAdult: Boolean): List + fun getLatestPostListFromCreatorsYouFollow(memberId: Long, isAdult: Boolean): List } class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CreatorCommunityQueryRepository { @@ -42,7 +42,7 @@ class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFact offset: Long, limit: Long, isAdult: Boolean - ): List { + ): List { 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 { + override fun getLatestPostListFromCreatorsYouFollow( + memberId: Long, + isAdult: Boolean + ): List { 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) 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 db6e7a7..f1f6633 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 @@ -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 { + 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 diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/GetCommunityPostListResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/GetCommunityPostListResponse.kt index 4aed806..b4b9b94 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/GetCommunityPostListResponse.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/GetCommunityPostListResponse.kt @@ -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? diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/SelectCommunityPostResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/SelectCommunityPostResponse.kt new file mode 100644 index 0000000..89a953a --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/explorer/profile/creatorCommunity/SelectCommunityPostResponse.kt @@ -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 +)