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