From 033f775a6ebd48fbdb8d4749aeacd1fdb8e2fc09 Mon Sep 17 00:00:00 2001 From: anushkasankaran Date: Wed, 19 Feb 2025 21:14:00 -0600 Subject: [PATCH 1/5] Fix QR loop call in profile --- HackIllinois/ViewControllers/HIProfileCardView.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/HackIllinois/ViewControllers/HIProfileCardView.swift b/HackIllinois/ViewControllers/HIProfileCardView.swift index a9b89c0b..c2cbfd94 100644 --- a/HackIllinois/ViewControllers/HIProfileCardView.swift +++ b/HackIllinois/ViewControllers/HIProfileCardView.swift @@ -229,6 +229,13 @@ struct HIProfileCardView: View { } .edgesIgnoringSafeArea(.bottom) // Extend to the bottom edge .offset(y: 30 * (UIScreen.main.bounds.height/926)) + .onAppear { + startFetchingQR = true + QRFetchLoop() + } + .onDisappear { + startFetchingQR = false + } } func formatName() -> String { From 360be737f180dc71795c5cdb7fb746ad8e491b6a Mon Sep 17 00:00:00 2001 From: anushkasankaran Date: Wed, 19 Feb 2025 21:14:25 -0600 Subject: [PATCH 2/5] Shorten placeholder qr --- HackIllinois/ViewControllers/HIProfileCardView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HackIllinois/ViewControllers/HIProfileCardView.swift b/HackIllinois/ViewControllers/HIProfileCardView.swift index c2cbfd94..f5c3bdd7 100644 --- a/HackIllinois/ViewControllers/HIProfileCardView.swift +++ b/HackIllinois/ViewControllers/HIProfileCardView.swift @@ -58,7 +58,7 @@ struct HIProfileCardView: View { let isIpad = UIDevice.current.userInterfaceIdiom == .pad let role: String @State var startFetchingQR = false - @State var qrInfo = "hackillinois://user?userToken=11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" + @State var qrInfo = "hackillinois://user?userToken=111111111111111111111111111111111111111111111111111111111111111111111111111111111" // Factors used to change frame to alter based on device let padFactor = UIScreen.main.bounds.height/1366 let phoneFactor = UIScreen.main.bounds.height/844 From a3cb4469a2651d7037764124edb0c123378634ea Mon Sep 17 00:00:00 2001 From: anushkasankaran Date: Wed, 19 Feb 2025 21:15:36 -0600 Subject: [PATCH 3/5] Update call from scanner --- .../HIScanQRCodeViewController.swift | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift b/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift index e9574fe7..20602e2f 100644 --- a/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift +++ b/HackIllinois/ViewControllers/HIScanQRCodeViewController.swift @@ -392,49 +392,45 @@ extension HIScanQRCodeViewController: AVCaptureMetadataOutputObjectsDelegate { guard respondingToQRCodeFound else { return } let meta = metadataObjects.first as? AVMetadataMachineReadableCodeObject let code = meta?.stringValue ?? "" + let query = extractQueryValue(from: code) guard let user = HIApplicationStateController.shared.user else { return } let staffToken = user.token //print("staff token is:", staffToken, "event id is:", selectedEventId) print("qr code info is", code) if user.roles.contains(.STAFF) { if selectedEventId != "" { - if let range = code.range(of: "userToken=") { - let userToken = code[range.upperBound...] - respondingToQRCodeFound = false - HIAPI.StaffService.recordUserAttendance(userToken: String(userToken), staffToken: String(staffToken), eventId: selectedEventId) - .onCompletion { result in - do { - let (codeResult, _) = try result.get() - DispatchQueue.main.async { [self] in - print(codeResult.dietaryRestrictions) - // Parse dietary string - dietaryString = "" - if let dietaryRestrictions = codeResult.dietaryRestrictions, !dietaryRestrictions.isEmpty { - for (index, diet) in dietaryRestrictions.enumerated() { - dietaryString += diet - if index < dietaryRestrictions.count - 1 { - dietaryString += ", " - } + respondingToQRCodeFound = false + HIAPI.StaffService.recordUserAttendance(userQR: query ?? "", staffToken: String(staffToken), eventId: selectedEventId) + .onCompletion { result in + do { + let (codeResult, _) = try result.get() + DispatchQueue.main.async { [self] in + print(codeResult.dietaryRestrictions) + // Parse dietary string + dietaryString = "" + if let dietaryRestrictions = codeResult.dietaryRestrictions, !dietaryRestrictions.isEmpty { + for (index, diet) in dietaryRestrictions.enumerated() { + dietaryString += diet + if index < dietaryRestrictions.count - 1 { + dietaryString += ", " } - } else { - dietaryString = "None" } - self.handleStaffCheckInAlert(status: "Success") - } - } catch { - print(error, error.localizedDescription) - DispatchQueue.main.async { [self] in - self.handleStaffCheckInAlert(status: error.localizedDescription) + } else { + dietaryString = "None" } + self.handleStaffCheckInAlert(status: "Success") + } + } catch { + print(error, error.localizedDescription) + DispatchQueue.main.async { [self] in + self.handleStaffCheckInAlert(status: error.localizedDescription) } - sleep(2) - self.respondingToQRCodeFound = true } - .authorize(with: HIApplicationStateController.shared.user) - .launch() - } else { - self.handleStaffCheckInAlert(status: "Incorrect type of QR code") - } + sleep(2) + self.respondingToQRCodeFound = true + } + .authorize(with: HIApplicationStateController.shared.user) + .launch() } } else { respondingToQRCodeFound = false @@ -459,6 +455,15 @@ extension HIScanQRCodeViewController: AVCaptureMetadataOutputObjectsDelegate { .launch() } } + + func extractQueryValue(from url: String) -> String? { + guard let components = URLComponents(string: url), + let queryItem = components.queryItems?.first(where: { $0.name == "qr" }) else { + return nil + } + return queryItem.value + } + func decode(_ token: String) -> [String: AnyObject]? { let string = token.components(separatedBy: ".") if string.count == 1 { return nil } From 784dec95545f7711b3a88debac7be9af8b4ec7e5 Mon Sep 17 00:00:00 2001 From: anushkasankaran Date: Wed, 19 Feb 2025 21:16:02 -0600 Subject: [PATCH 4/5] Update call body --- HIAPI/Services/StaffService.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/HIAPI/Services/StaffService.swift b/HIAPI/Services/StaffService.swift index c0e2ac7d..ecf67643 100644 --- a/HIAPI/Services/StaffService.swift +++ b/HIAPI/Services/StaffService.swift @@ -32,12 +32,13 @@ public final class StaffService: BaseService { return APIRequest(service: self, endpoint: "attendance/", body: body, headers: headers, method: .POST) } - public static func recordUserAttendance(userToken: String, staffToken: String, eventId: String) -> APIRequest { + public static func recordUserAttendance(userQR: String, staffToken: String, eventId: String) -> APIRequest { var body = HTTPBody() - body["attendeeJWT"] = userToken body["eventId"] = eventId + body["attendeeQRCode"] = userQR + var headers = HTTPHeaders() - headers["Authorization"] = userToken + headers["Authorization"] = staffToken return APIRequest(service: self, endpoint: "scan-attendee/", body: body, headers: headers, method: .PUT) } } From d08a6091be29ceb72930a02a98c2e17b0cfe838c Mon Sep 17 00:00:00 2001 From: anushkasankaran Date: Wed, 19 Feb 2025 21:16:49 -0600 Subject: [PATCH 5/5] updated schema --- HIAPI/Models/Staff.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HIAPI/Models/Staff.swift b/HIAPI/Models/Staff.swift index 805c101f..91240c51 100644 --- a/HIAPI/Models/Staff.swift +++ b/HIAPI/Models/Staff.swift @@ -60,11 +60,11 @@ public struct Staff: Codable { public struct UserAttendanceContainer: Codable, APIReturnable { internal enum CodingKeys: String, CodingKey { case success - case error + case userId case dietaryRestrictions } public let success: Bool - public let error: String? + public let userId: String? public let dietaryRestrictions: [String]? }