Compare commits
No commits in common. "4097e5a13318bee58e926dfd09f0d169acf85bc3" and "559df6c7b8133b386d773da9ed8265b1c4826d2c" have entirely different histories.
4097e5a133
...
559df6c7b8
|
@ -17,13 +17,10 @@ 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.main.curation.QAudioContentCuration.audioContentCuration
|
||||||
import kr.co.vividnext.sodalive.content.order.QOrder.order
|
import kr.co.vividnext.sodalive.content.order.QOrder.order
|
||||||
import kr.co.vividnext.sodalive.content.pin.QPinContent.pinContent
|
import kr.co.vividnext.sodalive.content.pin.QPinContent.pinContent
|
||||||
import kr.co.vividnext.sodalive.content.playlist.AudioContentPlaylistContent
|
|
||||||
import kr.co.vividnext.sodalive.content.playlist.QAudioContentPlaylistContent
|
|
||||||
import kr.co.vividnext.sodalive.content.theme.QAudioContentTheme.audioContentTheme
|
import kr.co.vividnext.sodalive.content.theme.QAudioContentTheme.audioContentTheme
|
||||||
import kr.co.vividnext.sodalive.event.QEvent.event
|
import kr.co.vividnext.sodalive.event.QEvent.event
|
||||||
import kr.co.vividnext.sodalive.member.MemberRole
|
import kr.co.vividnext.sodalive.member.MemberRole
|
||||||
import kr.co.vividnext.sodalive.member.QMember.member
|
import kr.co.vividnext.sodalive.member.QMember.member
|
||||||
import org.springframework.beans.factory.annotation.Value
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
@ -123,18 +120,10 @@ interface AudioContentQueryRepository {
|
||||||
fun getNotReleaseContentId(): List<Long>
|
fun getNotReleaseContentId(): List<Long>
|
||||||
|
|
||||||
fun isContentCreator(contentId: Long, memberId: Long): Boolean
|
fun isContentCreator(contentId: Long, memberId: Long): Boolean
|
||||||
|
|
||||||
fun fetchContentForPlaylist(contentIdList: List<Long>): List<AudioContentPlaylistContent>
|
|
||||||
fun getCoverImageById(id: Long): String?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
class AudioContentQueryRepositoryImpl(
|
class AudioContentQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : AudioContentQueryRepository {
|
||||||
private val queryFactory: JPAQueryFactory,
|
|
||||||
|
|
||||||
@Value("\${cloud.aws.cloud-front.host}")
|
|
||||||
private val imageHost: String
|
|
||||||
) : AudioContentQueryRepository {
|
|
||||||
override fun findByIdAndActive(contentId: Long): AudioContent? {
|
override fun findByIdAndActive(contentId: Long): AudioContent? {
|
||||||
return queryFactory
|
return queryFactory
|
||||||
.selectFrom(audioContent)
|
.selectFrom(audioContent)
|
||||||
|
@ -789,27 +778,4 @@ class AudioContentQueryRepositoryImpl(
|
||||||
|
|
||||||
return foundedContentId != null && foundedContentId == contentId
|
return foundedContentId != null && foundedContentId == contentId
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchContentForPlaylist(contentIdList: List<Long>): List<AudioContentPlaylistContent> {
|
|
||||||
return queryFactory
|
|
||||||
.select(
|
|
||||||
QAudioContentPlaylistContent(
|
|
||||||
audioContent.id,
|
|
||||||
audioContent.title,
|
|
||||||
audioContentTheme.theme,
|
|
||||||
audioContent.coverImage.prepend("/").prepend(imageHost),
|
|
||||||
audioContent.duration
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.from(audioContent)
|
|
||||||
.innerJoin(audioContent.theme, audioContentTheme)
|
|
||||||
.fetch()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getCoverImageById(id: Long): String? {
|
|
||||||
return queryFactory
|
|
||||||
.select(audioContent.coverImage.prepend("/").prepend(imageHost))
|
|
||||||
.from(audioContent)
|
|
||||||
.fetchFirst()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,6 @@ interface OrderQueryRepository {
|
||||||
offset: Long = 0,
|
offset: Long = 0,
|
||||||
limit: Long = 20
|
limit: Long = 20
|
||||||
): List<GetAudioContentMainItem>
|
): List<GetAudioContentMainItem>
|
||||||
|
|
||||||
fun findOrderedContent(contentIdList: List<Long>, memberId: Long): List<Long>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@ -220,19 +218,4 @@ class OrderQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : Orde
|
||||||
.orderBy(order.createdAt.desc())
|
.orderBy(order.createdAt.desc())
|
||||||
.fetch()
|
.fetch()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun findOrderedContent(contentIdList: List<Long>, memberId: Long): List<Long> {
|
|
||||||
return queryFactory
|
|
||||||
.select(audioContent.id)
|
|
||||||
.from(order)
|
|
||||||
.innerJoin(order.member, member)
|
|
||||||
.innerJoin(order.audioContent, audioContent)
|
|
||||||
.where(
|
|
||||||
order.isActive.isTrue,
|
|
||||||
order.endDate.isNull,
|
|
||||||
member.id.eq(memberId),
|
|
||||||
audioContent.id.`in`(contentIdList)
|
|
||||||
)
|
|
||||||
.fetch()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.content.playlist
|
|
||||||
|
|
||||||
import com.querydsl.core.annotations.QueryProjection
|
|
||||||
import org.springframework.data.annotation.Id
|
|
||||||
import org.springframework.data.redis.core.RedisHash
|
|
||||||
import org.springframework.data.redis.core.index.Indexed
|
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
|
|
||||||
@RedisHash("AudioContentPlaylist")
|
|
||||||
data class AudioContentPlaylist(
|
|
||||||
@Id
|
|
||||||
val id: Long,
|
|
||||||
@Indexed
|
|
||||||
val memberId: Long,
|
|
||||||
var title: String,
|
|
||||||
var desc: String? = null,
|
|
||||||
var contentIdAndOrderList: List<PlaylistContentIdAndOrder>,
|
|
||||||
|
|
||||||
// ISO 8601 형식의 String
|
|
||||||
private val _createdAt: String = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
|
||||||
) {
|
|
||||||
val createdAt: LocalDateTime
|
|
||||||
get() = LocalDateTime.parse(_createdAt, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
|
||||||
}
|
|
||||||
|
|
||||||
data class AudioContentPlaylistContent @QueryProjection constructor(
|
|
||||||
val id: Long,
|
|
||||||
val title: String,
|
|
||||||
val category: String,
|
|
||||||
val coverUrl: String,
|
|
||||||
val duration: String
|
|
||||||
)
|
|
|
@ -1,68 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.content.playlist
|
|
||||||
|
|
||||||
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.DeleteMapping
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
|
||||||
import org.springframework.web.bind.annotation.RestController
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/audio-content/playlist")
|
|
||||||
class AudioContentPlaylistController(private val service: AudioContentPlaylistService) {
|
|
||||||
@PostMapping
|
|
||||||
fun createPlaylist(
|
|
||||||
@RequestBody request: CreatePlaylistRequest,
|
|
||||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
||||||
) = run {
|
|
||||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
||||||
|
|
||||||
ApiResponse.ok(service.createPlaylist(request, member))
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
|
||||||
fun updatePlaylist(
|
|
||||||
@PathVariable id: Long,
|
|
||||||
@RequestBody request: UpdatePlaylistRequest,
|
|
||||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
||||||
) = run {
|
|
||||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
||||||
|
|
||||||
ApiResponse.ok(service.updatePlaylist(playlistId = id, request = request, member = member))
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
fun deletePlaylist(
|
|
||||||
@PathVariable id: Long,
|
|
||||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
||||||
) = run {
|
|
||||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
||||||
|
|
||||||
ApiResponse.ok(service.deletePlaylist(playlistId = id, member))
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
fun getPlaylists(
|
|
||||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
||||||
) = run {
|
|
||||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
||||||
|
|
||||||
ApiResponse.ok(service.getPlaylists(member))
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
fun getPlaylistDetail(
|
|
||||||
@PathVariable id: Long,
|
|
||||||
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
|
|
||||||
) = run {
|
|
||||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
|
||||||
|
|
||||||
ApiResponse.ok(service.getPlaylistDetail(playlistId = id, member = member))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.content.playlist
|
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository
|
|
||||||
import org.springframework.stereotype.Repository
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
interface AudioContentPlaylistRedisRepository : CrudRepository<AudioContentPlaylist, Long> {
|
|
||||||
fun findByMemberId(memberId: Long): List<AudioContentPlaylist>
|
|
||||||
}
|
|
|
@ -1,156 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.content.playlist
|
|
||||||
|
|
||||||
import kr.co.vividnext.sodalive.common.SodaException
|
|
||||||
import kr.co.vividnext.sodalive.content.AudioContentRepository
|
|
||||||
import kr.co.vividnext.sodalive.content.order.OrderRepository
|
|
||||||
import kr.co.vividnext.sodalive.live.roulette.RedisIdGenerator
|
|
||||||
import kr.co.vividnext.sodalive.member.Member
|
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
|
||||||
import org.springframework.stereotype.Service
|
|
||||||
import java.time.ZoneId
|
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
|
|
||||||
@Service
|
|
||||||
class AudioContentPlaylistService(
|
|
||||||
private val idGenerator: RedisIdGenerator,
|
|
||||||
private val orderRepository: OrderRepository,
|
|
||||||
private val audioContentRepository: AudioContentRepository,
|
|
||||||
private val redisRepository: AudioContentPlaylistRedisRepository
|
|
||||||
) {
|
|
||||||
fun createPlaylist(request: CreatePlaylistRequest, member: Member) {
|
|
||||||
if (request.contentIdAndOrderList.size >= 30) {
|
|
||||||
throw SodaException("플레이 리스트에는 최대 30개의 콘텐츠를 저장할 수 있습니다.")
|
|
||||||
}
|
|
||||||
|
|
||||||
val playlistCount = redisRepository.findByMemberId(member.id!!).size
|
|
||||||
if (playlistCount >= 10) {
|
|
||||||
throw SodaException("플레이 리스트는 최대 10개까지 생성할 수 있습니다.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 콘텐츠 유효성 검사 (소장으로 구매한 콘텐츠 인가?)
|
|
||||||
checkOrderedContent(
|
|
||||||
contentIdList = request.contentIdAndOrderList.map { it.contentId },
|
|
||||||
memberId = member.id!!
|
|
||||||
)
|
|
||||||
|
|
||||||
val playlist = AudioContentPlaylist(
|
|
||||||
id = idGenerator.generateId(SEQUENCE_NAME),
|
|
||||||
memberId = member.id!!,
|
|
||||||
title = request.title,
|
|
||||||
desc = request.desc,
|
|
||||||
contentIdAndOrderList = request.contentIdAndOrderList
|
|
||||||
)
|
|
||||||
|
|
||||||
redisRepository.save(playlist)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkOrderedContent(contentIdList: List<Long>, memberId: Long) {
|
|
||||||
val orderedContentIdList = orderRepository.findOrderedContent(contentIdList, memberId).toSet()
|
|
||||||
val orderedContentMap = contentIdList.associateWith { it in orderedContentIdList }
|
|
||||||
val notOrderedContentList = orderedContentMap.filterValues { !it }.keys
|
|
||||||
|
|
||||||
if (notOrderedContentList.isNotEmpty()) {
|
|
||||||
throw SodaException("소장하지 않은 콘텐츠는 재생목록에 추가할 수 없습니다.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updatePlaylist(playlistId: Long, request: UpdatePlaylistRequest, member: Member) {
|
|
||||||
if (request.contentIdAndOrderList.size >= 30) {
|
|
||||||
throw SodaException("플레이 리스트에는 최대 30개의 콘텐츠를 저장할 수 있습니다.")
|
|
||||||
}
|
|
||||||
|
|
||||||
val playlist = redisRepository.findByIdOrNull(id = playlistId)
|
|
||||||
?: throw SodaException("잘못된 요청입니다.")
|
|
||||||
|
|
||||||
if (playlist.memberId != member.id) {
|
|
||||||
throw SodaException("잘못된 요청입니다.")
|
|
||||||
}
|
|
||||||
|
|
||||||
checkOrderedContent(
|
|
||||||
contentIdList = request.contentIdAndOrderList.map { it.contentId },
|
|
||||||
memberId = member.id!!
|
|
||||||
)
|
|
||||||
|
|
||||||
val updatePlaylist = playlist.copy(
|
|
||||||
title = request.title ?: playlist.title,
|
|
||||||
desc = request.desc ?: playlist.desc,
|
|
||||||
contentIdAndOrderList = request.contentIdAndOrderList
|
|
||||||
)
|
|
||||||
|
|
||||||
redisRepository.save(updatePlaylist)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getPlaylists(member: Member): GetPlaylistsResponse {
|
|
||||||
val playlists = redisRepository.findByMemberId(memberId = member.id!!)
|
|
||||||
|
|
||||||
return GetPlaylistsResponse(
|
|
||||||
totalCount = playlists.size,
|
|
||||||
items = playlists.map {
|
|
||||||
val contentCount = it.contentIdAndOrderList.size
|
|
||||||
val coverImageUrl = if (contentCount > 0) {
|
|
||||||
audioContentRepository.getCoverImageById(id = it.contentIdAndOrderList[0].contentId)
|
|
||||||
?: ""
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
GetPlaylistsItem(
|
|
||||||
id = it.id,
|
|
||||||
title = it.title,
|
|
||||||
desc = it.desc ?: "",
|
|
||||||
contentCount = contentCount,
|
|
||||||
coverImageUrl = coverImageUrl
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deletePlaylist(playlistId: Long, member: Member) {
|
|
||||||
val playlist = redisRepository.findByIdOrNull(id = playlistId)
|
|
||||||
?: throw SodaException("잘못된 요청입니다.")
|
|
||||||
|
|
||||||
if (playlist.memberId != member.id) {
|
|
||||||
throw SodaException("잘못된 요청입니다.")
|
|
||||||
}
|
|
||||||
|
|
||||||
redisRepository.delete(playlist)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getPlaylistDetail(playlistId: Long, member: Member): GetPlaylistDetailResponse {
|
|
||||||
val playlist = redisRepository.findByIdOrNull(id = playlistId)
|
|
||||||
?: throw SodaException("잘못된 요청입니다.")
|
|
||||||
|
|
||||||
if (playlist.memberId != member.id) {
|
|
||||||
throw SodaException("잘못된 요청입니다.")
|
|
||||||
}
|
|
||||||
|
|
||||||
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
||||||
val createdDate = playlist.createdAt
|
|
||||||
.atZone(ZoneId.of("UTC"))
|
|
||||||
.withZoneSameInstant(ZoneId.of("Asia/Seoul"))
|
|
||||||
.format(dateTimeFormatter)
|
|
||||||
|
|
||||||
val contentList = audioContentRepository.fetchContentForPlaylist(
|
|
||||||
contentIdList = playlist.contentIdAndOrderList.map { it.contentId }
|
|
||||||
)
|
|
||||||
|
|
||||||
val orderMap = playlist.contentIdAndOrderList.sortedBy { it.order }
|
|
||||||
.mapIndexed { index, item -> item.contentId to index }
|
|
||||||
.toMap()
|
|
||||||
|
|
||||||
val sortedContentList = contentList.sortedBy { orderMap[it.id] }
|
|
||||||
|
|
||||||
return GetPlaylistDetailResponse(
|
|
||||||
playlistId = playlist.id,
|
|
||||||
title = playlist.title,
|
|
||||||
desc = playlist.desc ?: "",
|
|
||||||
createdDate = createdDate,
|
|
||||||
contentCount = sortedContentList.size,
|
|
||||||
playlistCoverImageList = sortedContentList.take(4).map { it.coverUrl },
|
|
||||||
contentList = sortedContentList
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val SEQUENCE_NAME = "AudioContentPlaylist:sequence"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.content.playlist
|
|
||||||
|
|
||||||
data class CreatePlaylistRequest(
|
|
||||||
val title: String,
|
|
||||||
val desc: String? = null,
|
|
||||||
val contentIdAndOrderList: List<PlaylistContentIdAndOrder> = emptyList()
|
|
||||||
)
|
|
|
@ -1,11 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.content.playlist
|
|
||||||
|
|
||||||
data class GetPlaylistDetailResponse(
|
|
||||||
val playlistId: Long,
|
|
||||||
val title: String,
|
|
||||||
val desc: String,
|
|
||||||
val createdDate: String,
|
|
||||||
val contentCount: Int,
|
|
||||||
val playlistCoverImageList: List<String>,
|
|
||||||
val contentList: List<AudioContentPlaylistContent>
|
|
||||||
)
|
|
|
@ -1,14 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.content.playlist
|
|
||||||
|
|
||||||
data class GetPlaylistsResponse(
|
|
||||||
val totalCount: Int,
|
|
||||||
val items: List<GetPlaylistsItem>
|
|
||||||
)
|
|
||||||
|
|
||||||
data class GetPlaylistsItem(
|
|
||||||
val id: Long,
|
|
||||||
val title: String,
|
|
||||||
val desc: String,
|
|
||||||
val contentCount: Int,
|
|
||||||
val coverImageUrl: String
|
|
||||||
)
|
|
|
@ -1,6 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.content.playlist
|
|
||||||
|
|
||||||
data class PlaylistContentIdAndOrder(
|
|
||||||
val contentId: Long,
|
|
||||||
val order: Int
|
|
||||||
)
|
|
|
@ -1,7 +0,0 @@
|
||||||
package kr.co.vividnext.sodalive.content.playlist
|
|
||||||
|
|
||||||
data class UpdatePlaylistRequest(
|
|
||||||
val title: String? = null,
|
|
||||||
val desc: String? = null,
|
|
||||||
val contentIdAndOrderList: List<PlaylistContentIdAndOrder> = emptyList()
|
|
||||||
)
|
|
Loading…
Reference in New Issue