Update Factory and add a new Method toBetDetail, also improve the Model 🎨

pull/16/head
Emre KARTAL 1 year ago
parent d24a1cc244
commit 6fb1146ab6

@ -23,9 +23,9 @@
"color-space" : "display-p3", "color-space" : "display-p3",
"components" : { "components" : {
"alpha" : "1.000", "alpha" : "1.000",
"blue" : "0xCF", "blue" : "0x45",
"green" : "0xCF", "green" : "0x45",
"red" : "0xCF" "red" : "0x45"
} }
}, },
"idiom" : "universal" "idiom" : "universal"

@ -74,8 +74,8 @@ 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),
totalStakes: 100,
isPublic: true, isPublic: true,
status: .FINISHED,
invited: [], invited: [],
author: User(username: "Imri", email: "emre.kartal@etu.uca.fr", nbCoins: 75, friends: []), author: User(username: "Imri", email: "emre.kartal@etu.uca.fr", nbCoins: 75, friends: []),
registered: [])) registered: []))

@ -150,7 +150,7 @@ class AuthService: IAuthService {
} }
private func initManagerVM(token: String) { 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)))
} }
} }

@ -118,7 +118,7 @@ struct DetailsView: View {
ResultBanner() ResultBanner()
} }
VStack(alignment: .leading, spacing: 5) { 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") Text("Liste des participants")
.font(.system(size: 18)) .font(.system(size: 18))
.foregroundStyle(AllInColors.grey100Color) .foregroundStyle(AllInColors.grey100Color)

@ -10,7 +10,11 @@ import Model
public struct BetApiManager: BetDataManager { 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) { public func getBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) {
let url = URL(string: allInApi + "bets/gets")! let url = URL(string: allInApi + "bets/gets")!
@ -27,9 +31,8 @@ public struct BetApiManager: BetDataManager {
do { do {
if let httpResponse = response as? HTTPURLResponse, let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] { if let httpResponse = response as? HTTPURLResponse, let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] {
for json in jsonArray { for json in jsonArray {
if let bet = FactoryApiBet().toModel(from: json) { if let bet = FactoryApiBet().toBet(from: json) {
bets.append(bet) bets.append(bet)
print(bet.theme)
} }
} }
print(httpResponse.statusCode) print(httpResponse.statusCode)
@ -47,6 +50,29 @@ public struct BetApiManager: BetDataManager {
} }
public func getBet(withId id: String, completion: @escaping (BetDetail) -> Void) { 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()
} }

@ -10,14 +10,19 @@ import Model
public class FactoryApiBet: FactoryBet { public class FactoryApiBet: FactoryBet {
public func toResponse(bet: Bet) -> [String: Any] { 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] = [ let json: [String: Any] = [
"id": "1",
"theme": bet.theme, "theme": bet.theme,
"sentenceBet": bet.phrase, "sentenceBet": bet.phrase,
"endRegistration": bet.endRegisterDate.timeIntervalSince1970, "endRegistration": formatZonedDateTime(dateTime: bet.endRegisterDate),
"endBet": bet.endBetDate.timeIntervalSince1970, "endBet": formatZonedDateTime(dateTime: bet.endBetDate),
"isPrivate": String(bet.isPublic), "isPrivate": String(bet.isPublic),
"response": [], "response": [],
] ]
@ -25,7 +30,15 @@ public class FactoryApiBet: FactoryBet {
return json 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, guard let id = json["id"] as? String,
let theme = json["theme"] as? String, let theme = json["theme"] as? String,
let phrase = json["sentenceBet"] as? String, let phrase = json["sentenceBet"] as? String,
@ -36,28 +49,33 @@ public class FactoryApiBet: FactoryBet {
return nil return nil
} }
let dateFormatter = DateFormatter() guard let endRegisterDate = fromJsonDateString(endRegisterDateString),
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" let endBetDate = fromJsonDateString(endBetDateString) else {
guard let endRegisterDate = dateFormatter.date(from: endRegisterDateString),
let endBetDate = dateFormatter.date(from: endBetDateString) else {
return nil 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 { switch type {
case 0: 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: 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: 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: 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: [])
} }
} }

@ -24,14 +24,13 @@ public struct UserApiManager: UserDataManager {
public func addBet(bet: Bet) { public func addBet(bet: Bet) {
print(token)
let url = URL(string: allInApi + "bets/add")! let url = URL(string: allInApi + "bets/add")!
var request = URLRequest(url: url) var request = URLRequest(url: url)
request.httpMethod = "POST" request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type") request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
var json = FactoryApiBet().toResponse(bet: bet) let json = FactoryApiBet().toResponse(bet: bet)
json["createdBy"] = token
if let jsonData = try? JSONSerialization.data(withJSONObject: json, options: []){ if let jsonData = try? JSONSerialization.data(withJSONObject: json, options: []){
URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in

@ -1,5 +1,5 @@
// //
// BetAnswerDetail.swift // AnswerDetail.swift
// //
// //
// Created by Emre on 19/01/2024. // Created by Emre on 19/01/2024.
@ -8,7 +8,7 @@
import Foundation import Foundation
/// A class representing detailed information about a specific answer option for a bet. /// 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. /// The response or outcome associated with this answer.
public private(set) var response: String public private(set) var response: String

@ -25,12 +25,11 @@ public class Bet: ObservableObject, Identifiable {
/// The deadline for the actual betting to take place. /// The deadline for the actual betting to take place.
public private(set) var endBetDate: Date 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. /// Indicates whether the bet is public or private.
public private(set) var isPublic: Bool public private(set) var isPublic: Bool
public private(set) var status: BetStatus
/// List of users who are invited to participate in the bet. /// List of users who are invited to participate in the bet.
public private(set) var invited: [User] public private(set) var invited: [User]
@ -40,6 +39,7 @@ public class Bet: ObservableObject, Identifiable {
/// List of users who have registered for the bet. /// List of users who have registered for the bet.
public private(set) var registered: [User] public private(set) var registered: [User]
/// Custom Constructor /// Custom Constructor
/// ///
/// - Parameters: /// - Parameters:
@ -48,19 +48,18 @@ public class Bet: ObservableObject, Identifiable {
/// - phrase: The specific phrase or question related to the bet. /// - phrase: The specific phrase or question related to the bet.
/// - endRegisterDate: The deadline for users to register for the bet. /// - endRegisterDate: The deadline for users to register for the bet.
/// - endBetDate: The deadline for the actual betting to take place. /// - 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. /// - isPublic: Indicates whether the bet is public or private.
/// - 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, 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.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.totalStakes = totalStakes
self.isPublic = isPublic self.isPublic = isPublic
self.status = status
self.invited = invited self.invited = invited
self.author = author self.author = author
self.registered = registered self.registered = registered
@ -73,19 +72,18 @@ public class Bet: ObservableObject, Identifiable {
/// - phrase: The specific phrase or question related to the bet. /// - phrase: The specific phrase or question related to the bet.
/// - endRegisterDate: The deadline for users to register for the bet. /// - endRegisterDate: The deadline for users to register for the bet.
/// - endBetDate: The deadline for the actual betting to take place. /// - 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. /// - isPublic: Indicates whether the bet is public or private.
/// - 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, 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.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.totalStakes = totalStakes
self.isPublic = isPublic self.isPublic = isPublic
self.status = status
self.invited = invited self.invited = invited
self.author = author self.author = author
self.registered = registered self.registered = registered

@ -14,14 +14,11 @@ public class BetDetail: ObservableObject {
public private(set) var bet: Bet public private(set) var bet: Bet
/// Details about the answers available for the 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. /// List of user participations in the bet.
public private(set) var participations: [Participation] 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? public private(set) var finalAnswer: String?
/// Custom Constructor /// Custom Constructor
@ -31,11 +28,10 @@ public class BetDetail: ObservableObject {
/// - answers: Details about the answers available for the bet. /// - answers: Details about the answers available for the bet.
/// - participations: List of user participations in the bet. /// - participations: List of user participations in the bet.
/// - userParticipation: The user's own participation 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.bet = bet
self.answers = answers self.answers = answers
self.participations = participations self.participations = participations
self.userParticipation = userParticipation
self.finalAnswer = finalAnswer self.finalAnswer = finalAnswer
} }

@ -10,36 +10,4 @@ import Foundation
/// A subclass of Bet that represents a binary bet, where participants make a choice between two possible outcomes. /// A subclass of Bet that represents a binary bet, where participants make a choice between two possible outcomes.
public class BinaryBet: Bet { 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)
}
} }

@ -9,6 +9,7 @@ import Foundation
public protocol FactoryBet { public protocol FactoryBet {
func toResponse(bet: Bet) -> [String: Any] func toResponse(bet: Bet) -> [String: Any]
func toModel(from json: [String: Any]) -> Bet? func toBet(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 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
} }

@ -0,0 +1,12 @@
//
// File.swift
//
//
// Created by étudiant on 23/01/2024.
//
import Foundation
public enum BetStatus {
case WAITING, IN_PROGRESS, FINISHED
}

@ -17,7 +17,7 @@ public struct Manager {
} }
public func addBet(theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User) { 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) { public func getBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) {

@ -30,10 +30,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, 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.nameTeam1 = nameTeam1
self.nameTeam2 = nameTeam2 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 /// Custom Constructor without Id
@ -50,9 +50,9 @@ 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, 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.nameTeam1 = nameTeam1
self.nameTeam2 = nameTeam2 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)
} }
} }

@ -8,7 +8,7 @@
import Foundation import Foundation
/// A class representing a user's participation in a bet. /// A class representing a user's participation in a bet.
public class Participation: ObservableObject, Identifiable{ public class Participation: ObservableObject, Identifiable {
public let id: UUID public let id: UUID
/// The amount of stake in the bet. /// The amount of stake in the bet.
@ -24,7 +24,7 @@ public class Participation: ObservableObject, Identifiable{
public private(set) var user: User public private(set) var user: User
/// The unique identifier of the bet. /// The unique identifier of the bet.
let betId: String public private(set) var betId: String
/// Custom Constructor /// Custom Constructor
/// ///

@ -8,10 +8,10 @@
import Foundation import Foundation
public struct User { public struct User {
public var username: String public private(set) var username: String
public var email: String public private(set) var email: String
public var nbCoins: Int public private(set) var nbCoins: Int
public var friends: [User] public private(set) var friends: [User]
public init(username: String, email: String, nbCoins: Int, friends: [User]) { public init(username: String, email: String, nbCoins: Int, friends: [User]) {
self.username = username self.username = username

@ -37,8 +37,8 @@ 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),
totalStakes: 100,
isPublic: true, isPublic: true,
status: .IN_PROGRESS,
invited: [], invited: [],
author: user1, author: user1,
registered: [user2] registered: [user2]
@ -50,8 +50,8 @@ 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),
totalStakes: 150,
isPublic: false, isPublic: false,
status: .IN_PROGRESS,
invited: [user3], invited: [user3],
author: user1, author: user1,
registered: [user2] 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 ?", 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),
totalStakes: 75,
isPublic: true, isPublic: true,
status: .FINISHED,
invited: [], invited: [],
author: user1, author: user1,
registered: [user2, user1, user3] registered: [user2, user1, user3]
@ -76,8 +76,8 @@ 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),
totalStakes: 120,
isPublic: false, isPublic: false,
status: .FINISHED,
invited: [user1], invited: [user1],
author: user2, author: user2,
registered: [user3] registered: [user3]
@ -85,7 +85,7 @@ struct Stub {
self.bets.append(bet4) self.bets.append(bet4)
for bet in bets { 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) self.betsDetail.append(betDetail)
} }
@ -97,7 +97,7 @@ struct Stub {
} }
public mutating func add(bet: Bet) { 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) self.betsDetail.append(newBetDetail)
} }
} }

Loading…
Cancel
Save