parent
c381fdf0e7
commit
6eb3b2e8cd
@ -0,0 +1,43 @@
|
||||
//
|
||||
// BetAnswerDetail.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 19/01/2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A class representing detailed information about a specific answer option for a bet.
|
||||
public class BetAnswerDetail: ObservableObject {
|
||||
|
||||
/// The response or outcome associated with this answer.
|
||||
public private(set) var response: String
|
||||
|
||||
/// The total amount of stakes placed on this answer.
|
||||
public private(set) var totalStakes: Int
|
||||
|
||||
/// The total number of participants who selected this answer.
|
||||
public private(set) var totalParticipants: Int
|
||||
|
||||
/// The highest stake placed on this answer.
|
||||
public private(set) var highestStake: Int
|
||||
|
||||
/// The odds associated with this answer.
|
||||
public private(set) var odds: Float
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - response: The response or outcome associated with this answer.
|
||||
/// - totalStakes: The total amount of stakes placed on this answer.
|
||||
/// - totalParticipants: The total number of participants who selected this answer.
|
||||
/// - highestStake: The highest stake placed on this answer.
|
||||
/// - odds: The odds associated with this answer.
|
||||
public init(response: String, totalStakes: Int, totalParticipants: Int, highestStake: Int, odds: Float) {
|
||||
self.response = response
|
||||
self.totalStakes = totalStakes
|
||||
self.totalParticipants = totalParticipants
|
||||
self.highestStake = highestStake
|
||||
self.odds = odds
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
//
|
||||
// BetDetail.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 19/01/2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A class representing detailed information about a specific bet, including answers and user participations.
|
||||
public class BetDetail: ObservableObject {
|
||||
|
||||
/// The main bet information.
|
||||
public private(set) var bet: Bet
|
||||
|
||||
/// Details about the answers available for the bet.
|
||||
public private(set) var answers: [BetAnswerDetail]
|
||||
|
||||
/// 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
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - bet: The main bet information.
|
||||
/// - 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) {
|
||||
self.bet = bet
|
||||
self.answers = answers
|
||||
self.participations = participations
|
||||
self.userParticipation = userParticipation
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
//
|
||||
// BinaryParticipation.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Enum to represent the possible answers for a binary participation.
|
||||
public enum YesNo {
|
||||
case yes
|
||||
case no
|
||||
}
|
||||
|
||||
/// A subclass of Participation that represents a binary participation (yes/no) in a bet.
|
||||
public class BinaryParticipation: Participation {
|
||||
/// The answer for the binary participation (yes or no).
|
||||
public var answer: YesNo
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - coinAmount: The amount of coins involved in the binary participation.
|
||||
/// - date: The date and time when the binary participation occurred.
|
||||
/// - user: The user who participated in the binary bet.
|
||||
/// - bet: The binary bet in which the user participated.
|
||||
/// - answer: The answer for the binary participation (yes or no).
|
||||
public init(coinAmount: Int, date: Date, user: User, bet: Bet, answer: YesNo) {
|
||||
self.answer = answer
|
||||
super.init(coinAmount: coinAmount, date: date, user: user, bet: bet)
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
//
|
||||
// CustomParticipation.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A subclass of Participation that represents a custom participation in a bet.
|
||||
public class CustomParticipation: Participation {
|
||||
/// The user's response to the custom bet.
|
||||
public var answer: CustomBetResponse
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - coinAmount: The amount of coins involved in the custom participation.
|
||||
/// - date: The date and time when the custom participation occurred.
|
||||
/// - user: The user who participated in the custom bet.
|
||||
/// - bet: The custom bet in which the user participated.
|
||||
/// - answer: The user's response to the custom bet.
|
||||
public init(coinAmount: Int, date: Date, user: User, bet: Bet, answer: CustomBetResponse) {
|
||||
self.answer = answer
|
||||
super.init(coinAmount: coinAmount, date: date, user: user, bet: bet)
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
//
|
||||
// MatchParticipation.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A subclass of Participation that represents a user's participation in a match bet.
|
||||
public class MatchParticipation: Participation {
|
||||
/// The points earned by the user for the first team in the match.
|
||||
public var pointsTeam1: Int
|
||||
|
||||
/// The points earned by the user for the second team in the match.
|
||||
public var pointsTeam2: Int
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - coinAmount: The amount of coins involved in the match participation.
|
||||
/// - date: The date and time when the match participation occurred.
|
||||
/// - user: The user who participated in the match bet.
|
||||
/// - bet: The match bet in which the user participated.
|
||||
/// - pointsTeam1: The points earned by the user for the first team in the match.
|
||||
/// - pointsTeam2: The points earned by the user for the second team in the match.
|
||||
public init(coinAmount: Int, date: Date, user: User, bet: Bet, pointsTeam1: Int, pointsTeam2: Int) {
|
||||
self.pointsTeam1 = pointsTeam1
|
||||
self.pointsTeam2 = pointsTeam2
|
||||
super.init(coinAmount: coinAmount, date: date, user: user, bet: bet)
|
||||
}
|
||||
}
|
@ -1,37 +1,43 @@
|
||||
//
|
||||
// Participation.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// A class representing a user's participation in a bet, including the amount of coins, date, user, and the associated bet.
|
||||
/// A class representing a user's participation in a bet.
|
||||
public class Participation: ObservableObject {
|
||||
/// The amount of coins involved in the participation.
|
||||
var coinAmount: Int
|
||||
|
||||
/// The amount of stake in the bet.
|
||||
public private(set) var stake: Int
|
||||
|
||||
/// The date and time when the participation occurred.
|
||||
var date: Date
|
||||
public private(set) var date: Date
|
||||
|
||||
/// The response or outcome of the participation.
|
||||
public private(set) var response: String
|
||||
|
||||
/// The user who participated in the bet.
|
||||
var user: User
|
||||
public private(set) var user: User
|
||||
|
||||
/// The bet in which the user participated.
|
||||
var bet: Bet
|
||||
/// The unique identifier of the bet.
|
||||
let betId: String
|
||||
|
||||
/// Custom Constructor
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - coinAmount: The amount of coins involved in the participation.
|
||||
/// - stake: The amount of stake in the bet.
|
||||
/// - date: The date and time when the participation occurred.
|
||||
/// - response: The response or outcome of the participation.
|
||||
/// - user: The user who participated in the bet.
|
||||
/// - bet: The bet in which the user participated.
|
||||
init(coinAmount: Int, date: Date, user: User, bet: Bet) {
|
||||
self.coinAmount = coinAmount
|
||||
/// - betId: The unique identifier of the bet.
|
||||
public init(stake: Int, date: Date, response: String, user: User, betId: String) {
|
||||
self.stake = stake
|
||||
self.date = date
|
||||
self.response = response
|
||||
self.user = user
|
||||
self.bet = bet
|
||||
self.betId = betId
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
# ViewModel
|
||||
# StubLib
|
||||
|
||||
A description of this package.
|
@ -0,0 +1,32 @@
|
||||
//
|
||||
// BetStubManager.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 31/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Model
|
||||
|
||||
public struct BetStubManager: BetDataManager {
|
||||
|
||||
public init() {}
|
||||
|
||||
public func getBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) {
|
||||
completion(Stub.shared.bets)
|
||||
}
|
||||
|
||||
public func getUsers(username: String) -> [User] {
|
||||
return []
|
||||
}
|
||||
|
||||
public func getBet(withId id: String, completion: @escaping (BetDetail) -> Void) {
|
||||
|
||||
if let betDetail = Stub.shared.betsDetail.first(where: { $0.bet.id == id }) {
|
||||
completion(betDetail)
|
||||
} else {
|
||||
print("BetDetail with ID \(id) not found.")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
//
|
||||
// Stub.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 01/01/2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Model
|
||||
|
||||
struct Stub {
|
||||
|
||||
static var shared = Stub()
|
||||
public var bets: [Bet] = []
|
||||
public var betsDetail: [BetDetail] = []
|
||||
public var users: [User] = []
|
||||
|
||||
public init() {
|
||||
loadBets()
|
||||
}
|
||||
|
||||
public mutating func loadBets() {
|
||||
|
||||
var user1 = User(username: "Lucas", email: "lucas.delanier@etu.uca.fr", nbCoins: 100, friends: [])
|
||||
users.append(user1)
|
||||
|
||||
var user2 = User(username: "Imri", email: "emre.kartal@etu.uca.fr", nbCoins: 75, friends: [user1])
|
||||
users.append(user2)
|
||||
user1.addFriend(user: user2)
|
||||
|
||||
let user3 = User(username: "Arthur", email: "arthur.valin@etu.uca.fr", nbCoins: 30, friends: [user2])
|
||||
users.append(user3)
|
||||
user2.addFriend(user: user3)
|
||||
|
||||
let bet1 = BinaryBet(
|
||||
theme: "Football - Finale de la Ligue des Champions",
|
||||
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,
|
||||
invited: [],
|
||||
author: user1,
|
||||
registered: [user2]
|
||||
)
|
||||
self.bets.append(bet1)
|
||||
|
||||
let bet2 = BinaryBet(
|
||||
theme: "Cuisine - Concours de cuisine en direct",
|
||||
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,
|
||||
invited: [user3],
|
||||
author: user1,
|
||||
registered: [user2]
|
||||
)
|
||||
self.bets.append(bet2)
|
||||
|
||||
let bet3 = BinaryBet(
|
||||
theme: "Technologie - Lancement d'un nouveau smartphone",
|
||||
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,
|
||||
invited: [],
|
||||
author: user1,
|
||||
registered: [user2, user1, user3]
|
||||
)
|
||||
self.bets.append(bet3)
|
||||
|
||||
let bet4 = BinaryBet(
|
||||
theme: "Cinéma - Oscars 2024",
|
||||
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,
|
||||
invited: [user1],
|
||||
author: user2,
|
||||
registered: [user3]
|
||||
)
|
||||
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: ""))
|
||||
self.betsDetail.append(betDetail)
|
||||
}
|
||||
}
|
||||
|
||||
public mutating func add(bet: Bet) {
|
||||
let newBetDetail = BetDetail(bet: bet, answers: [], participations: [], userParticipation: Participation(stake: 0, date: Date(), response: "", user: users[1], betId: ""))
|
||||
self.betsDetail.append(newBetDetail)
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
//
|
||||
// ManagerVM.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 30/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Model
|
||||
|
||||
public class ManagerVM: ObservableObject {
|
||||
|
||||
@Published var model: Manager
|
||||
@Published public var bets: [Bet] = []
|
||||
@Published public var bet: Bet?
|
||||
|
||||
public init(withModel model: Manager) {
|
||||
self.model = model
|
||||
}
|
||||
|
||||
public func getPublicBets() {
|
||||
model.getBets(withIndex: 0, withCount: 20) { bets in
|
||||
self.bets = bets
|
||||
}
|
||||
}
|
||||
|
||||
public func addBet(theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User) {
|
||||
model.addBet(bet: BinaryBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, totalStakes: 0, isPublic: isPublic, invited: [], author: creator, registered: []))
|
||||
}
|
||||
|
||||
public func getBet(withId id: String) {
|
||||
model.getBet(withId: id) { bet in
|
||||
self.bet = bet
|
||||
}
|
||||
}
|
||||
|
||||
public func getHistoricBets() {
|
||||
model.getHistoricBets(withIndex: 0, withCount: 20) { bets in
|
||||
self.bets = bets
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue