커뮤니티 댓글

- 수정 / 삭제 API 적용
This commit is contained in:
Yu Sung
2023-12-20 21:31:31 +09:00
parent cb3a564a29
commit 302f69b265
7 changed files with 176 additions and 1 deletions

View File

@@ -110,6 +110,7 @@ struct CreatorCommunityCommentListView: View {
isShowPopupMenuButton: true,
modifyComment: { commentId, comment in
hideKeyboard()
viewModel.modifyComment(commentId: commentId, postId: postId, comment: comment)
},
onClickDelete: {
commentId = $0
@@ -134,6 +135,7 @@ struct CreatorCommunityCommentListView: View {
desc: "삭제하시겠습니까?",
confirmButtonTitle: "삭제",
confirmButtonAction: {
viewModel.modifyComment(commentId: commentId, postId: postId, isActive: false)
commentId = 0
isShowDeletePopup = false
},

View File

@@ -119,4 +119,77 @@ final class CreatorCommunityCommentListViewModel: ObservableObject {
.store(in: &subscription)
}
}
func modifyComment(
commentId: Int,
postId: Int,
comment: String? = nil,
isActive: Bool? = nil
) {
if comment == nil && isActive == nil {
errorMessage = "변경사항이 없습니다."
isShowPopup = true
return
}
if let comment = comment, comment.trimmingCharacters(in: .whitespaces).isEmpty {
errorMessage = "내용을 입력하세요."
isShowPopup = true
return
}
isLoading = true
var request = ModifyCommunityPostCommentRequest(commentId: commentId)
if let comment = comment {
request.comment = comment
}
if let isActive = isActive {
request.isActive = isActive
}
repository.modifyComment(request: request)
.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.comment = ""
self.page = 1
self.isLast = false
self.commentList.removeAll()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
self.getCommentList()
}
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.isLoading = false
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
}
.store(in: &subscription)
}
}

View File

@@ -115,6 +115,7 @@ struct CreatorCommunityCommentReplyView: View {
isShowPopupMenuButton: true,
modifyComment: { commentId, comment in
hideKeyboard()
viewModel.modifyComment(commentId: commentId, postId: postId, comment: comment)
},
onClickDelete: {
commentId = $0
@@ -140,6 +141,7 @@ struct CreatorCommunityCommentReplyView: View {
desc: "삭제하시겠습니까?",
confirmButtonTitle: "삭제",
confirmButtonAction: {
viewModel.modifyComment(commentId: commentId, postId: postId, isActive: false)
commentId = 0
isShowDeletePopup = false
},

View File

@@ -121,4 +121,77 @@ final class CreatorCommunityCommentReplyViewModel: ObservableObject {
.store(in: &subscription)
}
}
func modifyComment(
commentId: Int,
postId: Int,
comment: String? = nil,
isActive: Bool? = nil
) {
if comment == nil && isActive == nil {
errorMessage = "변경사항이 없습니다."
isShowPopup = true
return
}
if let comment = comment, comment.trimmingCharacters(in: .whitespaces).isEmpty {
errorMessage = "내용을 입력하세요."
isShowPopup = true
return
}
isLoading = true
var request = ModifyCommunityPostCommentRequest(commentId: commentId)
if let comment = comment {
request.comment = comment
}
if let isActive = isActive {
request.isActive = isActive
}
repository.modifyComment(request: request)
.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.comment = ""
self.page = 1
self.isLast = false
self.commentList.removeAll()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
self.getCommentList()
}
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.isLoading = false
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
}
.store(in: &subscription)
}
}

View File

@@ -0,0 +1,14 @@
//
// ModifyCommunityPostCommentRequest.swift
// SodaLive
//
// Created by klaus on 2023/12/20.
//
import Foundation
struct ModifyCommunityPostCommentRequest: Encodable {
let commentId: Int
var comment: String? = nil
var isActive: Bool? = nil
}