55 lines
2.1 KiB
Swift
55 lines
2.1 KiB
Swift
//
|
|
// ContentMainCreatorRankingViewModel.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 1/5/25.
|
|
//
|
|
|
|
import Foundation
|
|
import Combine
|
|
|
|
final class ContentMainCreatorRankingViewModel: ObservableObject {
|
|
|
|
private let repository = ContentRepository()
|
|
private var subscription = Set<AnyCancellable>()
|
|
|
|
@Published var errorMessage = ""
|
|
@Published var isShowPopup = false
|
|
@Published var creatorRankingResponse: GetExplorerSectionResponse? = nil
|
|
|
|
func getCreatorRanking() {
|
|
repository.getCreatorRanking()
|
|
.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<GetExplorerSectionResponse>.self, from: responseData)
|
|
|
|
if let data = decoded.data, decoded.success {
|
|
self.creatorRankingResponse = data
|
|
} else {
|
|
if let message = decoded.message {
|
|
self.errorMessage = message
|
|
} else {
|
|
self.errorMessage = "인기 크리에이터를 불러오지 못했습니다. 다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
|
}
|
|
|
|
self.isShowPopup = true
|
|
}
|
|
} catch {
|
|
self.errorMessage = "인기 크리에이터를 불러오지 못했습니다. 다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
|
self.isShowPopup = true
|
|
}
|
|
}
|
|
.store(in: &subscription)
|
|
}
|
|
}
|