새로운 콘텐츠 전체보기 API 추가

This commit is contained in:
Klaus 2023-09-27 00:02:05 +09:00
parent 468add0819
commit fd460f2d3e
4 changed files with 102 additions and 0 deletions

View File

@ -56,6 +56,16 @@ interface AudioContentQueryRepository {
limit: Long = 20
): List<GetAudioContentMainItem>
fun findByThemeFor2Weeks(
cloudfrontHost: String,
theme: String = "",
isAdult: Boolean = false,
offset: Long = 0,
limit: Long = 20
): List<GetAudioContentMainItem>
fun totalCountNewContentFor2Weeks(theme: String, isAdult: Boolean): Int
fun getNewContentUploadCreatorList(
cloudfrontHost: String,
isAdult: Boolean = false
@ -251,6 +261,68 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory)
.fetch()
}
override fun totalCountNewContentFor2Weeks(theme: String, isAdult: Boolean): Int {
var where = audioContent.isActive.isTrue
.and(audioContent.createdAt.loe(LocalDateTime.now()))
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 findByThemeFor2Weeks(
cloudfrontHost: String,
theme: String,
isAdult: Boolean,
offset: Long,
limit: Long
): List<GetAudioContentMainItem> {
var where = audioContent.isActive.isTrue
.and(audioContent.createdAt.loe(LocalDateTime.now()))
if (!isAdult) {
where = where.and(audioContent.isAdult.isFalse)
}
if (theme.isNotBlank()) {
where = where.and(audioContentTheme.theme.eq(theme))
}
return queryFactory
.select(
QGetAudioContentMainItem(
audioContent.id,
audioContent.coverImage.prepend("/").prepend(cloudfrontHost),
audioContent.title,
audioContent.isAdult,
member.id,
member.profileImage.prepend("/").prepend(cloudfrontHost),
member.nickname
)
)
.from(audioContent)
.innerJoin(audioContent.member, member)
.innerJoin(audioContent.theme, audioContentTheme)
.where(where)
.offset(offset)
.limit(limit)
.orderBy(audioContent.createdAt.desc())
.fetch()
}
override fun getNewContentUploadCreatorList(
cloudfrontHost: String,
isAdult: Boolean

View File

@ -33,4 +33,15 @@ class AudioContentMainController(private val service: AudioContentMainService) {
ApiResponse.ok(service.getNewContentByTheme(theme, member, pageable))
}
@GetMapping("/new/all")
fun getNewContentAllByTheme(
@RequestParam("theme") theme: String,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?,
pageable: Pageable
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
ApiResponse.ok(service.getNewContentFor2WeeksByTheme(theme, member, pageable))
}
}

View File

@ -148,4 +148,17 @@ class AudioContentMainService(
.filter { !blockMemberRepository.isBlocked(blockedMemberId = member.id!!, memberId = it.creatorId) }
.toList()
}
fun getNewContentFor2WeeksByTheme(theme: String, member: Member, pageable: Pageable): GetNewContentAllResponse {
val totalCount = repository.totalCountNewContentFor2Weeks(theme, isAdult = member.auth != null)
val items = repository.findByThemeFor2Weeks(
cloudfrontHost = imageHost,
theme = theme,
isAdult = member.auth != null,
offset = pageable.offset,
limit = pageable.pageSize.toLong()
)
return GetNewContentAllResponse(totalCount, items)
}
}

View File

@ -0,0 +1,6 @@
package kr.co.vividnext.sodalive.content.main
data class GetNewContentAllResponse(
val totalCount: Int,
val items: List<GetAudioContentMainItem>
)