콘텐츠 랭킹 추가 #44
| @@ -2,15 +2,19 @@ package kr.co.vividnext.sodalive.content | ||||
|  | ||||
| import com.querydsl.core.types.dsl.Expressions | ||||
| import com.querydsl.jpa.impl.JPAQueryFactory | ||||
| import kr.co.vividnext.sodalive.can.use.QUseCan.useCan | ||||
| import kr.co.vividnext.sodalive.content.QAudioContent.audioContent | ||||
| import kr.co.vividnext.sodalive.content.QBundleAudioContent.bundleAudioContent | ||||
| import kr.co.vividnext.sodalive.content.main.GetAudioContentMainItem | ||||
| import kr.co.vividnext.sodalive.content.main.GetAudioContentRankingItem | ||||
| import kr.co.vividnext.sodalive.content.main.GetNewContentUploadCreator | ||||
| import kr.co.vividnext.sodalive.content.main.QGetAudioContentMainItem | ||||
| import kr.co.vividnext.sodalive.content.main.QGetAudioContentRankingItem | ||||
| import kr.co.vividnext.sodalive.content.main.banner.AudioContentBanner | ||||
| import kr.co.vividnext.sodalive.content.main.banner.QAudioContentBanner.audioContentBanner | ||||
| import kr.co.vividnext.sodalive.content.main.curation.AudioContentCuration | ||||
| import kr.co.vividnext.sodalive.content.main.curation.QAudioContentCuration.audioContentCuration | ||||
| import kr.co.vividnext.sodalive.content.order.QOrder.order | ||||
| import kr.co.vividnext.sodalive.content.theme.QAudioContentTheme.audioContentTheme | ||||
| import kr.co.vividnext.sodalive.event.QEvent.event | ||||
| import kr.co.vividnext.sodalive.member.QMember.member | ||||
| @@ -78,6 +82,14 @@ interface AudioContentQueryRepository { | ||||
|         cloudfrontHost: String, | ||||
|         isAdult: Boolean | ||||
|     ): List<GetAudioContentMainItem> | ||||
|  | ||||
|     fun getAudioContentRanking( | ||||
|         cloudfrontHost: String, | ||||
|         isAdult: Boolean, | ||||
|         startDate: LocalDateTime, | ||||
|         endDate: LocalDateTime, | ||||
|         limit: Long = 12 | ||||
|     ): List<GetAudioContentRankingItem> | ||||
| } | ||||
|  | ||||
| @Repository | ||||
| @@ -424,4 +436,46 @@ class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) | ||||
|             .orderBy(audioContent.id.desc()) | ||||
|             .fetch() | ||||
|     } | ||||
|  | ||||
|     override fun getAudioContentRanking( | ||||
|         cloudfrontHost: String, | ||||
|         isAdult: Boolean, | ||||
|         startDate: LocalDateTime, | ||||
|         endDate: LocalDateTime, | ||||
|         limit: Long | ||||
|     ): List<GetAudioContentRankingItem> { | ||||
|         var where = audioContent.isActive.isTrue | ||||
|             .and(audioContent.member.isNotNull) | ||||
|             .and(audioContent.duration.isNotNull) | ||||
|             .and(audioContent.member.isActive.isTrue) | ||||
|             .and(useCan.createdAt.goe(startDate)) | ||||
|             .and(useCan.createdAt.lt(endDate)) | ||||
|  | ||||
|         if (!isAdult) { | ||||
|             where = where.and(audioContent.isAdult.isFalse) | ||||
|         } | ||||
|  | ||||
|         return queryFactory | ||||
|             .select( | ||||
|                 QGetAudioContentRankingItem( | ||||
|                     audioContent.id, | ||||
|                     audioContent.title, | ||||
|                     audioContent.coverImage.prepend("/").prepend(cloudfrontHost), | ||||
|                     audioContentTheme.theme, | ||||
|                     audioContent.price, | ||||
|                     audioContent.duration, | ||||
|                     member.id, | ||||
|                     member.nickname | ||||
|                 ) | ||||
|             ) | ||||
|             .from(useCan) | ||||
|             .innerJoin(useCan.order, order) | ||||
|             .innerJoin(order.audioContent, audioContent) | ||||
|             .innerJoin(audioContent.member, member) | ||||
|             .innerJoin(audioContent.theme, audioContentTheme) | ||||
|             .where(where) | ||||
|             .orderBy(order.can.sum().desc()) | ||||
|             .limit(limit) | ||||
|             .fetch() | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -12,6 +12,10 @@ import kr.co.vividnext.sodalive.member.block.BlockMemberRepository | ||||
| import org.springframework.beans.factory.annotation.Value | ||||
| import org.springframework.data.domain.Pageable | ||||
| import org.springframework.stereotype.Service | ||||
| import java.time.DayOfWeek | ||||
| import java.time.LocalDateTime | ||||
| import java.time.format.DateTimeFormatter | ||||
| import java.time.temporal.TemporalAdjusters | ||||
|  | ||||
| @Service | ||||
| class AudioContentMainService( | ||||
| @@ -126,13 +130,41 @@ class AudioContentMainService( | ||||
|             .filter { it.contents.isNotEmpty() } | ||||
|             .toList() | ||||
|  | ||||
|         val currentDateTime = LocalDateTime.now() | ||||
|         val startDate = currentDateTime | ||||
|             .withHour(15) | ||||
|             .withMinute(0) | ||||
|             .withSecond(0) | ||||
|             .minusWeeks(1) | ||||
|             .with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)) | ||||
|         val endDate = startDate | ||||
|             .plusDays(7) | ||||
|  | ||||
|         val startDateFormatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일") | ||||
|         val endDateFormatter = DateTimeFormatter.ofPattern("MM월 dd일") | ||||
|  | ||||
|         val contentRankingItemList = repository | ||||
|             .getAudioContentRanking( | ||||
|                 cloudfrontHost = imageHost, | ||||
|                 startDate = startDate, | ||||
|                 endDate = endDate, | ||||
|                 isAdult = isAdult | ||||
|             ) | ||||
|  | ||||
|         val contentRanking = GetAudioContentRanking( | ||||
|             startDate = startDate.format(startDateFormatter), | ||||
|             endDate = endDate.format(endDateFormatter), | ||||
|             contentRankingItemList | ||||
|         ) | ||||
|  | ||||
|         return GetAudioContentMainResponse( | ||||
|             newContentUploadCreatorList = newContentUploadCreatorList, | ||||
|             bannerList = bannerList, | ||||
|             orderList = orderList, | ||||
|             themeList = themeList, | ||||
|             newContentList = newContentList, | ||||
|             curationList = curationList | ||||
|             curationList = curationList, | ||||
|             contentRanking = contentRanking | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -9,5 +9,6 @@ data class GetAudioContentMainResponse( | ||||
|     val orderList: List<GetAudioContentMainItem>, | ||||
|     val themeList: List<String>, | ||||
|     val newContentList: List<GetAudioContentMainItem>, | ||||
|     val curationList: List<GetAudioContentCurationResponse> | ||||
|     val curationList: List<GetAudioContentCurationResponse>, | ||||
|     val contentRanking: GetAudioContentRanking | ||||
| ) | ||||
|   | ||||
| @@ -0,0 +1,20 @@ | ||||
| package kr.co.vividnext.sodalive.content.main | ||||
|  | ||||
| import com.querydsl.core.annotations.QueryProjection | ||||
|  | ||||
| data class GetAudioContentRanking( | ||||
|     val startDate: String, | ||||
|     val endDate: String, | ||||
|     val items: List<GetAudioContentRankingItem> | ||||
| ) | ||||
|  | ||||
| data class GetAudioContentRankingItem @QueryProjection constructor( | ||||
|     val contentId: Long, | ||||
|     val title: String, | ||||
|     val coverImageUrl: String, | ||||
|     val themeStr: String, | ||||
|     val price: Int, | ||||
|     val duration: String, | ||||
|     val creatorId: Long, | ||||
|     val creatorNickname: String | ||||
| ) | ||||
		Reference in New Issue
	
	Block a user