summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNavan Chauhan <navanchauhan@gmail.com>2024-02-11 07:54:24 -0700
committerNavan Chauhan <navanchauhan@gmail.com>2024-02-11 07:54:24 -0700
commitfdce29edf06e14e913182b50f072f2cd93527076 (patch)
tree14e6f3ca9c437539e2cdb4bb91b712dad6201e07
parent4632f8bc1e0318dd9d5057828a2fd8c851efb858 (diff)
-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