From 5890f9932b47d26236459234b198608a8a0e2056 Mon Sep 17 00:00:00 2001 From: Klaus Date: Wed, 14 Feb 2024 00:02:17 +0900 Subject: [PATCH] =?UTF-8?q?=ED=85=8C=EB=A7=88=EB=B3=84=20=EC=BD=98?= =?UTF-8?q?=ED=85=90=EC=B8=A0=20=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0=20API?= =?UTF-8?q?=20-=20=EC=B4=9D=20=EA=B0=9C=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content/AudioContentRepository.kt | 32 +++++++++++++++++++ .../content/theme/AudioContentThemeService.kt | 7 ++++ .../content/GetContentByThemeResponse.kt | 1 + 3 files changed, 40 insertions(+) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentRepository.kt index b896e68..f7a02fb 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/AudioContentRepository.kt @@ -68,6 +68,12 @@ interface AudioContentQueryRepository { limit: Long = 20 ): List + fun totalCountByTheme( + memberId: Long, + theme: String = "", + isAdult: Boolean = false + ): Int + fun findByThemeFor2Weeks( cloudfrontHost: String, memberId: Long, @@ -367,6 +373,32 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) .fetch() } + override fun totalCountByTheme(memberId: Long, theme: String, isAdult: Boolean): Int { + var where = audioContent.isActive.isTrue + .and( + audioContent.releaseDate.isNull + .or(audioContent.releaseDate.loe(LocalDateTime.now())) + .or(audioContent.member.id.eq(memberId)) + ) + + if (!isAdult) { + where = where.and(audioContent.isAdult.isFalse) + } + + if (theme.isNotBlank()) { + where = where.and(audioContentTheme.theme.eq(theme)) + } + + return queryFactory + .select(audioContent.id) + .from(audioContent) + .innerJoin(audioContent.member, member) + .innerJoin(audioContent.theme, audioContentTheme) + .where(where) + .fetch() + .size + } + override fun totalCountNewContentFor2Weeks(theme: String, memberId: Long, isAdult: Boolean): Int { var where = audioContent.isActive.isTrue .and(audioContent.releaseDate.goe(LocalDateTime.now().minusWeeks(2))) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/theme/AudioContentThemeService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/theme/AudioContentThemeService.kt index cbee2f4..64f600b 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/theme/AudioContentThemeService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/theme/AudioContentThemeService.kt @@ -35,6 +35,12 @@ class AudioContentThemeService( val theme = queryRepository.findThemeByIdAndActive(themeId) ?: throw SodaException("잘못된 요청입니다.") + val totalCount = contentRepository.totalCountByTheme( + memberId = member.id!!, + theme = theme.theme, + isAdult = member.auth != null + ) + val items = contentRepository.findByTheme( cloudfrontHost = imageHost, memberId = member.id!!, @@ -50,6 +56,7 @@ class AudioContentThemeService( return GetContentByThemeResponse( theme = theme.theme, + totalCount = totalCount, items = items ) } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/content/theme/content/GetContentByThemeResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/content/theme/content/GetContentByThemeResponse.kt index 59c4154..2776363 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/content/theme/content/GetContentByThemeResponse.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/content/theme/content/GetContentByThemeResponse.kt @@ -4,5 +4,6 @@ import kr.co.vividnext.sodalive.content.main.GetAudioContentMainItem data class GetContentByThemeResponse( val theme: String, + val totalCount: Int, val items: List )