test #34
| @@ -263,7 +263,7 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) | ||||
|  | ||||
|     override fun totalCountNewContentFor2Weeks(theme: String, isAdult: Boolean): Int { | ||||
|         var where = audioContent.isActive.isTrue | ||||
|             .and(audioContent.createdAt.loe(LocalDateTime.now())) | ||||
|             .and(audioContent.createdAt.goe(LocalDateTime.now().minusWeeks(2))) | ||||
|  | ||||
|         if (!isAdult) { | ||||
|             where = where.and(audioContent.isAdult.isFalse) | ||||
| @@ -291,7 +291,7 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) | ||||
|         limit: Long | ||||
|     ): List<GetAudioContentMainItem> { | ||||
|         var where = audioContent.isActive.isTrue | ||||
|             .and(audioContent.createdAt.loe(LocalDateTime.now())) | ||||
|             .and(audioContent.createdAt.goe(LocalDateTime.now().minusWeeks(2))) | ||||
|  | ||||
|         if (!isAdult) { | ||||
|             where = where.and(audioContent.isAdult.isFalse) | ||||
|   | ||||
| @@ -1,9 +1,12 @@ | ||||
| package kr.co.vividnext.sodalive.content.main.curation | ||||
|  | ||||
| import com.querydsl.jpa.impl.JPAQueryFactory | ||||
| import kr.co.vividnext.sodalive.content.AudioContent | ||||
| import kr.co.vividnext.sodalive.content.QAudioContent.audioContent | ||||
| import kr.co.vividnext.sodalive.content.SortType | ||||
| import kr.co.vividnext.sodalive.content.main.GetAudioContentMainItem | ||||
| import kr.co.vividnext.sodalive.content.main.QGetAudioContentMainItem | ||||
| import kr.co.vividnext.sodalive.content.theme.QAudioContentTheme.audioContentTheme | ||||
| import kr.co.vividnext.sodalive.member.QMember.member | ||||
| import org.springframework.stereotype.Repository | ||||
|  | ||||
| @Repository | ||||
| @@ -26,11 +29,12 @@ class AudioContentCurationQueryRepository(private val queryFactory: JPAQueryFact | ||||
|  | ||||
|     fun findByCurationId( | ||||
|         curationId: Long, | ||||
|         cloudfrontHost: String, | ||||
|         isAdult: Boolean = false, | ||||
|         sortType: SortType = SortType.NEWEST, | ||||
|         offset: Long = 0, | ||||
|         limit: Long = 10 | ||||
|     ): List<AudioContent> { | ||||
|     ): List<GetAudioContentMainItem> { | ||||
|         val orderBy = when (sortType) { | ||||
|             SortType.NEWEST -> audioContent.createdAt.desc() | ||||
|             SortType.PRICE_HIGH -> audioContent.price.desc() | ||||
| @@ -48,7 +52,20 @@ class AudioContentCurationQueryRepository(private val queryFactory: JPAQueryFact | ||||
|         } | ||||
|  | ||||
|         return queryFactory | ||||
|             .selectFrom(audioContent) | ||||
|             .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) | ||||
|   | ||||
| @@ -1,9 +1,6 @@ | ||||
| package kr.co.vividnext.sodalive.content.main.curation | ||||
|  | ||||
| import kr.co.vividnext.sodalive.content.GetAudioContentListItem | ||||
| import kr.co.vividnext.sodalive.content.SortType | ||||
| import kr.co.vividnext.sodalive.content.comment.AudioContentCommentRepository | ||||
| import kr.co.vividnext.sodalive.content.like.AudioContentLikeRepository | ||||
| import kr.co.vividnext.sodalive.member.Member | ||||
| import kr.co.vividnext.sodalive.member.block.BlockMemberRepository | ||||
| import org.springframework.beans.factory.annotation.Value | ||||
| @@ -14,8 +11,6 @@ import org.springframework.stereotype.Service | ||||
| class AudioContentCurationService( | ||||
|     private val repository: AudioContentCurationQueryRepository, | ||||
|     private val blockMemberRepository: BlockMemberRepository, | ||||
|     private val commentRepository: AudioContentCommentRepository, | ||||
|     private val audioContentLikeRepository: AudioContentLikeRepository, | ||||
|  | ||||
|     @Value("\${cloud.aws.cloud-front.host}") | ||||
|     private val cloudFrontHost: String | ||||
| @@ -30,44 +25,19 @@ class AudioContentCurationService( | ||||
|  | ||||
|         val audioContentList = repository.findByCurationId( | ||||
|             curationId = curationId, | ||||
|             cloudfrontHost = cloudFrontHost, | ||||
|             isAdult = member.auth != null, | ||||
|             sortType = sortType, | ||||
|             offset = pageable.offset, | ||||
|             limit = pageable.pageSize.toLong() | ||||
|         ) | ||||
|  | ||||
|         val items = audioContentList | ||||
|             .asSequence() | ||||
|             .filter { content -> | ||||
|                 !blockMemberRepository.isBlocked( | ||||
|                     blockedMemberId = member.id!!, | ||||
|                     memberId = content.member!!.id!! | ||||
|                 ) | ||||
|             } | ||||
|             .map { | ||||
|                 val commentCount = commentRepository | ||||
|                     .totalCountCommentByContentId(it.id!!) | ||||
|  | ||||
|                 val likeCount = audioContentLikeRepository | ||||
|                     .totalCountAudioContentLike(it.id!!) | ||||
|  | ||||
|                 GetAudioContentListItem( | ||||
|                     contentId = it.id!!, | ||||
|                     coverImageUrl = "$cloudFrontHost/${it.coverImage!!}", | ||||
|                     title = it.title, | ||||
|                     price = it.price, | ||||
|                     themeStr = it.theme!!.theme, | ||||
|                     duration = it.duration, | ||||
|                     likeCount = likeCount, | ||||
|                     commentCount = commentCount, | ||||
|                     isAdult = it.isAdult | ||||
|                 ) | ||||
|             } | ||||
|             .filter { !blockMemberRepository.isBlocked(blockedMemberId = member.id!!, memberId = it.creatorId) } | ||||
|             .toList() | ||||
|  | ||||
|         return GetCurationContentResponse( | ||||
|             totalCount = totalCount, | ||||
|             items = items | ||||
|             items = audioContentList | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| package kr.co.vividnext.sodalive.content.main.curation | ||||
|  | ||||
| import kr.co.vividnext.sodalive.content.GetAudioContentListItem | ||||
| import kr.co.vividnext.sodalive.content.main.GetAudioContentMainItem | ||||
|  | ||||
| data class GetCurationContentResponse( | ||||
|     val totalCount: Int, | ||||
|     val items: List<GetAudioContentListItem> | ||||
|     val items: List<GetAudioContentMainItem> | ||||
| ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user