Skip to content

Commit

Permalink
Merge pull request #548 from HackIllinois/sophia/fix-attendee-login-test
Browse files Browse the repository at this point in the history
Fix attendee login and refactor profile model
  • Loading branch information
s0phialiu authored Dec 3, 2023
2 parents 03a284d + f2ffb86 commit c5098a0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 48 deletions.
28 changes: 13 additions & 15 deletions HIAPI/Models/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
}

Expand All @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions HackIllinois/DataSources/HIProfileDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
12 changes: 7 additions & 5 deletions HackIllinois/FlowControllers/HILoginFlowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
self?.populateProfileData(buildingProfile: profile, sender: sender)
DispatchQueue.main.async {
NotificationCenter.default.post(name: .loginUser, object: nil, userInfo: ["user": user])
}
} else if user.provider == .google {
if user.roles.contains(.STAFF) {
DispatchQueue.main.async {
Expand Down Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions HackIllinois/Misc/MixTypeComparable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ extension Project: MixTypeComparable {
}

extension HIAPI.Profile: MixTypeComparable {
var comparable: String { return id }
var comparable: String { return userId }
}

extension Profile: MixTypeComparable {
var comparable: String { return id }
}

extension HIAPI.LeaderboardProfile: MixTypeComparable {
var comparable: String { return id }
var comparable: String { return userId }
}

extension LeaderboardProfile: MixTypeComparable {
Expand Down
9 changes: 4 additions & 5 deletions HackIllinois/Models/HIProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 15 additions & 9 deletions HackIllinois/ViewControllers/HIProfileCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import SwiftUI
import HIAPI

struct HIProfileCardView: View {
let firstName: String
let lastName: String
let displayName: String
let dietaryRestrictions: [String]
let points: Int
let tier: String
let foodWave: Int
let background = (\HIAppearance.profileCardBackground).value
let baseText = (\HIAppearance.profileBaseText).value
let id: String
let userId: String
let isIpad = UIDevice.current.userInterfaceIdiom == .pad
@State var flipped: Bool = false
@State var ticketRotation = 0.0
Expand Down Expand Up @@ -157,10 +156,18 @@ struct HIProfileCardView: View {
}

func formatName() -> String {
if lastName.count + firstName.count > 20 {
return firstName + " " + lastName.prefix(1) + "."
if displayName.count > 20 {
let names = displayName.split(separator: " ")
if names.count >= 2 {
let firstName = String(names[0])
let lastName = String(names[1])
let abbreviatedName = firstName + " " + String(lastName.prefix(1)) + "."
return abbreviatedName
} else {
return displayName
}
} else {
return firstName + " " + lastName
return displayName
}
}

Expand Down Expand Up @@ -268,13 +275,12 @@ struct HIProfileCardView: View {

struct HIProfileCardView_Previews: PreviewProvider {
static var previews: some View {
HIProfileCardView(firstName: "first",
lastName: "last",
HIProfileCardView(displayName: "first last",
dietaryRestrictions: ["Vegetarian", "Lactose-Intolerant", "None", "no beef"],
points: 100,
tier: "no tier",
foodWave: 1,
id: "https://www.hackillinois.org"
userId: "https://www.hackillinois.org"
)
}
}
14 changes: 6 additions & 8 deletions HackIllinois/ViewControllers/HIProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ extension HIProfileViewController {
view.willRemoveSubview(profileCardController!.view)
profileCardController?.removeFromParent()
}
profileCardController = UIHostingController(rootView: HIProfileCardView(firstName: profile.firstName,
lastName: profile.lastName,
profileCardController = UIHostingController(rootView: HIProfileCardView(displayName: profile.displayName,
dietaryRestrictions: dietaryRestrictions,
points: profile.points,
tier: profileTier,
foodWave: profile.foodWave,
id: profile.id
foodWave: 1,//profile.foodWave,
userId: profile.userId
))

addChild(profileCardController!)
Expand Down Expand Up @@ -159,11 +158,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()
Expand Down

0 comments on commit c5098a0

Please sign in to comment.