후원랭킹 전체보기 - 채널에 후원랭킹 활성화 스위치 추가
This commit is contained in:
@@ -10,6 +10,7 @@ import Combine
|
||||
|
||||
final class UserProfileDonationAllViewModel: ObservableObject {
|
||||
private var repository = ExplorerRepository()
|
||||
private var memberRepository = UserRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var errorMessage = ""
|
||||
@@ -20,6 +21,7 @@ final class UserProfileDonationAllViewModel: ObservableObject {
|
||||
@Published var accumulatedCansToday = 0
|
||||
@Published var accumulatedCansLastWeek = 0
|
||||
@Published var accumulatedCansThisMonth = 0
|
||||
@Published var isVisibleDonationRank = false
|
||||
@Published var userDonationRanking: [UserDonationRankingResponse] = []
|
||||
|
||||
var userId = 0
|
||||
@@ -51,6 +53,7 @@ final class UserProfileDonationAllViewModel: ObservableObject {
|
||||
self.accumulatedCansToday = data.accumulatedCansToday
|
||||
self.accumulatedCansLastWeek = data.accumulatedCansLastWeek
|
||||
self.accumulatedCansThisMonth = data.accumulatedCansThisMonth
|
||||
self.isVisibleDonationRank = data.isVisibleDonationRank
|
||||
|
||||
if !data.userDonationRanking.isEmpty {
|
||||
page += 1
|
||||
@@ -76,4 +79,47 @@ final class UserProfileDonationAllViewModel: ObservableObject {
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
|
||||
func toggleVisibleDonationRank() {
|
||||
isLoading = true
|
||||
|
||||
memberRepository.profileUpdate(
|
||||
request: ProfileUpdateRequest(
|
||||
email: UserDefaults.string(forKey: .email),
|
||||
isVisibleDonationRank: !isVisibleDonationRank
|
||||
)
|
||||
)
|
||||
.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<GetProfileResponse>.self, from: responseData)
|
||||
|
||||
if decoded.success {
|
||||
isVisibleDonationRank.toggle()
|
||||
} 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