플레이 리스트 수정 API 추가
This commit is contained in:
		| @@ -8,6 +8,7 @@ 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 | ||||
| @@ -22,9 +23,18 @@ class AudioContentPlaylistController(private val service: AudioContentPlaylistSe | ||||
|     ) = run { | ||||
|         if (member == null) throw SodaException("로그인 정보를 확인해주세요.") | ||||
|  | ||||
|         ApiResponse.ok( | ||||
|             service.createPlaylist(request, member) | ||||
|         ) | ||||
|         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}") | ||||
|   | ||||
| @@ -52,6 +52,32 @@ class AudioContentPlaylistService( | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fun updatePlaylist(playlistId: Long, request: UpdatePlaylistRequest, member: Member) { | ||||
|         if (request.contentIdList.size >= 30) { | ||||
|             throw SodaException("플레이 리스트에는 최대 30개의 콘텐츠를 저장할 수 있습니다.") | ||||
|         } | ||||
|  | ||||
|         val playlist = redisRepository.findByIdOrNull(id = playlistId) | ||||
|             ?: throw SodaException("잘못된 요청입니다.") | ||||
|  | ||||
|         if (playlist.memberId != member.id) { | ||||
|             throw SodaException("잘못된 요청입니다.") | ||||
|         } | ||||
|  | ||||
|         checkOrderedContent( | ||||
|             contentIdList = request.contentIdList, | ||||
|             memberId = member.id!! | ||||
|         ) | ||||
|  | ||||
|         val updatePlaylist = playlist.copy( | ||||
|             title = request.title ?: playlist.title, | ||||
|             desc = request.desc ?: playlist.desc, | ||||
|             contentIdList = request.contentIdList | ||||
|         ) | ||||
|  | ||||
|         redisRepository.save(updatePlaylist) | ||||
|     } | ||||
|  | ||||
|     fun getPlaylists(member: Member): GetPlaylistsResponse { | ||||
|         val playlists = redisRepository.findByMemberId(memberId = member.id!!) | ||||
|  | ||||
|   | ||||
| @@ -0,0 +1,7 @@ | ||||
| package kr.co.vividnext.sodalive.content.playlist | ||||
|  | ||||
| data class UpdatePlaylistRequest( | ||||
|     val title: String? = null, | ||||
|     val desc: String? = null, | ||||
|     val contentIdList: List<Long> = emptyList() | ||||
| ) | ||||
		Reference in New Issue
	
	Block a user