From 3feea9b22f2f27f925969e8db82d66504a9146a6 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 18 Nov 2024 17:25:18 +0100 Subject: [PATCH] Change to server url configuration --- PadelClub/Data/DataStore.swift | 14 ++-- PadelClub/Utils/Patcher.swift | 89 ----------------------- PadelClub/Utils/URLs.swift | 10 +-- PadelClubTests/ServerDataTests.swift | 3 +- PadelClubTests/SynchronizationTests.swift | 2 +- PadelClubTests/TokenExemptionTests.swift | 2 +- PadelClubTests/UserDataTests.swift | 2 +- 7 files changed, 18 insertions(+), 104 deletions(-) diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index 538a35c..dc5b308 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -52,17 +52,20 @@ class DataStore: ObservableObject { init() { let store = Store.main - let serverURL: String = URLs.api.rawValue StoreCenter.main.blackListUserName("apple-test") + let httpScheme: String = URLs.httpScheme.rawValue + let domain: String = URLs.activationHost.rawValue + #if DEBUG - if let server = PListReader.readString(plist: "local", key: "server") { - StoreCenter.main.synchronizationApiURL = server + if let scheme = PListReader.readString(plist: "local", key: "server_scheme"), + let domain = PListReader.readString(plist: "local", key: "server_domain"){ + StoreCenter.main.configureURLs(httpScheme: scheme, domain: domain) } else { - StoreCenter.main.synchronizationApiURL = serverURL + StoreCenter.main.configureURLs(httpScheme: httpScheme, domain: domain) } #else - StoreCenter.main.synchronizationApiURL = serverURL + StoreCenter.main.configureURLs(httpScheme: httpScheme, domain: domain) #endif StoreCenter.main.logsFailedAPICalls() @@ -77,7 +80,6 @@ class DataStore: ObservableObject { StoreCenter.main.forceNoSynchronization = !synchronized - Logger.log("Sync URL: \(StoreCenter.main.synchronizationApiURL ?? "none"), sync: \(synchronized) ") let indexed: Bool = true self.clubs = store.registerSynchronizedCollection(indexed: indexed) diff --git a/PadelClub/Utils/Patcher.swift b/PadelClub/Utils/Patcher.swift index 0ef8dc6..cefbf60 100644 --- a/PadelClub/Utils/Patcher.swift +++ b/PadelClub/Utils/Patcher.swift @@ -66,99 +66,10 @@ class Patcher { fileprivate static func _importDataFromDev() throws { - let devServices = Services(url: "https://xlr.alwaysdata.net/roads/") - guard devServices.hasToken() else { - return - } - guard StoreCenter.main.synchronizationApiURL == "https://padelclub.app/roads/" else { - return - } - - guard let userId = StoreCenter.main.userId else { - return - } - - try StoreCenter.main.migrateToken(devServices) - - - let myClubs: [Club] = DataStore.shared.clubs.filter { $0.creator == userId } - let clubIds: [String] = myClubs.map { $0.id } - - myClubs.forEach { club in - DataStore.shared.clubs.insertIntoCurrentService(item: club) - - let courts = DataStore.shared.courts.filter { clubIds.contains($0.club) } - for court in courts { - DataStore.shared.courts.insertIntoCurrentService(item: court) - } - } - - DataStore.shared.user.clubs = Array(clubIds) - DataStore.shared.saveUser() - - DataStore.shared.events.insertAllIntoCurrentService() - DataStore.shared.tournaments.insertAllIntoCurrentService() - DataStore.shared.dateIntervals.insertAllIntoCurrentService() - - for tournament in DataStore.shared.tournaments { - let store = tournament.tournamentStore - - Task { // need to wait for the collections to load - try await Task.sleep(until: .now + .seconds(2)) - - store.teamRegistrations.insertAllIntoCurrentService() - store.rounds.insertAllIntoCurrentService() - store.groupStages.insertAllIntoCurrentService() - store.matches.insertAllIntoCurrentService() - store.playerRegistrations.insertAllIntoCurrentService() - store.teamScores.insertAllIntoCurrentService() - - } - } - } fileprivate static func _patchMissingMatches() { - guard let url = StoreCenter.main.synchronizationApiURL else { - return - } - guard url == "https://padelclub.app/roads/" else { - return - } - let services = Services(url: url) - - for tournament in DataStore.shared.tournaments { - - let store = tournament.tournamentStore - let identifier = tournament.id - - Task { - - do { - // if nothing is online we upload the data - let matches: [Match] = try await services.get(identifier: identifier) - if matches.isEmpty { - store.matches.insertAllIntoCurrentService() - } - - let playerRegistrations: [PlayerRegistration] = try await services.get(identifier: identifier) - if playerRegistrations.isEmpty { - store.playerRegistrations.insertAllIntoCurrentService() - } - - let teamScores: [TeamScore] = try await services.get(identifier: identifier) - if teamScores.isEmpty { - store.teamScores.insertAllIntoCurrentService() - } - - } catch { - Logger.error(error) - } - - } - } - } } diff --git a/PadelClub/Utils/URLs.swift b/PadelClub/Utils/URLs.swift index 16e0fba..777e77a 100644 --- a/PadelClub/Utils/URLs.swift +++ b/PadelClub/Utils/URLs.swift @@ -8,23 +8,23 @@ import Foundation enum URLs: String, Identifiable { - + case httpScheme = "https://" #if DEBUG case activationHost = "xlr.alwaysdata.net" case main = "https://xlr.alwaysdata.net/" - case api = "https://xlr.alwaysdata.net/roads/" +// case api = "https://xlr.alwaysdata.net/roads/" #elseif TESTFLIGHT case activationHost = "xlr.alwaysdata.net" case main = "https://xlr.alwaysdata.net/" - case api = "https://xlr.alwaysdata.net/roads/" +// case api = "https://xlr.alwaysdata.net/roads/" #elseif PRODTEST case activationHost = "padelclub.app" case main = "https://padelclub.app/" - case api = "https://padelclub.app/roads/" +// case api = "https://padelclub.app/roads/" #else case activationHost = "padelclub.app" case main = "https://padelclub.app/" - case api = "https://padelclub.app/roads/" +// case api = "https://padelclub.app/roads/" #endif case subscriptions = "https://apple.co/2Th4vqI" diff --git a/PadelClubTests/ServerDataTests.swift b/PadelClubTests/ServerDataTests.swift index 8d44e9c..d71c522 100644 --- a/PadelClubTests/ServerDataTests.swift +++ b/PadelClubTests/ServerDataTests.swift @@ -15,7 +15,8 @@ final class ServerDataTests: XCTestCase { let password: String = "MyPass1234--" override func setUpWithError() throws { - StoreCenter.main.synchronizationApiURL = "http://127.0.0.1:8000/roads/" +// StoreCenter.main.synchronizationApiURL = "http://127.0.0.1:8000/roads/" + StoreCenter.main.configureURLs(httpScheme: "http://", domain: "127.0.0.1:8000") Task { do { try await self.login() diff --git a/PadelClubTests/SynchronizationTests.swift b/PadelClubTests/SynchronizationTests.swift index 0c2313d..1312527 100644 --- a/PadelClubTests/SynchronizationTests.swift +++ b/PadelClubTests/SynchronizationTests.swift @@ -15,7 +15,7 @@ struct SynchronizationTests { let password: String = "StaxKikoo12" init() { - StoreCenter.main.synchronizationApiURL = "http://127.0.0.1:8000/roads/" + StoreCenter.main.configureURLs(httpScheme: "http://", domain: "127.0.0.1:8000") } @Test func synchronizationTest() async throws { diff --git a/PadelClubTests/TokenExemptionTests.swift b/PadelClubTests/TokenExemptionTests.swift index 923be80..764cd2d 100644 --- a/PadelClubTests/TokenExemptionTests.swift +++ b/PadelClubTests/TokenExemptionTests.swift @@ -16,7 +16,7 @@ final class TokenExemptionTests: XCTestCase { let password: String = "MyPass1234--" override func setUpWithError() throws { - StoreCenter.main.synchronizationApiURL = "http://127.0.0.1:8000/roads/" + StoreCenter.main.configureURLs(httpScheme: "http://", domain: "127.0.0.1:8000") StoreCenter.main.disconnect() } diff --git a/PadelClubTests/UserDataTests.swift b/PadelClubTests/UserDataTests.swift index 8b848d5..5d10a59 100644 --- a/PadelClubTests/UserDataTests.swift +++ b/PadelClubTests/UserDataTests.swift @@ -15,7 +15,7 @@ final class UserDataTests: XCTestCase { let password: String = "MyPass1234--" override func setUpWithError() throws { - StoreCenter.main.synchronizationApiURL = "http://127.0.0.1:8000/roads/" + StoreCenter.main.configureURLs(httpScheme: "http://", domain: "127.0.0.1:8000") } override func tearDownWithError() throws {