diff --git a/PLAT/PLAT/Data/PlatService/Service/PlaylistService/PlaylistServiceImpl.swift b/PLAT/PLAT/Data/PlatService/Service/PlaylistService/PlaylistServiceImpl.swift index ab22420c..55b28093 100644 --- a/PLAT/PLAT/Data/PlatService/Service/PlaylistService/PlaylistServiceImpl.swift +++ b/PLAT/PLAT/Data/PlatService/Service/PlaylistService/PlaylistServiceImpl.swift @@ -188,6 +188,19 @@ final class PlaylistServiceImpl: PlaylistServiceInterface { } } + /// 플레이리스트를 업데이트합니다. 이미지URL을 받습니다. + func updatePlaylist(playlistId: Int, title: String, imageUrl: String?) async -> Result { + + let request = UpdatePlaylistRequest(title: title, playlistImageUrl: imageUrl ?? "") + let response = await playlistRepository.updatePlaylist(request: request, playlistId: Int64(playlistId)) + switch response { + case .success: + return .success(()) + case .failure(let error): + return .failure(error) + } + } + /// 플레이리스트의 트랙 순서를 변경합니다. func updateTrackOrder(playlistId: Int, tracks: [Track]) async -> Result { diff --git a/PLAT/PLAT/Domain/Interface/PlaylistServiceInterface.swift b/PLAT/PLAT/Domain/Interface/PlaylistServiceInterface.swift index e3320179..c9c65731 100644 --- a/PLAT/PLAT/Domain/Interface/PlaylistServiceInterface.swift +++ b/PLAT/PLAT/Domain/Interface/PlaylistServiceInterface.swift @@ -14,6 +14,7 @@ protocol PlaylistServiceInterface { func uploadPlaylist(title: String, image: UIImage?, tracks: [Track]) async -> Result func appendTrackToPlaylist(playlistId: Int, trackId: Int) async -> Result func updatePlaylist(playlistId: Int, title: String, image: UIImage?) async -> Result + func updatePlaylist(playlistId: Int, title: String, imageUrl: String?) async -> Result func updateTrackOrder(playlistId: Int, tracks: [Track]) async -> Result func deleteTrackFromPlaylist(playlistId: Int, trackId: Int) async -> Result func deletePlaylist(playlistId: Int) async -> Result diff --git a/PLAT/PLAT/Domain/UseCase/PlaylistUseCase.swift b/PLAT/PLAT/Domain/UseCase/PlaylistUseCase.swift index 2d83a85a..1a90ff49 100644 --- a/PLAT/PLAT/Domain/UseCase/PlaylistUseCase.swift +++ b/PLAT/PLAT/Domain/UseCase/PlaylistUseCase.swift @@ -137,6 +137,20 @@ extension PlaylistUseCase { } } + /// 플레이리스트를 업데이트합니다. ImageUrl을 받습니다. + func updatePlaylist(playlistId: Int, title: String, imageUrl: String?) async { + let result = await playlistService.updatePlaylist( + playlistId: playlistId, + title: title, + imageUrl: imageUrl + ) + + switch result { + case .success: break + case .failure(let error): print(error) // TODO: 에러 처리 + } + } + /// 플레이리스트의 트랙 순서를 변경합니다. func updateTrackOrder(playlistId: Int, tracks: [Track]) { Task { diff --git a/PLAT/PLAT/Presentaion/Playlist/PlaylistDetailsEditView.swift b/PLAT/PLAT/Presentaion/Playlist/PlaylistDetailsEditView.swift index b977e3e2..947f1475 100644 --- a/PLAT/PLAT/Presentaion/Playlist/PlaylistDetailsEditView.swift +++ b/PLAT/PLAT/Presentaion/Playlist/PlaylistDetailsEditView.swift @@ -60,11 +60,15 @@ struct PlaylistDetailsEditView: View { ToolbarItem(placement: .primaryAction) { Button { Task { - await playlistUseCase.updatePlaylist( - playlistId: Int(selectedPlaylist.id), - title: selectedPlaylist.title, - image: selectedImage - ) + if let selectedImg = selectedImage { + await playlistUseCase.updatePlaylist( + playlistId: Int(selectedPlaylist.id), + title: selectedPlaylist.title, + image: selectedImage + ) + } else { + await playlistUseCase.updatePlaylist(playlistId: Int(selectedPlaylist.id), title: selectedPlaylist.title, imageUrl: selectedPlaylist.imageUrl) + } playlistUseCase.fetchPlaylistDetail(playlistId: Int(selectedPlaylist.id)) pathModel.pop()