From 6fb1146ab68e907b91c0b71d75c7b5f20632694f Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Tue, 23 Jan 2024 21:23:14 +0100 Subject: [PATCH] Update Factory and add a new Method toBetDetail, also improve the Model :art: --- .../Grey100Color.colorset/Contents.json | 6 +-- .../AllInApp/AllIn/Components/BetCard.swift | 2 +- .../AllInApp/AllIn/Services/AuthService.swift | 2 +- .../AllInApp/AllIn/Views/DetailsView.swift | 2 +- Sources/Api/Sources/Api/BetApiManager.swift | 34 ++++++++++-- .../Sources/Api/Factory/FactoryApiBet.swift | 52 +++++++++++++------ Sources/Api/Sources/Api/UserApiManager.swift | 7 ++- ...tAnswerDetail.swift => AnswerDetail.swift} | 4 +- Sources/Model/Sources/Model/Bet.swift | 16 +++--- Sources/Model/Sources/Model/BetDetail.swift | 8 +-- Sources/Model/Sources/Model/BinaryBet.swift | 32 ------------ .../Sources/Model/Factory/FactoryBet.swift | 5 +- Sources/Model/Sources/Model/File.swift | 12 +++++ Sources/Model/Sources/Model/Manager.swift | 2 +- Sources/Model/Sources/Model/MatchBet.swift | 8 +-- .../Model/Sources/Model/Participation.swift | 4 +- Sources/Model/Sources/Model/User.swift | 8 +-- Sources/StubLib/Sources/StubLib/Stub.swift | 12 ++--- 18 files changed, 117 insertions(+), 99 deletions(-) rename Sources/Model/Sources/Model/{BetAnswerDetail.swift => AnswerDetail.swift} (94%) create mode 100644 Sources/Model/Sources/Model/File.swift diff --git a/Sources/AllInApp/AllIn/Assets.xcassets/Grey100Color.colorset/Contents.json b/Sources/AllInApp/AllIn/Assets.xcassets/Grey100Color.colorset/Contents.json index 806eef5..c165084 100644 --- a/Sources/AllInApp/AllIn/Assets.xcassets/Grey100Color.colorset/Contents.json +++ b/Sources/AllInApp/AllIn/Assets.xcassets/Grey100Color.colorset/Contents.json @@ -23,9 +23,9 @@ "color-space" : "display-p3", "components" : { "alpha" : "1.000", - "blue" : "0xCF", - "green" : "0xCF", - "red" : "0xCF" + "blue" : "0x45", + "green" : "0x45", + "red" : "0x45" } }, "idiom" : "universal" diff --git a/Sources/AllInApp/AllIn/Components/BetCard.swift b/Sources/AllInApp/AllIn/Components/BetCard.swift index b8ca216..68058b2 100644 --- a/Sources/AllInApp/AllIn/Components/BetCard.swift +++ b/Sources/AllInApp/AllIn/Components/BetCard.swift @@ -74,8 +74,8 @@ struct BetCard_Previews: PreviewProvider { phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.", endRegisterDate: Date().addingTimeInterval(86400), endBetDate: Date().addingTimeInterval(172800), - totalStakes: 100, isPublic: true, + status: .FINISHED, invited: [], author: User(username: "Imri", email: "emre.kartal@etu.uca.fr", nbCoins: 75, friends: []), registered: [])) diff --git a/Sources/AllInApp/AllIn/Services/AuthService.swift b/Sources/AllInApp/AllIn/Services/AuthService.swift index df4b7e6..3d2ab62 100644 --- a/Sources/AllInApp/AllIn/Services/AuthService.swift +++ b/Sources/AllInApp/AllIn/Services/AuthService.swift @@ -150,7 +150,7 @@ class AuthService: IAuthService { } private func initManagerVM(token: String) { - DependencyInjection.shared.addSingleton(Manager.self, Manager(withBetDataManager: BetStubManager(), withUserDataManager: UserApiManager(withUserToken: token))) + DependencyInjection.shared.addSingleton(Manager.self, Manager(withBetDataManager: BetApiManager(withUserToken: token), withUserDataManager: UserApiManager(withUserToken: token))) } } diff --git a/Sources/AllInApp/AllIn/Views/DetailsView.swift b/Sources/AllInApp/AllIn/Views/DetailsView.swift index 8266de9..2afda06 100644 --- a/Sources/AllInApp/AllIn/Views/DetailsView.swift +++ b/Sources/AllInApp/AllIn/Views/DetailsView.swift @@ -118,7 +118,7 @@ struct DetailsView: View { ResultBanner() } VStack(alignment: .leading, spacing: 5) { - BetLineLoading(participations: viewModel.betDetail!.participations).padding(.vertical,15) + BetLineLoading(participations: viewModel.betDetail?.participations ?? []).padding(.vertical,15) Text("Liste des participants") .font(.system(size: 18)) .foregroundStyle(AllInColors.grey100Color) diff --git a/Sources/Api/Sources/Api/BetApiManager.swift b/Sources/Api/Sources/Api/BetApiManager.swift index 4141547..380d832 100644 --- a/Sources/Api/Sources/Api/BetApiManager.swift +++ b/Sources/Api/Sources/Api/BetApiManager.swift @@ -10,7 +10,11 @@ import Model public struct BetApiManager: BetDataManager { - public init() { } + public let token: String + + public init(withUserToken token: String) { + self.token = token + } public func getBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) { let url = URL(string: allInApi + "bets/gets")! @@ -27,9 +31,8 @@ public struct BetApiManager: BetDataManager { do { if let httpResponse = response as? HTTPURLResponse, let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] { for json in jsonArray { - if let bet = FactoryApiBet().toModel(from: json) { + if let bet = FactoryApiBet().toBet(from: json) { bets.append(bet) - print(bet.theme) } } print(httpResponse.statusCode) @@ -47,7 +50,30 @@ public struct BetApiManager: BetDataManager { } public func getBet(withId id: String, completion: @escaping (BetDetail) -> Void) { - + let url = URL(string: allInApi + "betdetail/get/" + id)! + + var request = URLRequest(url: url) + request.httpMethod = "GET" + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") + + URLSession.shared.dataTask(with: request) { data, response, error in + if let data = data { + print ("ALLIN : get bet with id :" + id) + do { + if let httpResponse = response as? HTTPURLResponse, let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] { + + if let betDetail = FactoryApiBet().toBetDetail(from: json) { + completion(betDetail) + } + print(httpResponse.statusCode) + } + } catch { + print("Error parsing JSON: \(error)") + } + } + }.resume() + } } diff --git a/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift b/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift index 1adb92c..0a4931c 100644 --- a/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift +++ b/Sources/Api/Sources/Api/Factory/FactoryApiBet.swift @@ -10,14 +10,19 @@ import Model public class FactoryApiBet: FactoryBet { + func formatZonedDateTime(dateTime: Date) -> String { + let formatter = DateFormatter() + formatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z" + formatter.timeZone = TimeZone.current + return formatter.string(from: dateTime) + } + public func toResponse(bet: Bet) -> [String: Any] { - let json: [String: Any] = [ - "id": "1", "theme": bet.theme, "sentenceBet": bet.phrase, - "endRegistration": bet.endRegisterDate.timeIntervalSince1970, - "endBet": bet.endBetDate.timeIntervalSince1970, + "endRegistration": formatZonedDateTime(dateTime: bet.endRegisterDate), + "endBet": formatZonedDateTime(dateTime: bet.endBetDate), "isPrivate": String(bet.isPublic), "response": [], ] @@ -25,7 +30,15 @@ public class FactoryApiBet: FactoryBet { return json } - public func toModel(from json: [String: Any]) -> Bet? { + public func fromJsonDateString(_ dateString: String) -> Date? { + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z" + let date = formatter.date(from: dateString) + return date + } + + public func toBet(from json: [String: Any]) -> Bet? { guard let id = json["id"] as? String, let theme = json["theme"] as? String, let phrase = json["sentenceBet"] as? String, @@ -36,28 +49,33 @@ public class FactoryApiBet: FactoryBet { return nil } - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" - - guard let endRegisterDate = dateFormatter.date(from: endRegisterDateString), - let endBetDate = dateFormatter.date(from: endBetDateString) else { + guard let endRegisterDate = fromJsonDateString(endRegisterDateString), + let endBetDate = fromJsonDateString(endBetDateString) else { return nil } - - return toModel(id: id, theme: theme, description: phrase, endRegister: endRegisterDate, endBet: endBetDate, isPublic: isPublic, creator: User(username: createdBy, email: createdBy, nbCoins: 0, friends: []), type: 0) + + return toBet(id: id, theme: theme, description: phrase, endRegister: endRegisterDate, endBet: endBetDate, isPublic: isPublic, status: .FINISHED, creator: User(username: createdBy, email: createdBy, nbCoins: 0, friends: []), type: 0) } - public func toModel(id: String, theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User, type: Int) -> Bet { + public func toBet(id: String, theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, status: BetStatus, creator: User, type: Int) -> Bet { switch type { case 0: - return BinaryBet(id: id, theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, totalStakes: 0, isPublic: isPublic, invited: [], author: creator, registered: []) + return BinaryBet(id: id, theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPublic: isPublic, status: status, invited: [], author: creator, registered: []) case 1: - return MatchBet(id: id, theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, totalStakes: 0, isPublic: isPublic, invited: [], author: creator, registered: [], nameTeam1: "", nameTeam2: "") + return MatchBet(id: id, theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPublic: isPublic, status: status, invited: [], author: creator, registered: [], nameTeam1: "", nameTeam2: "") case 2: - return CustomBet(id: id, theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, totalStakes: 0, isPublic: isPublic, invited: [], author: creator, registered: []) + return CustomBet(id: id, theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPublic: isPublic, status: status, invited: [], author: creator, registered: []) default: - return BinaryBet(id: id, theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, totalStakes: 0, isPublic: isPublic, invited: [], author: creator, registered: []) + return BinaryBet(id: id, theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPublic: isPublic, status: status, invited: [], author: creator, registered: []) + } + } + + public func toBetDetail(from json: [String: Any]) -> BetDetail? { + guard let betJson = json["bet"] as? [String: Any], + let bet = self.toBet(from: betJson) else { + return nil } + return BetDetail(bet: bet, answers: [], participations: []) } } diff --git a/Sources/Api/Sources/Api/UserApiManager.swift b/Sources/Api/Sources/Api/UserApiManager.swift index 89873c8..eecc76b 100644 --- a/Sources/Api/Sources/Api/UserApiManager.swift +++ b/Sources/Api/Sources/Api/UserApiManager.swift @@ -24,15 +24,14 @@ public struct UserApiManager: UserDataManager { public func addBet(bet: Bet) { - print(token) let url = URL(string: allInApi + "bets/add")! var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-Type") + request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") + + let json = FactoryApiBet().toResponse(bet: bet) - var json = FactoryApiBet().toResponse(bet: bet) - json["createdBy"] = token - if let jsonData = try? JSONSerialization.data(withJSONObject: json, options: []){ URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in print ("ALLIN : Add BET") diff --git a/Sources/Model/Sources/Model/BetAnswerDetail.swift b/Sources/Model/Sources/Model/AnswerDetail.swift similarity index 94% rename from Sources/Model/Sources/Model/BetAnswerDetail.swift rename to Sources/Model/Sources/Model/AnswerDetail.swift index 77ab2d8..6474788 100644 --- a/Sources/Model/Sources/Model/BetAnswerDetail.swift +++ b/Sources/Model/Sources/Model/AnswerDetail.swift @@ -1,5 +1,5 @@ // -// BetAnswerDetail.swift +// AnswerDetail.swift // // // Created by Emre on 19/01/2024. @@ -8,7 +8,7 @@ import Foundation /// A class representing detailed information about a specific answer option for a bet. -public class BetAnswerDetail: ObservableObject { +public class AnswerDetail: ObservableObject { /// The response or outcome associated with this answer. public private(set) var response: String diff --git a/Sources/Model/Sources/Model/Bet.swift b/Sources/Model/Sources/Model/Bet.swift index 4ad6268..f733cd4 100644 --- a/Sources/Model/Sources/Model/Bet.swift +++ b/Sources/Model/Sources/Model/Bet.swift @@ -25,12 +25,11 @@ public class Bet: ObservableObject, Identifiable { /// The deadline for the actual betting to take place. public private(set) var endBetDate: Date - /// The total stakes or amount involved in the bet. - public private(set) var totalStakes: Int - /// Indicates whether the bet is public or private. public private(set) var isPublic: Bool + public private(set) var status: BetStatus + /// List of users who are invited to participate in the bet. public private(set) var invited: [User] @@ -39,6 +38,7 @@ public class Bet: ObservableObject, Identifiable { /// List of users who have registered for the bet. public private(set) var registered: [User] + /// Custom Constructor /// @@ -48,19 +48,18 @@ public class Bet: ObservableObject, Identifiable { /// - phrase: The specific phrase or question related to the bet. /// - endRegisterDate: The deadline for users to register for the bet. /// - endBetDate: The deadline for the actual betting to take place. - /// - totalStakes: The total stakes or amount involved in the bet. /// - isPublic: Indicates whether the bet is public or private. /// - invited: List of users who are invited to participate in the bet. /// - author: The user who created the bet. /// - registered: List of users who have registered for the bet. - public init(id: String, theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, totalStakes: Int, isPublic: Bool, invited: [User], author: User, registered: [User]) { + public init(id: String, theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPublic: Bool, status: BetStatus, invited: [User], author: User, registered: [User]) { self.id = id self.theme = theme self.phrase = phrase self.endRegisterDate = endRegisterDate self.endBetDate = endBetDate - self.totalStakes = totalStakes self.isPublic = isPublic + self.status = status self.invited = invited self.author = author self.registered = registered @@ -73,19 +72,18 @@ public class Bet: ObservableObject, Identifiable { /// - phrase: The specific phrase or question related to the bet. /// - endRegisterDate: The deadline for users to register for the bet. /// - endBetDate: The deadline for the actual betting to take place. - /// - totalStakes: The total stakes or amount involved in the bet. /// - isPublic: Indicates whether the bet is public or private. /// - invited: List of users who are invited to participate in the bet. /// - author: The user who created the bet. /// - registered: List of users who have registered for the bet. - public init(theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, totalStakes: Int, isPublic: Bool, invited: [User], author: User, registered: [User]) { + public init(theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPublic: Bool, status: BetStatus, invited: [User], author: User, registered: [User]) { self.id = UUID().uuidString self.theme = theme self.phrase = phrase self.endRegisterDate = endRegisterDate self.endBetDate = endBetDate - self.totalStakes = totalStakes self.isPublic = isPublic + self.status = status self.invited = invited self.author = author self.registered = registered diff --git a/Sources/Model/Sources/Model/BetDetail.swift b/Sources/Model/Sources/Model/BetDetail.swift index d492e8f..2f647f5 100644 --- a/Sources/Model/Sources/Model/BetDetail.swift +++ b/Sources/Model/Sources/Model/BetDetail.swift @@ -14,14 +14,11 @@ public class BetDetail: ObservableObject { public private(set) var bet: Bet /// Details about the answers available for the bet. - public private(set) var answers: [BetAnswerDetail] + public private(set) var answers: [AnswerDetail] /// List of user participations in the bet. public private(set) var participations: [Participation] - /// The user's own participation in the bet. - public private(set) var userParticipation: Participation - public private(set) var finalAnswer: String? /// Custom Constructor @@ -31,11 +28,10 @@ public class BetDetail: ObservableObject { /// - answers: Details about the answers available for the bet. /// - participations: List of user participations in the bet. /// - userParticipation: The user's own participation in the bet. - public init(bet: Bet, answers: [BetAnswerDetail], participations: [Participation], userParticipation: Participation, finalAnswer: String? = nil) { + public init(bet: Bet, answers: [AnswerDetail], participations: [Participation], finalAnswer: String? = nil) { self.bet = bet self.answers = answers self.participations = participations - self.userParticipation = userParticipation self.finalAnswer = finalAnswer } diff --git a/Sources/Model/Sources/Model/BinaryBet.swift b/Sources/Model/Sources/Model/BinaryBet.swift index 051ccf6..fafd7be 100644 --- a/Sources/Model/Sources/Model/BinaryBet.swift +++ b/Sources/Model/Sources/Model/BinaryBet.swift @@ -10,36 +10,4 @@ import Foundation /// A subclass of Bet that represents a binary bet, where participants make a choice between two possible outcomes. public class BinaryBet: Bet { - // Custom Constructor - /// - /// - Parameters: - /// - id: The id for the bet. - /// - theme: The theme or topic of the binary bet. - /// - phrase: The specific phrase or question related to the binary bet. - /// - endRegisterDate: The deadline for users to register for the binary bet. - /// - endBetDate: The deadline for the actual betting to take place for the binary bet. - /// - totalStakes: The total stakes or amount involved in the binary bet. - /// - isPublic: Indicates whether the binary bet is public or private. - /// - invited: List of users who are invited to participate in the binary bet. - /// - author: The user who created the binary bet. - /// - registered: List of users who have registered for the binary bet. - public override init(id: String, theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, totalStakes: Int, isPublic: Bool, invited: [User], author: User, registered: [User]) { - super.init(id: id, theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, totalStakes: totalStakes, isPublic: isPublic, invited: invited, author: author, registered: registered) - } - - // Custom Constructor without Id - /// - /// - Parameters: - /// - theme: The theme or topic of the binary bet. - /// - phrase: The specific phrase or question related to the binary bet. - /// - endRegisterDate: The deadline for users to register for the binary bet. - /// - endBetDate: The deadline for the actual betting to take place for the binary bet. - /// - totalStakes: The total stakes or amount involved in the binary bet. - /// - isPublic: Indicates whether the binary bet is public or private. - /// - invited: List of users who are invited to participate in the binary bet. - /// - author: The user who created the binary bet. - /// - registered: List of users who have registered for the binary bet. - public override init(theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, totalStakes: Int, isPublic: Bool, invited: [User], author: User, registered: [User]) { - super.init(theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, totalStakes: totalStakes, isPublic: isPublic, invited: invited, author: author, registered: registered) - } } diff --git a/Sources/Model/Sources/Model/Factory/FactoryBet.swift b/Sources/Model/Sources/Model/Factory/FactoryBet.swift index 40a7f0a..be18215 100644 --- a/Sources/Model/Sources/Model/Factory/FactoryBet.swift +++ b/Sources/Model/Sources/Model/Factory/FactoryBet.swift @@ -9,6 +9,7 @@ import Foundation public protocol FactoryBet { func toResponse(bet: Bet) -> [String: Any] - func toModel(from json: [String: Any]) -> Bet? - func toModel(id: String, theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User, type: Int) -> Bet + func toBet(from json: [String: Any]) -> Bet? + func toBetDetail(from json: [String: Any]) -> BetDetail? + func toBet(id: String, theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, status: BetStatus, creator: User, type: Int) -> Bet } diff --git a/Sources/Model/Sources/Model/File.swift b/Sources/Model/Sources/Model/File.swift new file mode 100644 index 0000000..a44b593 --- /dev/null +++ b/Sources/Model/Sources/Model/File.swift @@ -0,0 +1,12 @@ +// +// File.swift +// +// +// Created by étudiant on 23/01/2024. +// + +import Foundation + +public enum BetStatus { + case WAITING, IN_PROGRESS, FINISHED +} diff --git a/Sources/Model/Sources/Model/Manager.swift b/Sources/Model/Sources/Model/Manager.swift index 3ff086a..06392df 100644 --- a/Sources/Model/Sources/Model/Manager.swift +++ b/Sources/Model/Sources/Model/Manager.swift @@ -17,7 +17,7 @@ public struct Manager { } public func addBet(theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User) { - userDataManager.addBet(bet: BinaryBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, totalStakes: 0, isPublic: isPublic, invited: [], author: creator, registered: [])) + userDataManager.addBet(bet: BinaryBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, isPublic: isPublic, status: .IN_PROGRESS, invited: [], author: creator, registered: [])) } public func getBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) { diff --git a/Sources/Model/Sources/Model/MatchBet.swift b/Sources/Model/Sources/Model/MatchBet.swift index e197042..a6100c1 100644 --- a/Sources/Model/Sources/Model/MatchBet.swift +++ b/Sources/Model/Sources/Model/MatchBet.swift @@ -30,10 +30,10 @@ public class MatchBet: Bet { /// - registered: List of users who have registered for the match bet. /// - nameTeam1: The name of the first 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, totalStakes: Int, isPublic: Bool, invited: [User], author: User, registered: [User], nameTeam1: String, nameTeam2: String) { + public init(id: String, theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPublic: Bool, status: BetStatus, invited: [User], author: User, registered: [User], nameTeam1: String, nameTeam2: String) { self.nameTeam1 = nameTeam1 self.nameTeam2 = nameTeam2 - super.init(id: id, theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, totalStakes: totalStakes, isPublic: isPublic, invited: invited, author: author, registered: registered) + super.init(id: id, theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, isPublic: isPublic, status: status, invited: invited, author: author, registered: registered) } /// Custom Constructor without Id @@ -50,9 +50,9 @@ public class MatchBet: Bet { /// - registered: List of users who have registered for the match bet. /// - nameTeam1: The name of the first 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, totalStakes: Int, isPublic: Bool, invited: [User], author: User, registered: [User], nameTeam1: String, nameTeam2: String) { + public init(theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, isPublic: Bool, status: BetStatus, invited: [User], author: User, registered: [User], nameTeam1: String, nameTeam2: String) { self.nameTeam1 = nameTeam1 self.nameTeam2 = nameTeam2 - super.init(theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, totalStakes: totalStakes, isPublic: isPublic, invited: invited, author: author, registered: registered) + super.init(theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, isPublic: isPublic, status: status, invited: invited, author: author, registered: registered) } } diff --git a/Sources/Model/Sources/Model/Participation.swift b/Sources/Model/Sources/Model/Participation.swift index 9b5d088..f8e7058 100644 --- a/Sources/Model/Sources/Model/Participation.swift +++ b/Sources/Model/Sources/Model/Participation.swift @@ -8,7 +8,7 @@ import Foundation /// A class representing a user's participation in a bet. -public class Participation: ObservableObject, Identifiable{ +public class Participation: ObservableObject, Identifiable { public let id: UUID /// The amount of stake in the bet. @@ -24,7 +24,7 @@ public class Participation: ObservableObject, Identifiable{ public private(set) var user: User /// The unique identifier of the bet. - let betId: String + public private(set) var betId: String /// Custom Constructor /// diff --git a/Sources/Model/Sources/Model/User.swift b/Sources/Model/Sources/Model/User.swift index 784902f..385d6ee 100644 --- a/Sources/Model/Sources/Model/User.swift +++ b/Sources/Model/Sources/Model/User.swift @@ -8,10 +8,10 @@ import Foundation public struct User { - public var username: String - public var email: String - public var nbCoins: Int - public var friends: [User] + public private(set) var username: String + public private(set) var email: String + public private(set) var nbCoins: Int + public private(set) var friends: [User] public init(username: String, email: String, nbCoins: Int, friends: [User]) { self.username = username diff --git a/Sources/StubLib/Sources/StubLib/Stub.swift b/Sources/StubLib/Sources/StubLib/Stub.swift index 2692c33..09618bf 100644 --- a/Sources/StubLib/Sources/StubLib/Stub.swift +++ b/Sources/StubLib/Sources/StubLib/Stub.swift @@ -37,8 +37,8 @@ struct Stub { phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.", endRegisterDate: Date().addingTimeInterval(-86400), endBetDate: Date().addingTimeInterval(172800), - totalStakes: 100, isPublic: true, + status: .IN_PROGRESS, invited: [], author: user1, registered: [user2] @@ -50,8 +50,8 @@ struct Stub { phrase: "Le plat préféré du jury sera une recette végétarienne.", endRegisterDate: Date().addingTimeInterval(172800), endBetDate: Date().addingTimeInterval(259200), - totalStakes: 150, isPublic: false, + status: .IN_PROGRESS, invited: [user3], author: user1, registered: [user2] @@ -63,8 +63,8 @@ struct Stub { phrase: "Le nombre total de précommandes dépassera-t-il 1 million dans la première semaine ?", endRegisterDate: Date().addingTimeInterval(259200), endBetDate: Date().addingTimeInterval(345600), - totalStakes: 75, isPublic: true, + status: .FINISHED, invited: [], author: user1, registered: [user2, user1, user3] @@ -76,8 +76,8 @@ struct Stub { phrase: "Le film favori des critiques remportera-t-il le prix du meilleur film ?", endRegisterDate: Date().addingTimeInterval(345600), endBetDate: Date().addingTimeInterval(432000), - totalStakes: 120, isPublic: false, + status: .FINISHED, invited: [user1], author: user2, registered: [user3] @@ -85,7 +85,7 @@ struct Stub { self.bets.append(bet4) for bet in bets { - let betDetail = BetDetail(bet: bet, answers: [], participations: [], userParticipation: Participation(stake: 0, date: Date(), response: "", user: user1, betId: "")) + let betDetail = BetDetail(bet: bet, answers: [], participations: []) self.betsDetail.append(betDetail) } @@ -97,7 +97,7 @@ struct Stub { } public mutating func add(bet: Bet) { - let newBetDetail = BetDetail(bet: bet, answers: [], participations: [], userParticipation: Participation(stake: 0, date: Date(), response: "", user: users[1], betId: ""), finalAnswer: "test") + let newBetDetail = BetDetail(bet: bet, answers: [], participations: [], finalAnswer: "test") self.betsDetail.append(newBetDetail) } }