From e4ca84252de46268b8de1cc5b188fb90c89103e0 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 21 Dec 2023 22:35:52 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8C=94=EB=A1=9C=EC=9A=B0=20=ED=95=9C=20?= =?UTF-8?q?=ED=81=AC=EB=A6=AC=EC=97=90=EC=9D=B4=ED=84=B0=EC=9D=98=207?= =?UTF-8?q?=EC=9D=BC=20=EC=9D=B4=EB=82=B4=EC=9D=98=20=EC=BB=A4=EB=AE=A4?= =?UTF-8?q?=EB=8B=88=ED=8B=B0=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=2010=EA=B0=9C?= =?UTF-8?q?=20=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0=20API=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreatorCommunityController.kt | 16 +++++ .../CreatorCommunityRepository.kt | 43 ++++++++++++++ .../CreatorCommunityService.kt | 58 +++++++++++++++++++ 3 files changed, 117 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 7aa36dc..9c18a29 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 @@ -179,4 +179,20 @@ class CreatorCommunityController(private val service: CreatorCommunityService) { ) ) } + + @GetMapping("/latest") + fun getLatestPostListFromCreatorsYouFollow( + @RequestParam timezone: String, + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? + ) = run { + if (member == null) throw SodaException("로그인 정보를 확인해주세요.") + + ApiResponse.ok( + service.getLatestPostListFromCreatorsYouFollow( + timezone = timezone, + memberId = member.id!!, + isAdult = member.auth != null + ) + ) + } } 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 c0d3d35..1ebc02a 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 @@ -1,9 +1,12 @@ package kr.co.vividnext.sodalive.explorer.profile.creatorCommunity +import com.querydsl.core.types.dsl.Expressions import com.querydsl.jpa.impl.JPAQueryFactory import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.QCreatorCommunity.creatorCommunity import kr.co.vividnext.sodalive.member.QMember.member +import kr.co.vividnext.sodalive.member.following.QCreatorFollowing.creatorFollowing import org.springframework.data.jpa.repository.JpaRepository +import java.time.LocalDateTime interface CreatorCommunityRepository : JpaRepository, CreatorCommunityQueryRepository @@ -18,6 +21,7 @@ interface CreatorCommunityQueryRepository { ): List fun findByIdAndActive(postId: Long, isAdult: Boolean): CreatorCommunity? + fun getLatestPostListFromCreatorsYouFollow(memberId: Long, isAdult: Boolean): List } class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : CreatorCommunityQueryRepository { @@ -67,4 +71,43 @@ class CreatorCommunityQueryRepositoryImpl(private val queryFactory: JPAQueryFact .where(where) .fetchFirst() } + + override fun getLatestPostListFromCreatorsYouFollow(memberId: Long, isAdult: Boolean): List { + val creatorCommunity = QCreatorCommunity.creatorCommunity + val latest = QCreatorCommunity.creatorCommunity + + var where = creatorCommunity.isActive.isTrue + .and(creatorCommunity.createdAt.after(LocalDateTime.now().minusDays(7))) + + if (!isAdult) { + where = where.and(creatorCommunity.isAdult.isFalse) + } + + val subQuery = queryFactory + .select(latest.member.id, latest.createdAt.max().`as`("maxCreatedAt")) + .from(latest) + .groupBy(latest.member.id) + + where = where.and( + Expressions.list(creatorCommunity.member.id, creatorCommunity.createdAt).`in`(subQuery) + ) + + val memberSubQuery = queryFactory + .select(creatorFollowing.creator.id) + .from(creatorFollowing) + .where(creatorFollowing.member.id.eq(memberId)) + + where = where.and( + creatorCommunity.member.id.`in`(memberSubQuery) + ) + + return queryFactory + .selectFrom(creatorCommunity) + .innerJoin(creatorCommunity.member, member) + .innerJoin(member) + .where(where) + .orderBy(creatorCommunity.createdAt.desc()) + .limit(10) + .fetch() + } } 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 5c7bf25..c4ff494 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 @@ -353,4 +353,62 @@ class CreatorCommunityService( val totalCount = commentRepository.commentReplyCountByCommentId(commentId) return GetCommunityPostCommentListResponse(totalCount = totalCount, items = commentList) } + + fun getLatestPostListFromCreatorsYouFollow( + timezone: String, + memberId: Long, + isAdult: Boolean + ): List { + val postList = repository.getLatestPostListFromCreatorsYouFollow(memberId = memberId, isAdult = isAdult) + + return postList + .asSequence() + .map { + 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!!) + } else { + 0 + } + val commentList = commentRepository.findByPostId( + cloudFrontHost = imageHost, + timezone = timezone, + id = it.id!!, + offset = 0, + limit = 1 + ) + + val firstComment = if (commentList.isNotEmpty()) { + commentList[0] + } else { + null + } + + GetCommunityPostListResponse( + postId = it.id!!, + creatorNickname = it.member!!.nickname, + creatorProfileUrl = if (it.member!!.profileImage != null) { + "$imageHost/${it.member!!.profileImage}" + } else { + "$imageHost/profile/default-profile.png" + }, + imageUrl = if (it.imagePath != null) { + "$imageHost/${it.imagePath!!}" + } else { + null + }, + content = it.content, + date = getTimeAgoString(it.createdAt!!), + isCommentAvailable = it.isCommentAvailable, + isAdult = it.isAdult, + isLike = isLike, + likeCount = likeCount, + commentCount = commentCount, + firstComment = firstComment + ) + } + .toList() + } }