콘텐츠 메인
- 홈 탭 API
This commit is contained in:
@@ -6,9 +6,9 @@ import kr.co.vividnext.sodalive.content.QAudioContent.audioContent
|
||||
import kr.co.vividnext.sodalive.content.category.QCategoryContent.categoryContent
|
||||
import kr.co.vividnext.sodalive.content.comment.QAudioContentComment.audioContentComment
|
||||
import kr.co.vividnext.sodalive.content.like.QAudioContentLike.audioContentLike
|
||||
import kr.co.vividnext.sodalive.content.main.ContentCreatorResponse
|
||||
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
|
||||
@@ -98,7 +98,7 @@ interface AudioContentQueryRepository {
|
||||
fun getNewContentUploadCreatorList(
|
||||
cloudfrontHost: String,
|
||||
isAdult: Boolean = false
|
||||
): List<GetNewContentUploadCreator>
|
||||
): List<ContentCreatorResponse>
|
||||
|
||||
fun getAudioContentMainBannerList(isAdult: Boolean): List<AudioContentBanner>
|
||||
fun getAudioContentCurations(isAdult: Boolean): List<AudioContentCuration>
|
||||
@@ -533,7 +533,7 @@ class AudioContentQueryRepositoryImpl(
|
||||
override fun getNewContentUploadCreatorList(
|
||||
cloudfrontHost: String,
|
||||
isAdult: Boolean
|
||||
): List<GetNewContentUploadCreator> {
|
||||
): List<ContentCreatorResponse> {
|
||||
var where = audioContent.releaseDate.after(LocalDateTime.now().minusWeeks(2))
|
||||
.and(audioContent.isActive.isTrue)
|
||||
.and(audioContent.duration.isNotNull)
|
||||
@@ -552,7 +552,7 @@ class AudioContentQueryRepositoryImpl(
|
||||
.limit(20)
|
||||
.fetch()
|
||||
.map {
|
||||
GetNewContentUploadCreator(
|
||||
ContentCreatorResponse(
|
||||
it.id!!,
|
||||
it.nickname,
|
||||
creatorProfileImageUrl = if (it.profileImage != null) {
|
||||
|
@@ -80,7 +80,7 @@ class AudioContentMainService(
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(cacheNames = ["default"], key = "'newContentUploadCreatorList:' + #memberId + ':' + #isAdult")
|
||||
fun getNewContentUploadCreatorList(memberId: Long, isAdult: Boolean): List<GetNewContentUploadCreator> {
|
||||
fun getNewContentUploadCreatorList(memberId: Long, isAdult: Boolean): List<ContentCreatorResponse> {
|
||||
return repository.getNewContentUploadCreatorList(
|
||||
cloudfrontHost = imageHost,
|
||||
isAdult = isAdult
|
||||
|
@@ -3,7 +3,7 @@ package kr.co.vividnext.sodalive.content.main
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import com.querydsl.core.annotations.QueryProjection
|
||||
|
||||
data class GetNewContentUploadCreator @QueryProjection constructor(
|
||||
data class ContentCreatorResponse @QueryProjection constructor(
|
||||
@JsonProperty("creatorId") val creatorId: Long,
|
||||
@JsonProperty("creatorNickname") val creatorNickname: String,
|
||||
@JsonProperty("creatorProfileImageUrl") val creatorProfileImageUrl: String
|
@@ -0,0 +1,41 @@
|
||||
package kr.co.vividnext.sodalive.content.main.banner
|
||||
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||
import kr.co.vividnext.sodalive.content.main.banner.QAudioContentBanner.audioContentBanner
|
||||
import kr.co.vividnext.sodalive.content.main.tab.QAudioContentMainTab.audioContentMainTab
|
||||
import kr.co.vividnext.sodalive.event.QEvent.event
|
||||
import kr.co.vividnext.sodalive.member.QMember.member
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface AudioContentBannerRepository : JpaRepository<AudioContentBanner, Long>, AudioContentBannerQueryRepository
|
||||
|
||||
interface AudioContentBannerQueryRepository {
|
||||
fun getAudioContentMainBannerList(tabId: Long, isAdult: Boolean): List<AudioContentBanner>
|
||||
}
|
||||
|
||||
class AudioContentBannerQueryRepositoryImpl(
|
||||
private val queryFactory: JPAQueryFactory
|
||||
) : AudioContentBannerQueryRepository {
|
||||
override fun getAudioContentMainBannerList(tabId: Long, isAdult: Boolean): List<AudioContentBanner> {
|
||||
var where = audioContentBanner.isActive.isTrue
|
||||
|
||||
where = if (tabId == 1L) {
|
||||
where.and(audioContentBanner.tab.isNull)
|
||||
} else {
|
||||
where.and(audioContentBanner.tab.id.eq(tabId))
|
||||
}
|
||||
|
||||
if (!isAdult) {
|
||||
where = where.and(audioContentBanner.isAdult.isFalse)
|
||||
}
|
||||
|
||||
return queryFactory
|
||||
.selectFrom(audioContentBanner)
|
||||
.leftJoin(audioContentBanner.tab, audioContentMainTab)
|
||||
.leftJoin(audioContentBanner.event, event)
|
||||
.leftJoin(audioContentBanner.creator, member)
|
||||
.where(where)
|
||||
.orderBy(audioContentBanner.orders.asc())
|
||||
.fetch()
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
package kr.co.vividnext.sodalive.content.main.banner
|
||||
|
||||
import kr.co.vividnext.sodalive.event.EventItem
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class AudioContentBannerService(
|
||||
private val repository: AudioContentBannerRepository,
|
||||
private val blockMemberRepository: BlockMemberRepository,
|
||||
|
||||
@Value("\${cloud.aws.cloud-front.host}")
|
||||
private val imageHost: String
|
||||
) {
|
||||
fun getBannerList(tabId: Long, memberId: Long, isAdult: Boolean): List<GetAudioContentBannerResponse> {
|
||||
return repository.getAudioContentMainBannerList(tabId, isAdult)
|
||||
.filter {
|
||||
if (it.type == AudioContentBannerType.CREATOR && it.creator != null) {
|
||||
!blockMemberRepository.isBlocked(blockedMemberId = memberId, memberId = it.creator!!.id!!)
|
||||
} else if (it.type == AudioContentBannerType.SERIES && it.series != null) {
|
||||
!blockMemberRepository.isBlocked(blockedMemberId = memberId, memberId = it.series!!.member!!.id!!)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
.map {
|
||||
GetAudioContentBannerResponse(
|
||||
type = it.type,
|
||||
thumbnailImageUrl = "$imageHost/${it.thumbnailImage}",
|
||||
eventItem = if (it.type == AudioContentBannerType.EVENT && it.event != null) {
|
||||
EventItem(
|
||||
id = it.event!!.id!!,
|
||||
thumbnailImageUrl = if (!it.event!!.thumbnailImage.startsWith("https://")) {
|
||||
"$imageHost/${it.event!!.thumbnailImage}"
|
||||
} else {
|
||||
it.event!!.thumbnailImage
|
||||
},
|
||||
detailImageUrl = if (
|
||||
it.event!!.detailImage != null &&
|
||||
!it.event!!.detailImage!!.startsWith("https://")
|
||||
) {
|
||||
"$imageHost/${it.event!!.detailImage}"
|
||||
} else {
|
||||
it.event!!.detailImage
|
||||
},
|
||||
popupImageUrl = null,
|
||||
link = it.event!!.link
|
||||
)
|
||||
} else {
|
||||
null
|
||||
},
|
||||
creatorId = if (it.type == AudioContentBannerType.CREATOR && it.creator != null) {
|
||||
it.creator!!.id
|
||||
} else {
|
||||
null
|
||||
},
|
||||
seriesId = if (it.type == AudioContentBannerType.SERIES && it.series != null) {
|
||||
it.series!!.id
|
||||
} else {
|
||||
null
|
||||
},
|
||||
link = it.link
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package kr.co.vividnext.sodalive.content.main.tab.home
|
||||
|
||||
import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/v2/audio-content/main/home")
|
||||
class AudioContentMainTabHomeController(private val service: AudioContentMainTabHomeService) {
|
||||
@GetMapping
|
||||
fun fetchContentMainHome(
|
||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
||||
) = run {
|
||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||
|
||||
ApiResponse.ok(service.fetchData(member))
|
||||
}
|
||||
}
|
@@ -0,0 +1,109 @@
|
||||
package kr.co.vividnext.sodalive.content.main.tab.home
|
||||
|
||||
import kr.co.vividnext.sodalive.content.main.banner.AudioContentBannerService
|
||||
import kr.co.vividnext.sodalive.event.EventService
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.notice.ServiceNoticeService
|
||||
import kr.co.vividnext.sodalive.rank.RankingService
|
||||
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 AudioContentMainTabHomeService(
|
||||
private val noticeService: ServiceNoticeService,
|
||||
private val bannerService: AudioContentBannerService,
|
||||
private val rankingService: RankingService,
|
||||
private val eventService: EventService
|
||||
) {
|
||||
fun fetchData(member: Member): GetContentMainTabHomeResponse {
|
||||
// 주간 랭킹 기간
|
||||
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 formattedLastMonday = startDate.format(startDateFormatter)
|
||||
val formattedLastSunday = endDate.format(endDateFormatter)
|
||||
|
||||
// 최근 공지사항
|
||||
val latestNotice = noticeService.getLatestNotice()
|
||||
|
||||
// 메인 배너 (홈)
|
||||
val contentBannerList = bannerService.getBannerList(
|
||||
tabId = 1,
|
||||
memberId = member.id!!,
|
||||
isAdult = member.auth != null
|
||||
)
|
||||
|
||||
// 인기 크리에이터
|
||||
val rankCreatorList = rankingService.getCreatorRanking(
|
||||
memberId = member.id!!,
|
||||
rankingDate = "$formattedLastMonday ~ $formattedLastSunday"
|
||||
)
|
||||
|
||||
// 인기 시리즈
|
||||
val rankSeriesList = rankingService.getSeriesRanking(
|
||||
memberId = member.id!!,
|
||||
isAdult = member.auth != null,
|
||||
startDate = startDate.minusDays(1),
|
||||
endDate = endDate.minusDays(1)
|
||||
)
|
||||
|
||||
// 인기 콘텐츠
|
||||
val rankContentList = rankingService.getContentRanking(
|
||||
memberId = member.id!!,
|
||||
isAdult = member.auth != null,
|
||||
startDate = startDate.minusDays(1),
|
||||
endDate = endDate.minusDays(1)
|
||||
)
|
||||
|
||||
// 이벤트 배너
|
||||
val eventBannerList = eventService.getEventList(isAdult = member.auth != null)
|
||||
|
||||
/* 채널별 인기 콘텐츠
|
||||
* - 콘텐츠를 4개 이상 등록한 채널
|
||||
* - 주간 콘텐츠 매출 Top 20 채널
|
||||
* - 해당 채널의 누적 매출 Top 2
|
||||
* - 해당 채널의 누적 판매 개수 Top 2
|
||||
*/
|
||||
val contentRankCreatorList = rankingService.fetchCreatorByContentRevenueRankTop20(
|
||||
memberId = member.id!!,
|
||||
startDate = startDate.minusDays(1),
|
||||
endDate = endDate.minusDays(1)
|
||||
)
|
||||
|
||||
val salesRankContentList = rankingService.fetchCreatorContentBySalesTop2(
|
||||
creatorId = contentRankCreatorList[0].creatorId,
|
||||
isAdult = member.auth != null
|
||||
)
|
||||
|
||||
val salesCountRankContentList = rankingService.fetchCreatorContentBySalesCountTop2(
|
||||
creatorId = contentRankCreatorList[0].creatorId,
|
||||
isAdult = member.auth != null
|
||||
)
|
||||
|
||||
return GetContentMainTabHomeResponse(
|
||||
latestNotice = latestNotice,
|
||||
bannerList = contentBannerList,
|
||||
rankCreatorList = rankCreatorList,
|
||||
rankSeriesList = rankSeriesList,
|
||||
rankSortTypeList = listOf("매출", "댓글", "좋아요"),
|
||||
rankContentList = rankContentList,
|
||||
eventBannerList = eventBannerList,
|
||||
contentRankCreatorList = contentRankCreatorList,
|
||||
salesRankContentList = salesRankContentList,
|
||||
salesCountRankContentList = salesCountRankContentList
|
||||
)
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package kr.co.vividnext.sodalive.content.main.tab.home
|
||||
|
||||
import kr.co.vividnext.sodalive.content.main.ContentCreatorResponse
|
||||
import kr.co.vividnext.sodalive.content.main.GetAudioContentRankingItem
|
||||
import kr.co.vividnext.sodalive.content.main.banner.GetAudioContentBannerResponse
|
||||
import kr.co.vividnext.sodalive.content.series.GetSeriesListResponse
|
||||
import kr.co.vividnext.sodalive.event.GetEventResponse
|
||||
import kr.co.vividnext.sodalive.explorer.GetExplorerSectionResponse
|
||||
import kr.co.vividnext.sodalive.notice.NoticeTitleItem
|
||||
|
||||
data class GetContentMainTabHomeResponse(
|
||||
val tabId: Long = 1,
|
||||
val latestNotice: NoticeTitleItem?,
|
||||
val bannerList: List<GetAudioContentBannerResponse>,
|
||||
val rankCreatorList: GetExplorerSectionResponse,
|
||||
val rankSeriesList: List<GetSeriesListResponse.SeriesListItem>,
|
||||
val rankSortTypeList: List<String>,
|
||||
val rankContentList: List<GetAudioContentRankingItem>,
|
||||
val eventBannerList: GetEventResponse,
|
||||
val contentRankCreatorList: List<ContentCreatorResponse>,
|
||||
val salesRankContentList: List<GetAudioContentRankingItem>,
|
||||
val salesCountRankContentList: List<GetAudioContentRankingItem>
|
||||
)
|
Reference in New Issue
Block a user