플레이 리스트에 저장하는 콘텐츠ID에 정렬순서 값 추가
- 이유: 플레이 리스트에 저장하는 콘텐츠ID에는 순서가 있지만 해당 값으로 조회한 콘텐츠 상세내용의 정렬이 콘텐츠ID가 저장된 순서대로 나온다는 보장이 없음, 조회한 콘텐츠 상세의 정렬을 위해 추가
This commit is contained in:
parent
3093d2159d
commit
4097e5a133
|
@ -15,7 +15,7 @@ data class AudioContentPlaylist(
|
||||||
val memberId: Long,
|
val memberId: Long,
|
||||||
var title: String,
|
var title: String,
|
||||||
var desc: String? = null,
|
var desc: String? = null,
|
||||||
var contentIdList: List<Long>,
|
var contentIdAndOrderList: List<PlaylistContentIdAndOrder>,
|
||||||
|
|
||||||
// ISO 8601 형식의 String
|
// ISO 8601 형식의 String
|
||||||
private val _createdAt: String = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
private val _createdAt: String = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
|
||||||
|
|
|
@ -18,7 +18,7 @@ class AudioContentPlaylistService(
|
||||||
private val redisRepository: AudioContentPlaylistRedisRepository
|
private val redisRepository: AudioContentPlaylistRedisRepository
|
||||||
) {
|
) {
|
||||||
fun createPlaylist(request: CreatePlaylistRequest, member: Member) {
|
fun createPlaylist(request: CreatePlaylistRequest, member: Member) {
|
||||||
if (request.contentIdList.size >= 30) {
|
if (request.contentIdAndOrderList.size >= 30) {
|
||||||
throw SodaException("플레이 리스트에는 최대 30개의 콘텐츠를 저장할 수 있습니다.")
|
throw SodaException("플레이 리스트에는 최대 30개의 콘텐츠를 저장할 수 있습니다.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class AudioContentPlaylistService(
|
||||||
|
|
||||||
// 콘텐츠 유효성 검사 (소장으로 구매한 콘텐츠 인가?)
|
// 콘텐츠 유효성 검사 (소장으로 구매한 콘텐츠 인가?)
|
||||||
checkOrderedContent(
|
checkOrderedContent(
|
||||||
contentIdList = request.contentIdList,
|
contentIdList = request.contentIdAndOrderList.map { it.contentId },
|
||||||
memberId = member.id!!
|
memberId = member.id!!
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class AudioContentPlaylistService(
|
||||||
memberId = member.id!!,
|
memberId = member.id!!,
|
||||||
title = request.title,
|
title = request.title,
|
||||||
desc = request.desc,
|
desc = request.desc,
|
||||||
contentIdList = request.contentIdList
|
contentIdAndOrderList = request.contentIdAndOrderList
|
||||||
)
|
)
|
||||||
|
|
||||||
redisRepository.save(playlist)
|
redisRepository.save(playlist)
|
||||||
|
@ -55,7 +55,7 @@ class AudioContentPlaylistService(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updatePlaylist(playlistId: Long, request: UpdatePlaylistRequest, member: Member) {
|
fun updatePlaylist(playlistId: Long, request: UpdatePlaylistRequest, member: Member) {
|
||||||
if (request.contentIdList.size >= 30) {
|
if (request.contentIdAndOrderList.size >= 30) {
|
||||||
throw SodaException("플레이 리스트에는 최대 30개의 콘텐츠를 저장할 수 있습니다.")
|
throw SodaException("플레이 리스트에는 최대 30개의 콘텐츠를 저장할 수 있습니다.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,14 +67,14 @@ class AudioContentPlaylistService(
|
||||||
}
|
}
|
||||||
|
|
||||||
checkOrderedContent(
|
checkOrderedContent(
|
||||||
contentIdList = request.contentIdList,
|
contentIdList = request.contentIdAndOrderList.map { it.contentId },
|
||||||
memberId = member.id!!
|
memberId = member.id!!
|
||||||
)
|
)
|
||||||
|
|
||||||
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,
|
||||||
contentIdList = request.contentIdList
|
contentIdAndOrderList = request.contentIdAndOrderList
|
||||||
)
|
)
|
||||||
|
|
||||||
redisRepository.save(updatePlaylist)
|
redisRepository.save(updatePlaylist)
|
||||||
|
@ -86,9 +86,9 @@ class AudioContentPlaylistService(
|
||||||
return GetPlaylistsResponse(
|
return GetPlaylistsResponse(
|
||||||
totalCount = playlists.size,
|
totalCount = playlists.size,
|
||||||
items = playlists.map {
|
items = playlists.map {
|
||||||
val contentCount = it.contentIdList.size
|
val contentCount = it.contentIdAndOrderList.size
|
||||||
val coverImageUrl = if (contentCount > 0) {
|
val coverImageUrl = if (contentCount > 0) {
|
||||||
audioContentRepository.getCoverImageById(id = it.contentIdList[0])
|
audioContentRepository.getCoverImageById(id = it.contentIdAndOrderList[0].contentId)
|
||||||
?: ""
|
?: ""
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
|
@ -129,16 +129,24 @@ class AudioContentPlaylistService(
|
||||||
.withZoneSameInstant(ZoneId.of("Asia/Seoul"))
|
.withZoneSameInstant(ZoneId.of("Asia/Seoul"))
|
||||||
.format(dateTimeFormatter)
|
.format(dateTimeFormatter)
|
||||||
|
|
||||||
val contentList = audioContentRepository.fetchContentForPlaylist(contentIdList = playlist.contentIdList)
|
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(
|
return GetPlaylistDetailResponse(
|
||||||
playlistId = playlist.id,
|
playlistId = playlist.id,
|
||||||
title = playlist.title,
|
title = playlist.title,
|
||||||
desc = playlist.desc ?: "",
|
desc = playlist.desc ?: "",
|
||||||
createdDate = createdDate,
|
createdDate = createdDate,
|
||||||
contentCount = contentList.size,
|
contentCount = sortedContentList.size,
|
||||||
playlistCoverImageList = contentList.take(4).map { it.coverUrl },
|
playlistCoverImageList = sortedContentList.take(4).map { it.coverUrl },
|
||||||
contentList = contentList
|
contentList = sortedContentList
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,5 +3,5 @@ package kr.co.vividnext.sodalive.content.playlist
|
||||||
data class CreatePlaylistRequest(
|
data class CreatePlaylistRequest(
|
||||||
val title: String,
|
val title: String,
|
||||||
val desc: String? = null,
|
val desc: String? = null,
|
||||||
val contentIdList: List<Long> = emptyList()
|
val contentIdAndOrderList: List<PlaylistContentIdAndOrder> = emptyList()
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package kr.co.vividnext.sodalive.content.playlist
|
||||||
|
|
||||||
|
data class PlaylistContentIdAndOrder(
|
||||||
|
val contentId: Long,
|
||||||
|
val order: Int
|
||||||
|
)
|
|
@ -3,5 +3,5 @@ package kr.co.vividnext.sodalive.content.playlist
|
||||||
data class UpdatePlaylistRequest(
|
data class UpdatePlaylistRequest(
|
||||||
val title: String? = null,
|
val title: String? = null,
|
||||||
val desc: String? = null,
|
val desc: String? = null,
|
||||||
val contentIdList: List<Long> = emptyList()
|
val contentIdAndOrderList: List<PlaylistContentIdAndOrder> = emptyList()
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue