Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.3 #1

Merged
merged 27 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7188d29
Create new UserManager and User type
wissehes Jan 18, 2023
0cc533a
Create new AuthManager and rename old AuthManager
wissehes Jan 18, 2023
7c5c4af
update API methods
wissehes Jan 18, 2023
d049782
Remove "me" argument from all views/viewmodels since this is no longe…
wissehes Jan 18, 2023
139ebc9
Remove "me" argument
wissehes Jan 18, 2023
f576ed3
Add "school" argument
wissehes Jan 18, 2023
e351457
add welcomeScreenClosed handler
wissehes Jan 18, 2023
7ea15ac
Fix weird glitch where the welcome screen would flash on first open
wissehes Jan 18, 2023
3f813ea
Only run firebase when not in simulator
wissehes Jan 18, 2023
f2b5a0c
Add users to settings
wissehes Jan 18, 2023
9d6d36c
Create a work-in-progress addUserView
wissehes Jan 18, 2023
9fc0411
Fix notifications not being localized
wissehes Jan 19, 2023
d6ef4f5
Add getToken API method
wissehes Jan 19, 2023
be6bc27
Create method for adding user
wissehes Jan 19, 2023
6f95604
Add addUser method to the AuthManager
wissehes Jan 19, 2023
27ee8c0
Update translations
wissehes Jan 19, 2023
8fb8844
Add setCurrent method
wissehes Jan 19, 2023
cbf4611
Add id property to User
wissehes Jan 19, 2023
3a2f452
Move account selector to separate view
wissehes Jan 19, 2023
4c56257
Update AddUserView
wissehes Jan 19, 2023
45f9c67
Fix homescreen stuck on loading
wissehes Jan 20, 2023
9ba8098
Add selector for the user notifications should be for
wissehes Jan 20, 2023
801f6e1
Only update notifications if the current user matches
wissehes Jan 20, 2023
a4803af
other thingies
wissehes Jan 20, 2023
3b3c881
Remove print statements
wissehes Jan 20, 2023
c523be5
Update localisation
wissehes Jan 21, 2023
b21b316
increment build version and number
wissehes Jan 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 64 additions & 4 deletions Rooster voor Zermelo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
/* Begin PBXBuildFile section */
8905E44F28DB292D00CA8027 /* AboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8905E44E28DB292D00CA8027 /* AboutView.swift */; };
8905E45128DB5C3700CA8027 /* AuthManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8905E45028DB5C3700CA8027 /* AuthManager.swift */; };
8906E334297AEEA20064F3B1 /* NotificationSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8906E333297AEEA20064F3B1 /* NotificationSettings.swift */; };
890F82442979426E005F6E27 /* Userlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890F82432979426E005F6E27 /* Userlist.swift */; };
891829222976B54B0003F81A /* UsersViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891829212976B54B0003F81A /* UsersViewModel.swift */; };
891829242976B5630003F81A /* UserListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891829232976B5630003F81A /* UserListItem.swift */; };
891829262976B6150003F81A /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891829252976B6150003F81A /* User.swift */; };
891829282976BAA80003F81A /* UserManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891829272976BAA80003F81A /* UserManager.swift */; };
892632DE28C3A94400B9C624 /* Rooster_voor_ZermeloApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892632DD28C3A94400B9C624 /* Rooster_voor_ZermeloApp.swift */; };
892632E028C3A94400B9C624 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892632DF28C3A94400B9C624 /* ContentView.swift */; };
892632E228C3A94600B9C624 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 892632E128C3A94600B9C624 /* Assets.xcassets */; };
Expand All @@ -17,10 +23,13 @@
892AA7DB296D8AD000BC883D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 892AA7DD296D8AD000BC883D /* Localizable.strings */; };
892DDA2C2974794100E0592E /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892DDA2B2974794000E0592E /* SettingsView.swift */; };
892DDA2E29747E2100E0592E /* NotificationsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892DDA2D29747E2000E0592E /* NotificationsManager.swift */; };
89346ECF29784A8A006E1651 /* NewAuthManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89346ECE29784A8A006E1651 /* NewAuthManager.swift */; };
89346ED22978978F006E1651 /* AddUserView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89346ED12978978F006E1651 /* AddUserView.swift */; };
8947BD3828C793060063E3DF /* WeekView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8947BD3728C793060063E3DF /* WeekView.swift */; };
8947BD3A28C7932E0063E3DF /* WeekViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8947BD3928C7932E0063E3DF /* WeekViewModel.swift */; };
8947BD3C28C797B40063E3DF /* DayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8947BD3B28C797B40063E3DF /* DayView.swift */; };
8965E2D528C3D06D001D9B8E /* CodeScanner in Frameworks */ = {isa = PBXBuildFile; productRef = 8965E2D428C3D06D001D9B8E /* CodeScanner */; };
896EAC7729799CD400FB0B05 /* SettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 896EAC7629799CD400FB0B05 /* SettingsViewModel.swift */; };
897038C628FDE11600773BCD /* NewWeekView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 897038C528FDE11600773BCD /* NewWeekView.swift */; };
8982676E28C68E0000C85D12 /* AppointmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8982676D28C68E0000C85D12 /* AppointmentView.swift */; };
898C925428C3D65F00100AD6 /* ZermeloQRData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 898C925328C3D65F00100AD6 /* ZermeloQRData.swift */; };
Expand All @@ -43,6 +52,12 @@
/* Begin PBXFileReference section */
8905E44E28DB292D00CA8027 /* AboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; };
8905E45028DB5C3700CA8027 /* AuthManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthManager.swift; sourceTree = "<group>"; };
8906E333297AEEA20064F3B1 /* NotificationSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSettings.swift; sourceTree = "<group>"; };
890F82432979426E005F6E27 /* Userlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Userlist.swift; sourceTree = "<group>"; };
891829212976B54B0003F81A /* UsersViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UsersViewModel.swift; sourceTree = "<group>"; };
891829232976B5630003F81A /* UserListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserListItem.swift; sourceTree = "<group>"; };
891829252976B6150003F81A /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
891829272976BAA80003F81A /* UserManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserManager.swift; sourceTree = "<group>"; };
892632DA28C3A94400B9C624 /* Rooster voor Zermelo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Rooster voor Zermelo.app"; sourceTree = BUILT_PRODUCTS_DIR; };
892632DD28C3A94400B9C624 /* Rooster_voor_ZermeloApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rooster_voor_ZermeloApp.swift; sourceTree = "<group>"; };
892632DF28C3A94400B9C624 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand All @@ -53,10 +68,13 @@
892AA7DE296D8AD300BC883D /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Localizable.strings; sourceTree = "<group>"; };
892DDA2B2974794000E0592E /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
892DDA2D29747E2000E0592E /* NotificationsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsManager.swift; sourceTree = "<group>"; };
89346ECE29784A8A006E1651 /* NewAuthManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewAuthManager.swift; sourceTree = "<group>"; };
89346ED12978978F006E1651 /* AddUserView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddUserView.swift; sourceTree = "<group>"; };
8947BD3728C793060063E3DF /* WeekView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekView.swift; sourceTree = "<group>"; };
8947BD3928C7932E0063E3DF /* WeekViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekViewModel.swift; sourceTree = "<group>"; };
8947BD3B28C797B40063E3DF /* DayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayView.swift; sourceTree = "<group>"; };
8965E2D628C3D296001D9B8E /* Rooster-voor-Zermelo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = "Rooster-voor-Zermelo-Info.plist"; sourceTree = SOURCE_ROOT; };
896EAC7629799CD400FB0B05 /* SettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewModel.swift; sourceTree = "<group>"; };
897038C528FDE11600773BCD /* NewWeekView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewWeekView.swift; sourceTree = "<group>"; };
8982676D28C68E0000C85D12 /* AppointmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppointmentView.swift; sourceTree = "<group>"; };
8986658128DB8DD000D7A98C /* week.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = week.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -94,6 +112,28 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
890F824529794286005F6E27 /* Users */ = {
isa = PBXGroup;
children = (
891829212976B54B0003F81A /* UsersViewModel.swift */,
891829232976B5630003F81A /* UserListItem.swift */,
890F82432979426E005F6E27 /* Userlist.swift */,
);
path = Users;
sourceTree = "<group>";
};
891829202976B53D0003F81A /* Settings */ = {
isa = PBXGroup;
children = (
890F824529794286005F6E27 /* Users */,
89346ED029789779006E1651 /* AddUserView */,
892DDA2B2974794000E0592E /* SettingsView.swift */,
896EAC7629799CD400FB0B05 /* SettingsViewModel.swift */,
8906E333297AEEA20064F3B1 /* NotificationSettings.swift */,
);
path = Settings;
sourceTree = "<group>";
};
892632D128C3A94400B9C624 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -141,17 +181,25 @@
892632EB28C3A95800B9C624 /* Views */ = {
isa = PBXGroup;
children = (
891829202976B53D0003F81A /* Settings */,
8947BD3628C792F20063E3DF /* WeekView */,
89BC860228E2DEAE006BEC62 /* AppointmentView */,
89ED829D28C5349C00306872 /* HomeView */,
892632EC28C3A96100B9C624 /* WelcomeView.swift */,
8947BD3B28C797B40063E3DF /* DayView.swift */,
8905E44E28DB292D00CA8027 /* AboutView.swift */,
892DDA2B2974794000E0592E /* SettingsView.swift */,
);
path = Views;
sourceTree = "<group>";
};
89346ED029789779006E1651 /* AddUserView */ = {
isa = PBXGroup;
children = (
89346ED12978978F006E1651 /* AddUserView.swift */,
);
path = AddUserView;
sourceTree = "<group>";
};
8947BD3628C792F20063E3DF /* WeekView */ = {
isa = PBXGroup;
children = (
Expand All @@ -178,8 +226,9 @@
children = (
89ED82A228C53D1800306872 /* ZermeloHTTP */,
898C925328C3D65F00100AD6 /* ZermeloQRData.swift */,
89ED829A28C530C000306872 /* SavedToken.swift */,
89ACDEFB2972DAEF008C8640 /* DemoTokenResponse.swift */,
891829252976B6150003F81A /* User.swift */,
89ED829A28C530C000306872 /* SavedToken.swift */,
);
path = Types;
sourceTree = "<group>";
Expand All @@ -200,6 +249,8 @@
89F7051E28C682A000AFF2DF /* API.swift */,
8905E45028DB5C3700CA8027 /* AuthManager.swift */,
892DDA2D29747E2000E0592E /* NotificationsManager.swift */,
891829272976BAA80003F81A /* UserManager.swift */,
89346ECE29784A8A006E1651 /* NewAuthManager.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -331,6 +382,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
891829262976B6150003F81A /* User.swift in Sources */,
8982676E28C68E0000C85D12 /* AppointmentView.swift in Sources */,
8905E45128DB5C3700CA8027 /* AuthManager.swift in Sources */,
8947BD3C28C797B40063E3DF /* DayView.swift in Sources */,
Expand All @@ -343,17 +395,25 @@
89ED829928C5307F00306872 /* TokenSaver.swift in Sources */,
89ACDEFC2972DAEF008C8640 /* DemoTokenResponse.swift in Sources */,
89ED82A428C53D2E00306872 /* ZermeloLivescheduleResponse.swift in Sources */,
8906E334297AEEA20064F3B1 /* NotificationSettings.swift in Sources */,
898C925428C3D65F00100AD6 /* ZermeloQRData.swift in Sources */,
89346ECF29784A8A006E1651 /* NewAuthManager.swift in Sources */,
898C925928C3D7FB00100AD6 /* ZermeloTokenRequest.swift in Sources */,
89ED829B28C530C000306872 /* SavedToken.swift in Sources */,
89ED829F28C534A200306872 /* HomeView.swift in Sources */,
896EAC7729799CD400FB0B05 /* SettingsViewModel.swift in Sources */,
890F82442979426E005F6E27 /* Userlist.swift in Sources */,
89ED82A128C53ADB00306872 /* ZermeloMeResponse.swift in Sources */,
891829282976BAA80003F81A /* UserManager.swift in Sources */,
8947BD3828C793060063E3DF /* WeekView.swift in Sources */,
892632ED28C3A96100B9C624 /* WelcomeView.swift in Sources */,
89346ED22978978F006E1651 /* AddUserView.swift in Sources */,
891829242976B5630003F81A /* UserListItem.swift in Sources */,
89BC860428E2DEC6006BEC62 /* AppointmentActionView.swift in Sources */,
89F7051F28C682A000AFF2DF /* API.swift in Sources */,
892632DE28C3A94400B9C624 /* Rooster_voor_ZermeloApp.swift in Sources */,
892DDA2C2974794100E0592E /* SettingsView.swift in Sources */,
891829222976B54B0003F81A /* UsersViewModel.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -513,7 +573,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = "nl.wissehes.Rooster-voor-Zermelo";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -546,7 +606,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = "nl.wissehes.Rooster-voor-Zermelo";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
69 changes: 57 additions & 12 deletions Rooster voor Zermelo/Helpers/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ final class API {
}
}

static func getLiveSchedule(me: ZermeloMeData, completion: @escaping (Result<[ZermeloLivescheduleAppointment], AFError>) -> Void) {
guard let token = TokenSaver.get() else { return completion(.success([])) }
static func getLiveSchedule(completion: @escaping (Result<[ZermeloLivescheduleAppointment], AFError>) -> Void) {
guard let user = UserManager.getCurrent() else { return completion(.success([])) }

let params: Parameters = [
"student": me.code,
"student": user.me.code,
"week": getWeek(nil)
]
let headers: HTTPHeaders = [
"Authorization": "Bearer \(token.access_token)"
"Authorization": "Bearer \(user.token.access_token)"
]

AF.request("https://\(token.portal).zportal.nl/api/v3/liveschedule", parameters: params, headers: headers)
AF.request("https://\(user.token.portal).zportal.nl/api/v3/liveschedule", parameters: params, headers: headers)
.validate()
.responseDecodable(of: GetZermeloLiveschedule.self) { response in
switch response.result {
Expand All @@ -48,17 +48,17 @@ final class API {
}
}

static func getLiveScheduleAsync(me: ZermeloMeData, week: String = getWeek(nil)) async throws -> [ZermeloLivescheduleAppointment] {
guard let token = TokenSaver.get() else { fatalError("No token") }
static func getLiveScheduleAsync(week: String = getWeek(nil)) async throws -> [ZermeloLivescheduleAppointment] {
guard let user = UserManager.getCurrent() else { fatalError("No token") }

guard var url = URLComponents(string: "https://\(token.portal).zportal.nl/api/v3/liveschedule") else { fatalError("url error") }
guard var url = URLComponents(string: "https://\(user.token.portal).zportal.nl/api/v3/liveschedule") else { fatalError("url error") }
url.queryItems = [
URLQueryItem(name: "student", value: me.code),
URLQueryItem(name: "student", value: user.me.code),
URLQueryItem(name: "week", value: week)
]

var urlRequest = URLRequest(url: url.url!)
urlRequest.addValue("Bearer \(token.access_token)", forHTTPHeaderField: "Authorization")
urlRequest.addValue("Bearer \(user.token.access_token)", forHTTPHeaderField: "Authorization")

let (data, _) = try await URLSession.shared.data(for: urlRequest)

Expand All @@ -68,8 +68,8 @@ final class API {
} else { return [] }
}

static func getScheduleForDay(me: ZermeloMeData, date: Date) async throws -> [ZermeloLivescheduleAppointment] {
let weekAppointments = try await self.getLiveScheduleAsync(me: me, week: getWeek(date))
static func getScheduleForDay(date: Date) async throws -> [ZermeloLivescheduleAppointment] {
let weekAppointments = try await self.getLiveScheduleAsync(week: getWeek(date))

if weekAppointments.isEmpty {
return []
Expand All @@ -82,5 +82,50 @@ final class API {

return filtered
}

static func fetchMe(token: SavedToken, completion: @escaping (Result<ZermeloMeData, FetchError>) -> ()) {
let headers: HTTPHeaders = [
"Authorization": "Bearer \(token.access_token)"
]

AF.request("https://\(token.portal).zportal.nl/api/v3/users/~me", headers: headers)
.validate()
.responseDecodable(of: GetZermeloMe.self) { response in
switch response.result {
case .success(let data):
guard let me = data.response.data.first else {
completion(.failure(.noData))
return
}
completion(.success(me))
case .failure(let err):
completion(.failure(.AFError(error: err)))
}
}
}

static func getToken(_ data: ZermeloQRData, completion: @escaping (Result<SavedToken, AFError>) -> ()) {

let params: Parameters = [
"grant_type": "authorization_code",
"code": data.code
]
AF.request("https://\(data.institution).zportal.nl/api/v3/oauth/token", method: .post, parameters: params)
.validate()
.responseDecodable(of: ZermeloTokenRequest.self){ response in
switch response.result {
case .failure(let err):
completion(.failure(err))
case .success(let tokenInfo):
let tokenData = SavedToken.init(qrData: data, tokenInfo: tokenInfo)
completion(.success(tokenData))
}
}
}

}

enum FetchError: Error {
case noData
case AFError(error: AFError)
}
2 changes: 1 addition & 1 deletion Rooster voor Zermelo/Helpers/AuthManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import Alamofire

class AuthManager: ObservableObject {
class OldAuthManager: ObservableObject {
@Published var isLoading = true
@Published var me: ZermeloMeData? = nil
@Published var token: SavedToken? = nil
Expand Down
Loading