Skip to content

Commit bcaf24a

Browse files
committed
fix: 질문하기 오류
1 parent 30a37e5 commit bcaf24a

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

HalfFifty_FE/HalfFifty_FE/View/Setting/CustomerCenterView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct CustomerCenterView: View {
5757
.navigationBarTitleDisplayMode(.inline)
5858
.background(Color(UIColor.systemGray6))
5959
.onAppear {
60-
viewModel.fetchAQ(userId: "9f373112-8e93-4444-a403-a986f8bea4a3")
60+
viewModel.fetchAQ(userId: "1f273112-8e93-4444-a403-a986f8bea4a2")
6161
}
6262
}
6363
}

HalfFifty_FE/HalfFifty_FE/View/Setting/InquiryView.swift

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ struct InquiryView: View {
1111
@State private var questionText: String = ""
1212
@StateObject private var viewModel = AQViewModel()
1313
@Environment(\.presentationMode) var presentationMode // 화면 닫기용
14-
14+
@State private var showErrorAlert = false
15+
1516
var body: some View {
1617
VStack(alignment: .leading) {
1718
// 질문 입력란
@@ -35,19 +36,19 @@ struct InquiryView: View {
3536
)
3637
}
3738
.padding(.top, 16)
38-
39+
3940
// 안내 문구
4041
Text("해당 서비스의 궁금한 점에 대해 질문해주세요. 친절하게 답변해드립니다.")
4142
.font(.system(size: 14))
4243
.foregroundColor(.gray)
4344
.padding(.top, 10)
4445
.padding(.leading, 10)
45-
46+
4647
Spacer()
47-
48+
4849
// 질문하기 버튼
4950
Button(action: {
50-
viewModel.saveAQ(userId: "9f373112-8e93-4444-a403-a986f8bea4a3", question: questionText) {
51+
viewModel.saveAQ(userId: "1f273112-8e93-4444-a403-a986f8bea4a2", question: questionText) {_ in
5152
presentationMode.wrappedValue.dismiss() // 성공 시 화면 닫기
5253
}
5354
}) {
@@ -71,40 +72,53 @@ struct InquiryView: View {
7172
}
7273

7374
extension AQViewModel {
74-
func saveAQ(userId: String, question: String, completion: @escaping () -> Void) {
75-
guard let url = URL(string: "http://54.180.92.32/AQ") else { return }
76-
75+
func saveAQ(userId: String, question: String, completion: @escaping (Bool) -> Void) {
76+
guard let url = URL(string: "http://54.180.92.32/AQ") else {
77+
completion(false)
78+
return
79+
}
80+
7781
let requestData: [String: Any] = [
7882
"userId": userId,
7983
"question": question
8084
]
81-
82-
guard let jsonData = try? JSONSerialization.data(withJSONObject: requestData) else { return }
83-
85+
86+
guard let jsonData = try? JSONSerialization.data(withJSONObject: requestData) else {
87+
completion(false)
88+
return
89+
}
90+
8491
var request = URLRequest(url: url)
8592
request.httpMethod = "POST"
8693
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
8794
request.httpBody = jsonData
88-
95+
8996
URLSession.shared.dataTask(with: request) { data, response, error in
9097
DispatchQueue.main.async {
9198
if let error = error {
9299
print("질문 등록 오류: \(error.localizedDescription)")
100+
completion(false)
93101
return
94102
}
95-
96-
guard let data = data else { return }
97-
103+
104+
guard let data = data else {
105+
print("응답 데이터 없음")
106+
completion(false)
107+
return
108+
}
109+
98110
do {
99111
let decodedResponse = try JSONDecoder().decode(AQResponse.self, from: data)
100112
if decodedResponse.success {
101113
print("질문 등록 성공: \(decodedResponse.message)")
102-
completion() // 성공 시 화면 닫기
114+
completion(true)
103115
} else {
104116
print("질문 등록 실패: \(decodedResponse.message)")
117+
completion(false)
105118
}
106119
} catch {
107120
print("디코딩 오류: \(error.localizedDescription)")
121+
completion(false)
108122
}
109123
}
110124
}.resume()

0 commit comments

Comments
 (0)