내 보관함, 재생목록 리스트 UI 추가

This commit is contained in:
Yu Sung
2024-12-07 05:32:05 +09:00
parent 627d6d9b7e
commit abc4a4f39d
14 changed files with 490 additions and 81 deletions

View File

@@ -0,0 +1,62 @@
//
// ContentPlaylistListViewModel.swift
// SodaLive
//
// Created by klaus on 12/7/24.
//
import Foundation
import Combine
final class ContentPlaylistListViewModel: ObservableObject {
private let repository = ContentPlaylistListRepository()
private var subscription = Set<AnyCancellable>()
@Published var isLoading = false
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var totalCount = 0
@Published var playlists = [GetPlaylistsItem]()
func getPlaylistList() {
if !isLoading {
isLoading = true
repository.getPlaylistList()
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponse<GetPlaylistsResponse>.self, from: responseData)
if let data = decoded.data, decoded.success {
self.totalCount = data.totalCount
self.playlists.append(contentsOf: data.items)
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
self.isLoading = false
}
.store(in: &subscription)
}
}
}