parent
00e4fefc8f
commit
36052f034a
|
@ -6,6 +6,8 @@ import kr.co.vividnext.sodalive.content.QAudioContent.audioContent
|
||||||
import kr.co.vividnext.sodalive.content.main.GetAudioContentMainItem
|
import kr.co.vividnext.sodalive.content.main.GetAudioContentMainItem
|
||||||
import kr.co.vividnext.sodalive.content.main.QGetAudioContentMainItem
|
import kr.co.vividnext.sodalive.content.main.QGetAudioContentMainItem
|
||||||
import kr.co.vividnext.sodalive.content.order.QOrder.order
|
import kr.co.vividnext.sodalive.content.order.QOrder.order
|
||||||
|
import kr.co.vividnext.sodalive.content.playlist.ContentIdAndEndDateData
|
||||||
|
import kr.co.vividnext.sodalive.content.playlist.QContentIdAndEndDateData
|
||||||
import kr.co.vividnext.sodalive.member.QMember.member
|
import kr.co.vividnext.sodalive.member.QMember.member
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
|
@ -37,6 +39,7 @@ interface OrderQueryRepository {
|
||||||
): List<GetAudioContentMainItem>
|
): List<GetAudioContentMainItem>
|
||||||
|
|
||||||
fun findOrderedContent(contentIdList: List<Long>, memberId: Long): List<Long>
|
fun findOrderedContent(contentIdList: List<Long>, memberId: Long): List<Long>
|
||||||
|
fun findEndDateByContentId(contentIdList: List<Long>, memberId: Long): List<ContentIdAndEndDateData>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@ -229,9 +232,24 @@ class OrderQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Orde
|
||||||
.innerJoin(order.audioContent, audioContent)
|
.innerJoin(order.audioContent, audioContent)
|
||||||
.where(
|
.where(
|
||||||
order.isActive.isTrue,
|
order.isActive.isTrue,
|
||||||
order.endDate.isNull,
|
|
||||||
member.id.eq(memberId),
|
member.id.eq(memberId),
|
||||||
audioContent.id.`in`(contentIdList)
|
audioContent.id.`in`(contentIdList),
|
||||||
|
order.endDate.isNull.or(order.endDate.after(LocalDateTime.now()))
|
||||||
|
)
|
||||||
|
.fetch()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun findEndDateByContentId(contentIdList: List<Long>, memberId: Long): List<ContentIdAndEndDateData> {
|
||||||
|
return queryFactory
|
||||||
|
.select(QContentIdAndEndDateData(audioContent.id, order.endDate))
|
||||||
|
.from(order)
|
||||||
|
.innerJoin(order.member, member)
|
||||||
|
.innerJoin(order.audioContent, audioContent)
|
||||||
|
.where(
|
||||||
|
order.isActive.isTrue,
|
||||||
|
member.id.eq(memberId),
|
||||||
|
audioContent.id.`in`(contentIdList),
|
||||||
|
order.endDate.isNull.or(order.endDate.after(LocalDateTime.now()))
|
||||||
)
|
)
|
||||||
.fetch()
|
.fetch()
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,9 @@ class AudioContentPlaylistService(
|
||||||
throw SodaException("플레이 리스트는 최대 10개까지 생성할 수 있습니다.")
|
throw SodaException("플레이 리스트는 최대 10개까지 생성할 수 있습니다.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 콘텐츠 유효성 검사 (소장으로 구매한 콘텐츠 인가?)
|
val contentIdAndOrderList = validateAndGetContentIdAndOrderList(
|
||||||
validateContent(
|
contentIdAndOrderList = request.contentIdAndOrderList,
|
||||||
contentIdList = request.contentIdAndOrderList.map { it.contentId },
|
member
|
||||||
memberId = member.id!!
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val playlist = AudioContentPlaylist(
|
val playlist = AudioContentPlaylist(
|
||||||
|
@ -38,12 +37,34 @@ class AudioContentPlaylistService(
|
||||||
memberId = member.id!!,
|
memberId = member.id!!,
|
||||||
title = request.title,
|
title = request.title,
|
||||||
desc = request.desc,
|
desc = request.desc,
|
||||||
contentIdAndOrderList = request.contentIdAndOrderList
|
contentIdAndOrderList = contentIdAndOrderList
|
||||||
)
|
)
|
||||||
|
|
||||||
redisRepository.save(playlist)
|
redisRepository.save(playlist)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun validateAndGetContentIdAndOrderList(
|
||||||
|
contentIdAndOrderList: List<PlaylistContentIdAndOrder>,
|
||||||
|
member: Member
|
||||||
|
): List<PlaylistContentIdAndOrder> {
|
||||||
|
validateContent(
|
||||||
|
contentIdList = contentIdAndOrderList.map { it.contentId },
|
||||||
|
memberId = member.id!!
|
||||||
|
)
|
||||||
|
|
||||||
|
val contentIdAndEndDate = orderRepository.findEndDateByContentId(
|
||||||
|
contentIdList = contentIdAndOrderList.map { it.contentId },
|
||||||
|
memberId = member.id!!
|
||||||
|
)
|
||||||
|
|
||||||
|
val contentIdAndEndDateMap = contentIdAndEndDate.associate { it.contentId to it.endDate }
|
||||||
|
|
||||||
|
return contentIdAndOrderList.map {
|
||||||
|
it.endDate = contentIdAndEndDateMap[it.contentId]
|
||||||
|
it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun validateContent(contentIdList: List<Long>, memberId: Long) {
|
private fun validateContent(contentIdList: List<Long>, memberId: Long) {
|
||||||
if (contentIdList.isEmpty()) {
|
if (contentIdList.isEmpty()) {
|
||||||
throw SodaException("콘텐츠를 1개 이상 추가하세요")
|
throw SodaException("콘텐츠를 1개 이상 추가하세요")
|
||||||
|
@ -61,7 +82,7 @@ class AudioContentPlaylistService(
|
||||||
val notOrderedContentList = orderedContentMap.filterValues { !it }.keys
|
val notOrderedContentList = orderedContentMap.filterValues { !it }.keys
|
||||||
|
|
||||||
if (notOrderedContentList.isNotEmpty()) {
|
if (notOrderedContentList.isNotEmpty()) {
|
||||||
throw SodaException("소장하지 않은 콘텐츠는 재생목록에 추가할 수 없습니다.")
|
throw SodaException("대여/소장하지 않은 콘텐츠는 재생목록에 추가할 수 없습니다.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,15 +98,15 @@ class AudioContentPlaylistService(
|
||||||
throw SodaException("잘못된 요청입니다.")
|
throw SodaException("잘못된 요청입니다.")
|
||||||
}
|
}
|
||||||
|
|
||||||
checkOrderedContent(
|
val contentIdAndOrderList = validateAndGetContentIdAndOrderList(
|
||||||
contentIdList = request.contentIdAndOrderList.map { it.contentId },
|
contentIdAndOrderList = request.contentIdAndOrderList,
|
||||||
memberId = member.id!!
|
member
|
||||||
)
|
)
|
||||||
|
|
||||||
val updatePlaylist = playlist.copy(
|
val updatePlaylist = playlist.copy(
|
||||||
title = request.title ?: playlist.title,
|
title = request.title ?: playlist.title,
|
||||||
desc = request.desc ?: playlist.desc,
|
desc = request.desc ?: playlist.desc,
|
||||||
contentIdAndOrderList = request.contentIdAndOrderList
|
contentIdAndOrderList = contentIdAndOrderList
|
||||||
)
|
)
|
||||||
|
|
||||||
redisRepository.save(updatePlaylist)
|
redisRepository.save(updatePlaylist)
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package kr.co.vividnext.sodalive.content.playlist
|
||||||
|
|
||||||
|
import com.querydsl.core.annotations.QueryProjection
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
data class ContentIdAndEndDateData @QueryProjection constructor(
|
||||||
|
val contentId: Long,
|
||||||
|
val endDate: LocalDateTime?
|
||||||
|
)
|
|
@ -1,6 +1,9 @@
|
||||||
package kr.co.vividnext.sodalive.content.playlist
|
package kr.co.vividnext.sodalive.content.playlist
|
||||||
|
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
data class PlaylistContentIdAndOrder(
|
data class PlaylistContentIdAndOrder(
|
||||||
val contentId: Long,
|
val contentId: Long,
|
||||||
val order: Int
|
val order: Int,
|
||||||
|
var endDate: LocalDateTime? = null
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue