커뮤니티 댓글
- 수정 / 삭제 API 적용
This commit is contained in:
@@ -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
|
||||
},
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
},
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
Reference in New Issue
Block a user