diff --git a/PadelClub/Data/Club.swift b/PadelClub/Data/Club.swift index ccd2921..582701b 100644 --- a/PadelClub/Data/Club.swift +++ b/PadelClub/Data/Club.swift @@ -36,10 +36,10 @@ class Club : ModelObject, Storable, Hashable { var latitude: Double? var longitude: Double? var courtCount: Int = 2 + var broadcastCode: String? // var alphabeticalName: Bool = false - internal init(creator: String? = nil, name: String, acronym: String? = nil, phone: String? = nil, code: String? = nil, address: String? = nil, city: String? = nil, zipCode: String? = nil, latitude: Double? = nil, longitude: Double? = nil, courtCount: Int = 2) { - self.creator = creator + internal init(name: String, acronym: String? = nil, phone: String? = nil, code: String? = nil, address: String? = nil, city: String? = nil, zipCode: String? = nil, latitude: Double? = nil, longitude: Double? = nil, courtCount: Int = 2, broadcastCode: String? = nil) { self.name = name self.acronym = acronym ?? name.acronym() self.phone = phone @@ -50,6 +50,7 @@ class Club : ModelObject, Storable, Hashable { self.latitude = latitude self.longitude = longitude self.courtCount = courtCount + self.broadcastCode = broadcastCode } func clubTitle(_ displayStyle: DisplayStyle = .wide) -> String { @@ -86,6 +87,7 @@ class Club : ModelObject, Storable, Hashable { case _latitude = "latitude" case _longitude = "longitude" case _courtCount = "courtCount" + case _broadcastCode = "broadcastCode" // case _alphabeticalName = "alphabeticalName" } @@ -146,6 +148,13 @@ class Club : ModelObject, Storable, Hashable { } try container.encode(courtCount, forKey: ._courtCount) + + if let broadcastCode { + try container.encode(broadcastCode, forKey: ._broadcastCode) + } else { + try container.encodeNil(forKey: ._broadcastCode) + } + // try container.encode(alphabeticalName, forKey: ._alphabeticalName) } @@ -220,7 +229,7 @@ extension Club { if clubs.isEmpty == false { return clubs.first! } else { - return Club(creator: DataStore.shared.user.id, name: name, code: code) + return Club(name: name, code: code) } } } diff --git a/PadelClub/Data/MockData.swift b/PadelClub/Data/MockData.swift index 01266d7..9e838fd 100644 --- a/PadelClub/Data/MockData.swift +++ b/PadelClub/Data/MockData.swift @@ -25,7 +25,7 @@ extension Club { } static func newEmptyInstance() -> Club { - Club(creator: DataStore.shared.user.id, name: "", acronym: "") + Club(name: "", acronym: "") } } diff --git a/PadelClub/Data/README.md b/PadelClub/Data/README.md index c93d3a6..5afddab 100644 --- a/PadelClub/Data/README.md +++ b/PadelClub/Data/README.md @@ -4,7 +4,7 @@ Dans Swift: - Ajouter le champ dans classe - Ajouter le champ dans le constructeur si possible - Ajouter la codingKey correspondante -- Ajouter le champ dans l'encoding + decoding +- Ajouter le champ dans l'encoding - Ouvrir **ServerDataTests** et ajouter un test sur le champ - Pour que les tests sur les dates fonctionnent, on peut tester date.formatted() par exemple diff --git a/PadelClub/Views/User/ChangePasswordView.swift b/PadelClub/Views/User/ChangePasswordView.swift index bb1c329..67eaf8c 100644 --- a/PadelClub/Views/User/ChangePasswordView.swift +++ b/PadelClub/Views/User/ChangePasswordView.swift @@ -14,6 +14,9 @@ struct ChangePasswordView: View { @State var password1: String = "" @State var password2: String = "" + @State var isLoading: Bool = false + @State var errorMessage: String = "" + var body: some View { Form { @@ -29,6 +32,10 @@ struct ChangePasswordView: View { Text("Changer de mot de passe") }) .frame(maxWidth: .infinity) + } footer: { + if self.errorMessage.count > 0 { + Text(self.errorMessage).foregroundStyle(.red) + } } } .navigationTitle("Changer de mot de passe") @@ -37,13 +44,21 @@ struct ChangePasswordView: View { fileprivate func _changePassword() { Task { do { + self.isLoading = true let service = try Store.main.service() _ = try await service.changePassword( oldPassword: self.oldPassword, password1: self.password1, password2: self.password2) + self.isLoading = false } catch { Logger.error(error) + switch error { + case ServiceError.responseError(let reason): + self.errorMessage = reason + default: + self.errorMessage = error.localizedDescription + } } } diff --git a/PadelClub/Views/User/LoginView.swift b/PadelClub/Views/User/LoginView.swift index 199c89b..2ed3117 100644 --- a/PadelClub/Views/User/LoginView.swift +++ b/PadelClub/Views/User/LoginView.swift @@ -51,7 +51,11 @@ struct LoginView: View { Spacer() } } else { - Text("Connexion").frame(maxWidth: .infinity) + Text("Connexion") + .buttonStyle(.borderedProminent) + .tint(.orange) + .listRowBackground(Color.clear) + .frame(maxWidth: .infinity) } }) if let error = self.errorText { @@ -70,7 +74,8 @@ struct LoginView: View { Text("Mot passe oubliƩ") }) .alert( - Text("Changer de mot de passe"), + Text("Changer de mot de passe") + , isPresented: self.$showEmailPopup ) { EmailConfirmationView() @@ -125,6 +130,7 @@ struct LoginView: View { struct EmailConfirmationView: View { @State var email: String = "" + @State var errorMessage: String = "" var body: some View { VStack { @@ -147,6 +153,14 @@ struct EmailConfirmationView: View { try await service.forgotPassword(email: self.email) } catch { Logger.error(error) + + switch error { + case ServiceError.responseError(let reason): + self.errorMessage = reason + default: + self.errorMessage = error.localizedDescription + } + Logger.log(self.errorMessage) } } } diff --git a/PadelClubTests/ServerDataTests.swift b/PadelClubTests/ServerDataTests.swift index b6a16dc..b1d80db 100644 --- a/PadelClubTests/ServerDataTests.swift +++ b/PadelClubTests/ServerDataTests.swift @@ -45,6 +45,7 @@ final class ServerDataTests: XCTestCase { club.latitude = 13 club.longitude = 10 club.phone = "061234567890" + club.courtCount = 3 let inserted_club: Club = try await Store.main.service().post(club) assert(inserted_club.name == club.name) @@ -54,6 +55,8 @@ final class ServerDataTests: XCTestCase { assert(inserted_club.latitude == club.latitude) assert(inserted_club.longitude == club.longitude) assert(inserted_club.phone == club.phone) + assert(inserted_club.courtCount == club.courtCount) + assert(inserted_club.broadcastCode != nil) inserted_club.phone = "123456" diff --git a/PadelClubTests/TokenExemptionTests.swift b/PadelClubTests/TokenExemptionTests.swift index 8423ab7..61831eb 100644 --- a/PadelClubTests/TokenExemptionTests.swift +++ b/PadelClubTests/TokenExemptionTests.swift @@ -29,7 +29,7 @@ final class TokenExemptionTests: XCTestCase { let user = try await self.login() Store.main.disconnect() - let club: Club = Club(creator: user.id, name: "mon club 2", acronym: "MC", phone: "132", code: "456", address: "l'adresse", city: "la ville", zipCode: "13131", latitude: 13.11111, longitude: 1.121212) + let club: Club = Club(name: "mon club 2", acronym: "MC", phone: "132", code: "456", address: "l'adresse", city: "la ville", zipCode: "13131", latitude: 13.11111, longitude: 1.121212) let c = try await Store.main.service().post(club) assert(c.id == club.id)