fix mistake ispublic

fix/bet-creation
Lucas DELANIER 8 months ago
parent 5ce52cff75
commit c3f4ac0a68

@ -77,7 +77,7 @@ struct BetCard_Previews: PreviewProvider {
phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.", phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.",
endRegisterDate: Date().addingTimeInterval(86400), endRegisterDate: Date().addingTimeInterval(86400),
endBetDate: Date().addingTimeInterval(172800), endBetDate: Date().addingTimeInterval(172800),
isPublic: true, isPrivate: false,
status: .inProgress, status: .inProgress,
invited: [], invited: [],
author: "Imri", author: "Imri",

@ -77,7 +77,7 @@ struct TrendingBetCard_Previews: PreviewProvider {
phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.", phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.",
endRegisterDate: Date().addingTimeInterval(86400), endRegisterDate: Date().addingTimeInterval(86400),
endBetDate: Date().addingTimeInterval(172800), endBetDate: Date().addingTimeInterval(172800),
isPublic: true, isPrivate: true,
status: .inProgress, status: .inProgress,
invited: [], invited: [],
author: "Imri", author: "Imri",

@ -15,7 +15,7 @@ class CreationBetViewModel: ObservableObject {
@Inject var manager: Manager @Inject var manager: Manager
@Published var theme: String = "" @Published var theme: String = ""
@Published var description: String = "" @Published var description: String = ""
@Published var isPublic = true @Published var isPrivate = false
@Published var endRegisterDate = Date() @Published var endRegisterDate = Date()
@Published var endBetDate = Date() @Published var endBetDate = Date()
@Published var betAdded = false @Published var betAdded = false
@ -38,7 +38,8 @@ class CreationBetViewModel: ObservableObject {
resetAllFieldErrors() resetAllFieldErrors()
if let user = AppStateContainer.shared.user { if let user = AppStateContainer.shared.user {
manager.addBet(bet: toBet(theme: theme, description: description, endRegister: endRegisterDate, endBet: endBetDate, isPublic: isPublic, status: .inProgress, creator: user.username, type: selectedOption)) { statusCode in manager.addBet(bet: toBet(theme: theme, description: description, endRegister: endRegisterDate, endBet: endBetDate, isPrivate: isPrivate, status: .inProgress, creator: user.username, type: selectedOption)) { statusCode in
print(statusCode)
switch statusCode { switch statusCode {
case 201: case 201:
self.betAdded = true self.betAdded = true
@ -113,16 +114,16 @@ class CreationBetViewModel: ObservableObject {
self.errorMessage = errorMessage self.errorMessage = errorMessage
} }
func toBet(theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, status: BetStatus, creator: String, type: Int) -> Bet { func toBet(theme: String, description: String, endRegister: Date, endBet: Date, isPrivate: Bool, status: BetStatus, creator: String, type: Int) -> Bet {
switch type { switch type {
case 0: case 0:
return BinaryBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPublic: isPublic, status: status, invited: [], author: creator, registered: []) return BinaryBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPrivate: isPrivate, status: status, invited: [], author: creator, registered: [])
case 1: case 1:
return MatchBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPublic: isPublic, status: status, invited: [], author: creator, registered: [], nameTeam1: "", nameTeam2: "") return MatchBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPrivate: isPrivate, status: status, invited: [], author: creator, registered: [], nameTeam1: "", nameTeam2: "")
case 2: case 2:
return CustomBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPublic: isPublic, status: status, invited: [], author: creator, registered: []) return CustomBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPrivate: isPrivate, status: status, invited: [], author: creator, registered: [])
default: default:
return BinaryBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPublic: isPublic, status: status, invited: [], author: creator, registered: []) return BinaryBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPrivate: isPrivate, status: status, invited: [], author: creator, registered: [])
} }
} }
} }

@ -257,15 +257,15 @@ struct CreationBetView: View {
.padding(.leading, 10) .padding(.leading, 10)
HStack(spacing: 5) { HStack(spacing: 5) {
ConfidentialityButton(image: "globe", text: String(localized: "bet_public"), selected: viewModel.isPublic) ConfidentialityButton(image: "globe", text: String(localized: "bet_public"), selected: !viewModel.isPrivate)
.onTapGesture { .onTapGesture {
viewModel.isPublic = true viewModel.isPrivate = false
} }
.padding(.trailing, 5) .padding(.trailing, 5)
ConfidentialityButton(image: "lock", text: String(localized: "bet_private"), selected: !viewModel.isPublic) ConfidentialityButton(image: "lock", text: String(localized: "bet_private"), selected: viewModel.isPrivate)
.onTapGesture { .onTapGesture {
viewModel.isPublic = false viewModel.isPrivate = true
} }
Spacer() Spacer()
} }
@ -276,7 +276,7 @@ struct CreationBetView: View {
VStack(spacing: 10) { VStack(spacing: 10) {
if !self.viewModel.isPublic { if self.viewModel.isPrivate {
DropDownFriends() DropDownFriends()
.padding(.bottom, 30) .padding(.bottom, 30)

@ -23,7 +23,7 @@ public class FactoryApiBet: FactoryBet {
"sentenceBet": bet.phrase, "sentenceBet": bet.phrase,
"endRegistration": formatZonedDateTime(dateTime: bet.endRegisterDate), "endRegistration": formatZonedDateTime(dateTime: bet.endRegisterDate),
"endBet": formatZonedDateTime(dateTime: bet.endBetDate), "endBet": formatZonedDateTime(dateTime: bet.endBetDate),
"isPrivate": String(bet.isPublic), "isPrivate": String(bet.isPrivate),
"response": ["Yes","No"], "response": ["Yes","No"],
"type": betTypeString(fromType: String(describing: type(of: bet))) "type": betTypeString(fromType: String(describing: type(of: bet)))
] ]

@ -26,7 +26,7 @@ public class Bet: ObservableObject, Identifiable, Codable {
public private(set) var endBetDate: Date public private(set) var endBetDate: Date
/// Indicates whether the bet is public or private. /// Indicates whether the bet is public or private.
public private(set) var isPublic: Bool public private(set) var isPrivate: Bool
/// The current status of the bet. /// The current status of the bet.
public private(set) var status: BetStatus public private(set) var status: BetStatus
@ -46,7 +46,7 @@ public class Bet: ObservableObject, Identifiable, Codable {
case phrase = "sentenceBet" case phrase = "sentenceBet"
case endRegisterDate = "endRegistration" case endRegisterDate = "endRegistration"
case endBetDate = "endBet" case endBetDate = "endBet"
case isPublic = "isPrivate" case isPrivate = "isPrivate"
case status case status
case author = "createdBy" case author = "createdBy"
} }
@ -63,7 +63,7 @@ public class Bet: ObservableObject, Identifiable, Codable {
self.endRegisterDate = formatter.date(from: endRegisterDateString)! self.endRegisterDate = formatter.date(from: endRegisterDateString)!
let endBetDateString = try container.decode(String.self, forKey: .endBetDate) let endBetDateString = try container.decode(String.self, forKey: .endBetDate)
self.endBetDate = formatter.date(from: endBetDateString)! self.endBetDate = formatter.date(from: endBetDateString)!
self.isPublic = try container.decode(Bool.self, forKey: .isPublic) self.isPrivate = try container.decode(Bool.self, forKey: .isPrivate)
self.status = try container.decode(BetStatus.self, forKey: .status) self.status = try container.decode(BetStatus.self, forKey: .status)
self.author = try container.decode(String.self, forKey: .author) self.author = try container.decode(String.self, forKey: .author)
} }
@ -81,13 +81,13 @@ public class Bet: ObservableObject, Identifiable, Codable {
/// - invited: List of users who are invited to participate in the bet. /// - invited: List of users who are invited to participate in the bet.
/// - author: The user who created the bet. /// - author: The user who created the bet.
/// - registered: List of users who have registered for the bet. /// - registered: List of users who have registered for the bet.
public init(id: String, theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPublic: Bool, status: BetStatus, invited: [User], author: String, registered: [User]) { public init(id: String, theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPrivate: Bool, status: BetStatus, invited: [User], author: String, registered: [User]) {
self.id = id self.id = id
self.theme = theme self.theme = theme
self.phrase = phrase self.phrase = phrase
self.endRegisterDate = endRegisterDate self.endRegisterDate = endRegisterDate
self.endBetDate = endBetDate self.endBetDate = endBetDate
self.isPublic = isPublic self.isPrivate = isPrivate
self.status = status self.status = status
self.invited = invited self.invited = invited
self.author = author self.author = author
@ -106,13 +106,13 @@ public class Bet: ObservableObject, Identifiable, Codable {
/// - invited: List of users who are invited to participate in the bet. /// - invited: List of users who are invited to participate in the bet.
/// - author: The user who created the bet. /// - author: The user who created the bet.
/// - registered: List of users who have registered for the bet. /// - registered: List of users who have registered for the bet.
public init(theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPublic: Bool, status: BetStatus, invited: [User], author: String, registered: [User]) { public init(theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPrivate: Bool, status: BetStatus, invited: [User], author: String, registered: [User]) {
self.id = UUID().uuidString self.id = UUID().uuidString
self.theme = theme self.theme = theme
self.phrase = phrase self.phrase = phrase
self.endRegisterDate = endRegisterDate self.endRegisterDate = endRegisterDate
self.endBetDate = endBetDate self.endBetDate = endBetDate
self.isPublic = isPublic self.isPrivate = isPrivate
self.status = status self.status = status
self.invited = invited self.invited = invited
self.author = author self.author = author

@ -36,10 +36,10 @@ public class MatchBet: Bet {
/// - registered: List of users who have registered for the match bet. /// - registered: List of users who have registered for the match bet.
/// - nameTeam1: The name of the first team involved in the match. /// - nameTeam1: The name of the first team involved in the match.
/// - nameTeam2: The name of the second team involved in the match. /// - nameTeam2: The name of the second team involved in the match.
public init(id: String, theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPublic: Bool, status: BetStatus, invited: [User], author: String, registered: [User], nameTeam1: String, nameTeam2: String) { public init(id: String, theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPrivate: Bool, status: BetStatus, invited: [User], author: String, registered: [User], nameTeam1: String, nameTeam2: String) {
self.nameTeam1 = nameTeam1 self.nameTeam1 = nameTeam1
self.nameTeam2 = nameTeam2 self.nameTeam2 = nameTeam2
super.init(id: id, theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, isPublic: isPublic, status: status, invited: invited, author: author, registered: registered) super.init(id: id, theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, isPrivate: isPrivate, status: status, invited: invited, author: author, registered: registered)
} }
/// Custom Constructor without Id /// Custom Constructor without Id
@ -56,10 +56,10 @@ public class MatchBet: Bet {
/// - registered: List of users who have registered for the match bet. /// - registered: List of users who have registered for the match bet.
/// - nameTeam1: The name of the first team involved in the match. /// - nameTeam1: The name of the first team involved in the match.
/// - nameTeam2: The name of the second team involved in the match. /// - nameTeam2: The name of the second team involved in the match.
public init(theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPublic: Bool, status: BetStatus, invited: [User], author: String, registered: [User], nameTeam1: String, nameTeam2: String) { public init(theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPrivate: Bool, status: BetStatus, invited: [User], author: String, registered: [User], nameTeam1: String, nameTeam2: String) {
self.nameTeam1 = nameTeam1 self.nameTeam1 = nameTeam1
self.nameTeam2 = nameTeam2 self.nameTeam2 = nameTeam2
super.init(theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, isPublic: isPublic, status: status, invited: invited, author: author, registered: registered) super.init(theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, isPrivate: isPrivate, status: status, invited: invited, author: author, registered: registered)
} }
public required init(from decoder: Decoder) throws { public required init(from decoder: Decoder) throws {

@ -35,7 +35,7 @@ struct Stub {
phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.", phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.",
endRegisterDate: Date().addingTimeInterval(-86400), endRegisterDate: Date().addingTimeInterval(-86400),
endBetDate: Date().addingTimeInterval(172800), endBetDate: Date().addingTimeInterval(172800),
isPublic: true, isPrivate: false,
status: .inProgress, status: .inProgress,
invited: [], invited: [],
author: "Lucas", author: "Lucas",
@ -48,7 +48,7 @@ struct Stub {
phrase: "Le plat préféré du jury sera une recette végétarienne.", phrase: "Le plat préféré du jury sera une recette végétarienne.",
endRegisterDate: Date().addingTimeInterval(172800), endRegisterDate: Date().addingTimeInterval(172800),
endBetDate: Date().addingTimeInterval(259200), endBetDate: Date().addingTimeInterval(259200),
isPublic: false, isPrivate: false,
status: .inProgress, status: .inProgress,
invited: [user3], invited: [user3],
author: "Lucas", author: "Lucas",
@ -61,7 +61,7 @@ struct Stub {
phrase: "Le nombre total de précommandes dépassera-t-il 1 million dans la première semaine ?", phrase: "Le nombre total de précommandes dépassera-t-il 1 million dans la première semaine ?",
endRegisterDate: Date().addingTimeInterval(259200), endRegisterDate: Date().addingTimeInterval(259200),
endBetDate: Date().addingTimeInterval(345600), endBetDate: Date().addingTimeInterval(345600),
isPublic: true, isPrivate: true,
status: .finished, status: .finished,
invited: [], invited: [],
author: "Lucas", author: "Lucas",
@ -74,7 +74,7 @@ struct Stub {
phrase: "Le film favori des critiques remportera-t-il le prix du meilleur film ?", phrase: "Le film favori des critiques remportera-t-il le prix du meilleur film ?",
endRegisterDate: Date().addingTimeInterval(345600), endRegisterDate: Date().addingTimeInterval(345600),
endBetDate: Date().addingTimeInterval(432000), endBetDate: Date().addingTimeInterval(432000),
isPublic: false, isPrivate: false,
status: .finished, status: .finished,
invited: [user1], invited: [user1],
author: "Lucase", author: "Lucase",

Loading…
Cancel
Save