summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--iCUrHealth/AutoCallerSheet.swift39
1 files changed, 39 insertions, 0 deletions
diff --git a/iCUrHealth/AutoCallerSheet.swift b/iCUrHealth/AutoCallerSheet.swift
index 6bad0ec..bfbacea 100644
--- a/iCUrHealth/AutoCallerSheet.swift
+++ b/iCUrHealth/AutoCallerSheet.swift
@@ -7,6 +7,45 @@
import SwiftUI
+struct Student: Codable {
+ let phoneNumber: String
+ let name: String
+ let studentID: String
+ let dateOfBirth: String
+ let request: String
+}
+
+func submitStudentInfo(student: Student) {
+ guard let url = URL(string: "http://127.0.0.1:8000/submit/") else { return }
+
+ var request = URLRequest(url: url)
+ request.httpMethod = "POST"
+ request.addValue("application/json", forHTTPHeaderField: "Content-Type")
+
+ do {
+ let jsonData = try JSONEncoder().encode(student)
+ request.httpBody = jsonData
+
+ let task = URLSession.shared.dataTask(with: request) { data, response, error in
+ guard let data = data, error == nil else {
+ print("Error: \(error?.localizedDescription ?? "No error description.")")
+ return
+ }
+
+ if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {
+ print("StatusCode should be 200, but is \(httpStatus.statusCode)")
+ print("Response = \(response!)")
+ }
+
+ let responseString = String(data: data, encoding: .utf8)
+ print("responseString = \(responseString!)")
+ }
+ task.resume()
+ } catch {
+ print("Error: \(error.localizedDescription)")
+ }
+}
+
struct AutoCallerSheet: View {
@State private var helpNeeded: String