diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllView.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllView.swift index af1aa2b..64d6168 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllView.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllView.swift @@ -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 + } + ) } } } diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllViewModel.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllViewModel.swift index 43d5718..9282819 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllViewModel.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/All/CreatorCommunityAllViewModel.swift @@ -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 + } + } } diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityApi.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityApi.swift index c81e674..54e9c95 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityApi.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityApi.swift @@ -10,6 +10,7 @@ import Moya enum CreatorCommunityApi { case createCommunityPost(parameters: [MultipartFormData]) + case modifyCommunityPost(parameters: [MultipartFormData]) case getCommunityPostList(creatorId: Int, page: Int, size: Int) case communityPostLike(postId: Int) case createCommunityPostComment(comment: String, postId: Int, parentId: Int?) @@ -25,7 +26,7 @@ extension CreatorCommunityApi: TargetType { var path: String { switch self { - case .createCommunityPost, .getCommunityPostList: + case .createCommunityPost, .getCommunityPostList, .modifyCommunityPost: return "/creator-community" case .communityPostLike: @@ -50,7 +51,7 @@ extension CreatorCommunityApi: TargetType { case .getCommunityPostList, .getCommunityPostCommentList, .getCommentReplyList: return .get - case .modifyComment: + case .modifyComment, .modifyCommunityPost: return .put } } @@ -60,6 +61,9 @@ extension CreatorCommunityApi: TargetType { case .createCommunityPost(let parameters): return .uploadMultipart(parameters) + case .modifyCommunityPost(let parameters): + return .uploadMultipart(parameters) + case .getCommunityPostList(let creatorId, let page, let size): let parameters = [ "creatorId": creatorId, @@ -95,6 +99,7 @@ extension CreatorCommunityApi: TargetType { case .modifyComment(let request): return .requestJSONEncodable(request) + } } diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityRepository.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityRepository.swift index 673ed4c..29e2fce 100644 --- a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityRepository.swift +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/CreatorCommunityRepository.swift @@ -17,6 +17,10 @@ class CreatorCommunityRepository { return api.requestPublisher(.createCommunityPost(parameters: parameters)) } + func modifyCommunityPost(parameters: [MultipartFormData]) -> AnyPublisher { + return api.requestPublisher(.modifyCommunityPost(parameters: parameters)) + } + func getCommunityPostList(creatorId: Int, page: Int, size: Int) -> AnyPublisher { return api.requestPublisher(.getCommunityPostList(creatorId: creatorId, page: page, size: size)) } diff --git a/SodaLive/Sources/Explorer/Profile/CreatorCommunity/ModifyCommunityPostRequest.swift b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/ModifyCommunityPostRequest.swift new file mode 100644 index 0000000..bc96c51 --- /dev/null +++ b/SodaLive/Sources/Explorer/Profile/CreatorCommunity/ModifyCommunityPostRequest.swift @@ -0,0 +1,14 @@ +// +// ModifyCommunityPostRequest.swift +// SodaLive +// +// Created by klaus on 2023/12/21. +// + +struct ModifyCommunityPostRequest: Encodable { + let creatorCommunityId: Int + var content: String? = nil + var isCommentAvailable: Bool? = nil + var isAdult: Bool? = nil + var isActive: Bool? = nil +}