응원글 삭제 기능 추가

This commit is contained in:
Yu Sung
2023-09-09 00:02:39 +09:00
parent b31933715d
commit 5d95c0f1c9
10 changed files with 227 additions and 131 deletions

View File

@@ -47,10 +47,9 @@ final class UserProfileViewModel: ObservableObject {
@Published var isShowUesrReportView = false
@Published var isShowProfileReportConfirm = false
@Published var reportCheersId = 0
@Published var isShowCheersReportMenu = false
@Published var cheersId = 0
@Published var isShowCheersReportView = false
@Published var isShowCheersDeleteView = false
let paymentDialogCancelTitle = "취소"
@@ -488,7 +487,7 @@ final class UserProfileViewModel: ObservableObject {
func report(type: ReportType, userId: Int? = nil, reason: String = "프로필 신고") {
isLoading = true
let request = ReportRequest(type: type, reason: reason, reportedMemberId: userId, cheersId: reportCheersId > 0 && type == .CHEERS ? reportCheersId : nil, audioContentId: nil)
let request = ReportRequest(type: type, reason: reason, reportedMemberId: userId, cheersId: cheersId > 0 && type == .CHEERS ? cheersId : nil, audioContentId: nil)
reportRepository.report(request: request)
.sink { result in
switch result {
@@ -501,7 +500,7 @@ final class UserProfileViewModel: ObservableObject {
self.isLoading = false
let responseData = response.data
self.reportCheersId = 0
self.cheersId = 0
do {
let jsonDecoder = JSONDecoder()
@@ -521,4 +520,43 @@ final class UserProfileViewModel: ObservableObject {
}
.store(in: &subscription)
}
func deleteCheers(creatorId: Int) {
isLoading = true
repository.modifyCheers(cheersId: cheersId, content: nil, isActive: false)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
self.cheersId = 0
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
if decoded.success {
self.getCreatorProfile(userId: creatorId)
} 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)
}
}