콘텐츠 메인 - 인기 콘텐츠 정렬 추가
This commit is contained in:
@@ -24,6 +24,7 @@ final class ContentMainViewModel: ObservableObject {
|
||||
@Published var orderList = [GetAudioContentMainItem]()
|
||||
@Published var themeList = [String]()
|
||||
@Published var curationList = [GetAudioContentCurationResponse]()
|
||||
@Published var contentRankingSortList = [String]()
|
||||
@Published var contentRanking: GetAudioContentRanking? = nil
|
||||
|
||||
@Published var selectedTheme = "전체" {
|
||||
@@ -32,6 +33,12 @@ final class ContentMainViewModel: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
@Published var selectedContentRankingSort = "매출" {
|
||||
didSet {
|
||||
getContentRanking()
|
||||
}
|
||||
}
|
||||
|
||||
func getMain() {
|
||||
isLoading = true
|
||||
|
||||
@@ -66,6 +73,7 @@ final class ContentMainViewModel: ObservableObject {
|
||||
self.orderList.append(contentsOf: data.orderList)
|
||||
self.curationList.append(contentsOf: data.curationList)
|
||||
self.contentRanking = data.contentRanking
|
||||
self.contentRankingSortList.append(contentsOf: data.contentRankingSortTypeList)
|
||||
|
||||
self.themeList.append("전체")
|
||||
self.themeList.append(contentsOf: data.themeList)
|
||||
@@ -124,4 +132,42 @@ final class ContentMainViewModel: ObservableObject {
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func getContentRanking() {
|
||||
isLoading = true
|
||||
|
||||
repository.getContentRanking(page: 1, size: 12, sortType: selectedContentRankingSort)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<GetAudioContentRanking>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.contentRanking = 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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user