From 914f708fcb62b3b9d81aa0347f5455910a1cd565 Mon Sep 17 00:00:00 2001 From: Sophia Liu Date: Thu, 23 Nov 2023 13:54:41 -0600 Subject: [PATCH] Fixed attendee login --- HIAPI/Models/Profile.swift | 28 +++++++++---------- .../DataSources/HIProfileDataSource.swift | 8 +++--- .../HILoginFlowController.swift | 16 ++++++----- HackIllinois/Misc/MixTypeComparable.swift | 4 +-- HackIllinois/Models/HIProfile.swift | 9 +++--- .../HIProfileViewController.swift | 15 +++++----- 6 files changed, 39 insertions(+), 41 deletions(-) diff --git a/HIAPI/Models/Profile.swift b/HIAPI/Models/Profile.swift index faf6318b..4a29da1f 100644 --- a/HIAPI/Models/Profile.swift +++ b/HIAPI/Models/Profile.swift @@ -25,26 +25,24 @@ public struct ProfileContainer: Decodable, APIReturnable { public struct Profile: Codable, APIReturnable { internal enum CodingKeys: String, CodingKey { - case id - case firstName - case lastName + case userId + case displayName case points - case foodWave - case discord + //case foodWave + case discordTag case avatarUrl } - public let id: String - public let firstName: String - public let lastName: String + public let userId: String + public let displayName: String public let points: Int - public let foodWave: Int - public let discord: String + //public let foodWave: Int + public let discordTag: String public let avatarUrl: String } public struct ProfileFavorites: Codable, APIReturnable { - public let id: String + public let userId: String public let profiles: Set } @@ -60,13 +58,13 @@ public struct LeaderboardProfileContainer: Decodable, APIReturnable { public struct LeaderboardProfile: Codable, APIReturnable { internal enum CodingKeys: String, CodingKey { - case id - case discord + case userId + case discordTag case points } - public let id: String - public let discord: String + public let userId: String + public let discordTag: String public let points: Int } diff --git a/HackIllinois/DataSources/HIProfileDataSource.swift b/HackIllinois/DataSources/HIProfileDataSource.swift index abf56805..2310622f 100644 --- a/HackIllinois/DataSources/HIProfileDataSource.swift +++ b/HackIllinois/DataSources/HIProfileDataSource.swift @@ -58,15 +58,15 @@ final class HIProfileDataSource { } coreDataProfilesToUpdate.forEach { (coreDataProfile, apiProfile) in // Update CoreData profile. - coreDataProfile.id = apiProfile.id - coreDataProfile.discord = apiProfile.discord + coreDataProfile.id = apiProfile.userId + coreDataProfile.discord = apiProfile.discordTag coreDataProfile.points = Int32(apiProfile.points) } apiProfilesToInsert.forEach { apiProfile in // Create CoreData profile. let coreDataProfile = LeaderboardProfile(context: context) - coreDataProfile.id = apiProfile.id - coreDataProfile.discord = apiProfile.discord + coreDataProfile.id = apiProfile.userId + coreDataProfile.discord = apiProfile.discordTag coreDataProfile.points = Int32(apiProfile.points) } diff --git a/HackIllinois/FlowControllers/HILoginFlowController.swift b/HackIllinois/FlowControllers/HILoginFlowController.swift index 0d6bcdb2..900e1262 100644 --- a/HackIllinois/FlowControllers/HILoginFlowController.swift +++ b/HackIllinois/FlowControllers/HILoginFlowController.swift @@ -185,7 +185,10 @@ private extension HILoginFlowController { user.roles = apiRolesContainer.roles profile.roles = apiRolesContainer.roles if user.provider == .github && user.roles.contains(.ATTENDEE) { - self?.populateRegistrationData(buildingUser: user, profile: profile, sender: sender) + DispatchQueue.main.async { + NotificationCenter.default.post(name: .loginUser, object: nil, userInfo: ["user": user]) + } + self?.populateProfileData(buildingProfile: profile, sender: sender) } else if user.provider == .google { if user.roles.contains(.STAFF) { DispatchQueue.main.async { @@ -210,7 +213,7 @@ private extension HILoginFlowController { .launch() } - private func populateRegistrationData(buildingUser user: HIUser, profile: HIProfile, sender: HIBaseViewController) { + /*private func populateRegistrationData(buildingUser user: HIUser, profile: HIProfile, sender: HIBaseViewController) { HIAPI.RegistrationService.getAttendee() .onCompletion { [weak self] result in do { @@ -229,7 +232,7 @@ private extension HILoginFlowController { } .authorize(with: user) .launch() - } + }*/ private func populateProfileData(buildingProfile profile: HIProfile, sender: HIBaseViewController) { HIAPI.ProfileService.getUserProfile() @@ -237,11 +240,10 @@ private extension HILoginFlowController { do { let (apiProfile, _) = try result.get() var profile = profile - profile.id = apiProfile.id - profile.firstName = apiProfile.firstName - profile.lastName = apiProfile.lastName + profile.userId = apiProfile.userId + profile.displayName = apiProfile.displayName profile.points = apiProfile.points - profile.discord = apiProfile.discord + profile.discordTag = apiProfile.discordTag profile.avatarUrl = apiProfile.avatarUrl DispatchQueue.main.async { NotificationCenter.default.post(name: .loginProfile, object: nil, userInfo: ["profile": profile]) diff --git a/HackIllinois/Misc/MixTypeComparable.swift b/HackIllinois/Misc/MixTypeComparable.swift index 89847d6e..f3562070 100644 --- a/HackIllinois/Misc/MixTypeComparable.swift +++ b/HackIllinois/Misc/MixTypeComparable.swift @@ -121,7 +121,7 @@ extension Project: MixTypeComparable { } extension HIAPI.Profile: MixTypeComparable { - var comparable: String { return id } + var comparable: String { return userId } } extension Profile: MixTypeComparable { @@ -129,7 +129,7 @@ extension Profile: MixTypeComparable { } extension HIAPI.LeaderboardProfile: MixTypeComparable { - var comparable: String { return id } + var comparable: String { return userId } } extension LeaderboardProfile: MixTypeComparable { diff --git a/HackIllinois/Models/HIProfile.swift b/HackIllinois/Models/HIProfile.swift index a5cbe5d8..289bb5c3 100644 --- a/HackIllinois/Models/HIProfile.swift +++ b/HackIllinois/Models/HIProfile.swift @@ -21,13 +21,12 @@ struct HIProfile: Codable { var attendee: HIAPI.Attendee? var token = "" var oauthCode = "" - var id = "" - var firstName = "" - var lastName = "" + var userId = "" + var displayName = "" var points = 0 - var foodWave = 0 + //var foodWave = 0 var timezone = "" - var discord = "" + var discordTag = "" var avatarUrl = "" init(provider: HIAPI.AuthService.OAuthProvider) { diff --git a/HackIllinois/ViewControllers/HIProfileViewController.swift b/HackIllinois/ViewControllers/HIProfileViewController.swift index da23af7e..abcbb273 100644 --- a/HackIllinois/ViewControllers/HIProfileViewController.swift +++ b/HackIllinois/ViewControllers/HIProfileViewController.swift @@ -73,13 +73,13 @@ extension HIProfileViewController { view.willRemoveSubview(profileCardController!.view) profileCardController?.removeFromParent() } - profileCardController = UIHostingController(rootView: HIProfileCardView(firstName: profile.firstName, - lastName: profile.lastName, + profileCardController = UIHostingController(rootView: HIProfileCardView(firstName: profile.displayName, + lastName: profile.displayName, dietaryRestrictions: dietaryRestrictions, points: profile.points, tier: profileTier, - foodWave: profile.foodWave, - id: profile.id + foodWave: 1,//profile.foodWave, + id: profile.userId )) addChild(profileCardController!) @@ -159,11 +159,10 @@ extension HIProfileViewController { .onCompletion { [weak self] result in do { let (apiProfile, _) = try result.get() - self?.profile.id = apiProfile.id - self?.profile.firstName = apiProfile.firstName - self?.profile.lastName = apiProfile.lastName + self?.profile.userId = apiProfile.userId + self?.profile.displayName = apiProfile.discordTag self?.profile.points = apiProfile.points - self?.profile.foodWave = apiProfile.foodWave + //self?.profile.foodWave = apiProfile.foodWave DispatchQueue.main.async { NotificationCenter.default.post(name: .loginProfile, object: nil, userInfo: ["profile": self?.profile]) self?.updateProfile()