커뮤니티 게시물 삭제 API 적용

This commit is contained in:
Yu Sung
2023-12-21 00:38:30 +09:00
parent 9f360e9fcd
commit f40642f90f
5 changed files with 99 additions and 2 deletions

View File

@@ -73,6 +73,9 @@ struct CreatorCommunityAllView: View {
modifyAction: {
},
deleteAction: {
if creatorId == UserDefaults.int(forKey: .userId) {
viewModel.isShowDeleteConfirm = true
}
},
reportAction: {
viewModel.isShowReportView = true
@@ -95,6 +98,19 @@ struct CreatorCommunityAllView: View {
}
if viewModel.isShowDeleteConfirm {
SodaDialog(
title: "게시물 삭제",
desc: "삭제하시겠습니까?",
confirmButtonTitle: "삭제",
confirmButtonAction: {
viewModel.deleteCommunityPost()
viewModel.isShowDeleteConfirm = false
},
cancelButtonTitle: "취소",
cancelButtonAction: {
viewModel.isShowDeleteConfirm = false
}
)
}
}
}

View File

@@ -198,4 +198,62 @@ class CreatorCommunityAllViewModel: ObservableObject {
}
.store(in: &subscription)
}
func deleteCommunityPost() {
isLoading = true
let request = ModifyCommunityPostRequest(creatorCommunityId: postId, isActive: false)
var multipartData = [MultipartFormData]()
let encoder = JSONEncoder()
encoder.outputFormatting = .withoutEscapingSlashes
let jsonData = try? encoder.encode(request)
if let jsonData = jsonData {
multipartData.append(MultipartFormData(provider: .data(jsonData), name: "request"))
repository.modifyCommunityPost(parameters: multipartData)
.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(ApiResponseWithoutData.self, from: responseData)
if decoded.success {
self.errorMessage = "삭제되었습니다"
self.isShowPopup = true
self.page = 1
self.isLast = false
self.getCommunityPostList()
} 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)
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
self.isLoading = false
}
}
}