Adds broadcastCode to Club + minor improvements

multistore
Laurent 1 year ago
parent a1e9b6e8d0
commit 16bbfd21ec
  1. 15
      PadelClub/Data/Club.swift
  2. 2
      PadelClub/Data/MockData.swift
  3. 2
      PadelClub/Data/README.md
  4. 15
      PadelClub/Views/User/ChangePasswordView.swift
  5. 18
      PadelClub/Views/User/LoginView.swift
  6. 3
      PadelClubTests/ServerDataTests.swift
  7. 2
      PadelClubTests/TokenExemptionTests.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)
}
}
}

@ -25,7 +25,7 @@ extension Club {
}
static func newEmptyInstance() -> Club {
Club(creator: DataStore.shared.user.id, name: "", acronym: "")
Club(name: "", acronym: "")
}
}

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

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

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

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

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

Loading…
Cancel
Save