콘텐츠 전체보기
- 카테고리 추가
This commit is contained in:
@@ -21,6 +21,7 @@ final class ContentListViewModel: ObservableObject {
|
||||
@Published var isShowPopup = false
|
||||
@Published var isLoading = false
|
||||
|
||||
@Published var categoryList: [GetCategoryListResponse] = []
|
||||
@Published var audioContentList: [GetAudioContentListItem] = []
|
||||
@Published var totalCount = 0
|
||||
@Published var sort = Sort.NEWEST {
|
||||
@@ -32,18 +33,20 @@ final class ContentListViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
@Published var scrollToTop = false
|
||||
@Published var selectedCategory: String = "전체"
|
||||
|
||||
var userId = 0
|
||||
var page = 1
|
||||
var isLast = false
|
||||
private let pageSize = 10
|
||||
private var categoryId = 0
|
||||
|
||||
func getAudioContentList() {
|
||||
if (!isLast && !isLoading) {
|
||||
isLoading = true
|
||||
|
||||
repository
|
||||
.getAudioContentList(userId: userId, page: page, size: pageSize, sort: sort)
|
||||
.getAudioContentList(userId: userId, categoryId: categoryId, page: page, size: pageSize, sort: sort)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
@@ -64,11 +67,11 @@ final class ContentListViewModel: ObservableObject {
|
||||
self.scrollToTop.toggle()
|
||||
}
|
||||
|
||||
if !data.items.isEmpty {
|
||||
page += 1
|
||||
self.totalCount = data.totalCount
|
||||
self.audioContentList.append(contentsOf: data.items)
|
||||
} else {
|
||||
page += 1
|
||||
self.totalCount = data.totalCount
|
||||
self.audioContentList.append(contentsOf: data.items)
|
||||
|
||||
if data.items.isEmpty {
|
||||
isLast = true
|
||||
}
|
||||
} else {
|
||||
@@ -90,4 +93,53 @@ final class ContentListViewModel: ObservableObject {
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
|
||||
func getCategoryList() {
|
||||
repository.getCategoryList(creatorId: userId)
|
||||
.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<[GetCategoryListResponse]>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
categoryList.removeAll()
|
||||
|
||||
if !data.isEmpty {
|
||||
categoryList.append(GetCategoryListResponse(categoryId: 0, category: "전체"))
|
||||
categoryList.append(contentsOf: data)
|
||||
}
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
print(error)
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func selectCategory(categoryId: Int) {
|
||||
self.categoryId = categoryId
|
||||
|
||||
page = 1
|
||||
isLast = false
|
||||
getAudioContentList()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user