Change to server url configuration

sync2
Laurent 12 months ago
parent c85dbad3ca
commit 3feea9b22f
  1. 14
      PadelClub/Data/DataStore.swift
  2. 89
      PadelClub/Utils/Patcher.swift
  3. 10
      PadelClub/Utils/URLs.swift
  4. 3
      PadelClubTests/ServerDataTests.swift
  5. 2
      PadelClubTests/SynchronizationTests.swift
  6. 2
      PadelClubTests/TokenExemptionTests.swift
  7. 2
      PadelClubTests/UserDataTests.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)

@ -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)
}
}
}
}
}

@ -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"

@ -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()

@ -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 {

@ -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()
}

@ -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 {

Loading…
Cancel
Save