Skip to content

Commit

Permalink
[Fix/#178] 플리 이미지 있는 상태에서의 편집 로직 수정
Browse files Browse the repository at this point in the history
Co-authored-by: Junu-Pak <[email protected]>
Co-authored-by: WooFeather <[email protected]>
  • Loading branch information
WooFeather and Junu-Park committed Nov 3, 2024
1 parent a9bbdd1 commit e61c666
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ final class PlaylistServiceImpl: PlaylistServiceInterface {
}
}

/// 플레이리스트를 업데이트합니다. 이미지URL을 받습니다.
func updatePlaylist(playlistId: Int, title: String, imageUrl: String?) async -> Result<Void, any Error> {

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<Void, Error> {

Expand Down
1 change: 1 addition & 0 deletions PLAT/PLAT/Domain/Interface/PlaylistServiceInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protocol PlaylistServiceInterface {
func uploadPlaylist(title: String, image: UIImage?, tracks: [Track]) async -> Result<Int64, Error>
func appendTrackToPlaylist(playlistId: Int, trackId: Int) async -> Result<Void, Error>
func updatePlaylist(playlistId: Int, title: String, image: UIImage?) async -> Result<Void, Error>
func updatePlaylist(playlistId: Int, title: String, imageUrl: String?) async -> Result<Void, Error>
func updateTrackOrder(playlistId: Int, tracks: [Track]) async -> Result<Void, Error>
func deleteTrackFromPlaylist(playlistId: Int, trackId: Int) async -> Result<Void, Error>
func deletePlaylist(playlistId: Int) async -> Result<Void, Error>
Expand Down
14 changes: 14 additions & 0 deletions PLAT/PLAT/Domain/UseCase/PlaylistUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 9 additions & 5 deletions PLAT/PLAT/Presentaion/Playlist/PlaylistDetailsEditView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e61c666

Please sign in to comment.