Converted all the model's structs to classes 🔨

pull/9/head
Emre KARTAL 1 year ago
parent 438cdb63d7
commit f4adde1bb3

@ -58,7 +58,7 @@ class AuthService: IAuthService {
request.setValue("application/json", forHTTPHeaderField: "Content-Type") request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let json = [ let json = [
"email": email, "email": email.lowercased(),
"username": username.lowercased(), "username": username.lowercased(),
"password": password, "password": password,
"nbCoins": "0" "nbCoins": "0"

@ -113,7 +113,7 @@ struct CreationBetView: View {
.frame(height: 40) .frame(height: 40)
) )
.frame(width: 350, height: 40) .frame(width: 350, height: 40)
.foregroundColor(.black) .foregroundColor(AllInColors.primaryTextColor)
.overlay( .overlay(
RoundedRectangle(cornerRadius: 10, style: .continuous) RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(AllInColors.delimiterGrey, lineWidth: 1) .stroke(AllInColors.delimiterGrey, lineWidth: 1)
@ -155,7 +155,7 @@ struct CreationBetView: View {
.frame(height: 110) .frame(height: 110)
) )
.frame(width: 350, height: 110) .frame(width: 350, height: 110)
.foregroundColor(.black) .foregroundColor(AllInColors.primaryTextColor)
.overlay( .overlay(
RoundedRectangle(cornerRadius: 10, style: .continuous) RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(AllInColors.delimiterGrey, lineWidth: 1) .stroke(AllInColors.delimiterGrey, lineWidth: 1)

@ -5,6 +5,9 @@ import PackageDescription
let package = Package( let package = Package(
name: "Api", name: "Api",
platforms: [
.iOS(.v13)
],
products: [ products: [
// Products define the executables and libraries a package produces, and make them visible to other packages. // Products define the executables and libraries a package produces, and make them visible to other packages.
.library( .library(

@ -43,8 +43,6 @@ public struct UserApiManager: UserDataManager {
"createdBy": token "createdBy": token
] ]
print (json)
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
print ("ALLIN : Add BET") print ("ALLIN : Add BET")

@ -5,6 +5,9 @@ import PackageDescription
let package = Package( let package = Package(
name: "Model", name: "Model",
platforms: [
.iOS(.v13)
],
products: [ products: [
// Products define the executables and libraries a package produces, and make them visible to other packages. // Products define the executables and libraries a package produces, and make them visible to other packages.
.library( .library(

@ -7,16 +7,56 @@
import Foundation import Foundation
public protocol Bet { /// A class representing a betting entity, including details about the bet theme, participants, and deadlines.
//public private(set) var id: String public class Bet: ObservableObject {
var theme: String { get set } /// The theme or topic of the bet.
var phrase: String { get set } public var theme: String
var endRegisterDate: Date { get set }
var endBetDate: Date { get set }
var totalStakes: Int { get set }
var isPublic: Bool { get set }
var invited: [User] { get set }
var author: User { get set }
var registered: [User] { get set }
/// The specific phrase or question related to the bet.
public var phrase: String
/// The deadline for users to register for the bet.
public var endRegisterDate: Date
/// The deadline for the actual betting to take place.
public var endBetDate: Date
/// The total stakes or amount involved in the bet.
public var totalStakes: Int
/// Indicates whether the bet is public or private.
public var isPublic: Bool
/// List of users who are invited to participate in the bet.
public var invited: [User]
/// The user who created the bet.
public var author: User
/// List of users who have registered for the bet.
public var registered: [User]
/// Custom Constructor
///
/// - Parameters:
/// - theme: The theme or topic of the bet.
/// - 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]) {
self.theme = theme
self.phrase = phrase
self.endRegisterDate = endRegisterDate
self.endBetDate = endBetDate
self.totalStakes = totalStakes
self.isPublic = isPublic
self.invited = invited
self.author = author
self.registered = registered
}
} }

@ -7,37 +7,22 @@
import Foundation import Foundation
public struct BinaryBet: Bet { /// A subclass of Bet that represents a binary bet, where participants make a choice between two possible outcomes.
public var theme: String public class BinaryBet: Bet {
public var phrase: String
public var endRegisterDate: Date
public var endBetDate: Date
public var totalStakes: Int
public var isPublic: Bool
public var invited: [User]
public var author: User
public var registered: [User]
public init( // Custom Constructor
theme: String, ///
phrase: String, /// - Parameters:
endRegisterDate: Date, /// - theme: The theme or topic of the binary bet.
endBetDate: Date, /// - phrase: The specific phrase or question related to the binary bet.
totalStakes: Int, /// - endRegisterDate: The deadline for users to register for the binary bet.
isPublic: Bool, /// - endBetDate: The deadline for the actual betting to take place for the binary bet.
invited: [User], /// - totalStakes: The total stakes or amount involved in the binary bet.
author: User, /// - isPublic: Indicates whether the binary bet is public or private.
registered: [User] /// - invited: List of users who are invited to participate in the binary bet.
) { /// - author: The user who created the binary bet.
self.theme = theme /// - registered: List of users who have registered for the binary bet.
self.phrase = phrase public override init(theme: String, phrase: String, endRegisterDate: Date, endBetDate: Date, totalStakes: Int, isPublic: Bool, invited: [User], author: User, registered: [User]) {
self.endRegisterDate = endRegisterDate super.init(theme: theme, phrase: phrase, endRegisterDate: endRegisterDate, endBetDate: endBetDate, totalStakes: totalStakes, isPublic: isPublic, invited: invited, author: author, registered: registered)
self.endBetDate = endBetDate
self.totalStakes = totalStakes
self.isPublic = isPublic
self.invited = invited
self.author = author
self.registered = registered
} }
} }

@ -7,16 +7,27 @@
import Foundation import Foundation
/// Enum to represent the possible answers for a binary participation.
public enum YesNo { public enum YesNo {
case yes case yes
case no case no
} }
public struct BinaryParticipation: Participation { /// A subclass of Participation that represents a binary participation (yes/no) in a bet.
public var coinAmount: Int public class BinaryParticipation: Participation {
public var date: Date /// The answer for the binary participation (yes or no).
public var user: User
public var bet: Bet
public var answer: YesNo 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)
}
} }

@ -7,16 +7,7 @@
import Foundation import Foundation
public struct CustomBet: Bet { /// A subclass of Bet that represents a custom bet, allowing users to define their own parameters and rules.
public var theme: String public class CustomBet: Bet {
public var phrase: String
public var endRegisterDate: Date
public var endBetDate: Date
public var totalStakes: Int
public var isPublic: Bool
public var invited: [User]
public var author: User
public var registered: [User]
public var possibleAnswers: [CustomBetResponse]
} }

@ -7,7 +7,15 @@
import Foundation import Foundation
public struct CustomBetResponse { /// A class representing a user's response to a custom bet.
public class CustomBetResponse {
/// The name or description of the custom bet response.
public var name: String public var name: String
/// Custom Constructor
///
/// - Parameter name: The name or description of the custom bet response.
public init(name: String) {
self.name = name
}
} }

@ -7,11 +7,21 @@
import Foundation import Foundation
public struct CustomParticipation: Participation { /// A subclass of Participation that represents a custom participation in a bet.
public var coinAmount: Int public class CustomParticipation: Participation {
public var date: Date /// The user's response to the custom bet.
public var user: User
public var bet: Bet
public var answer: CustomBetResponse 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)
}
} }

@ -19,5 +19,4 @@ public struct Manager {
public func addBet(bet: Bet) { public func addBet(bet: Bet) {
userDataManager.addBet(bet: bet) userDataManager.addBet(bet: bet)
} }
} }

@ -7,17 +7,31 @@
import Foundation import Foundation
public struct MatchBet: Bet { /// A subclass of Bet that represents a bet on a match between two teams.
public var theme: String public class MatchBet: Bet {
public var phrase: String /// The name of the first team involved in the match.
public var endRegisterDate: Date
public var endBetDate: Date
public var totalStakes: Int
public var isPublic: Bool
public var invited: [User]
public var author: User
public var registered: [User]
public var nameTeam1: String public var nameTeam1: String
/// The name of the second team involved in the match.
public var nameTeam2: String public var nameTeam2: String
/// Custom Constructor
///
/// - Parameters:
/// - theme: The theme or topic of the match bet.
/// - phrase: The specific phrase or question related to the match bet.
/// - endRegisterDate: The deadline for users to register for the match bet.
/// - endBetDate: The deadline for the actual betting to take place for the match bet.
/// - totalStakes: The total stakes or amount involved in the match bet.
/// - isPublic: Indicates whether the match bet is public or private.
/// - invited: List of users who are invited to participate in the match bet.
/// - author: The user who created 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.
/// - 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) {
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)
}
} }

@ -7,12 +7,26 @@
import Foundation import Foundation
public struct MatchParticipation: Participation { /// A subclass of Participation that represents a user's participation in a match bet.
public var coinAmount: Int public class MatchParticipation: Participation {
public var date: Date /// The points earned by the user for the first team in the match.
public var user: User public var pointsTeam1: Int
public var bet: Bet
public var PointsTeam1: Int
public var PointsTeam2: 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)
}
} }

@ -7,10 +7,31 @@
import Foundation import Foundation
public protocol Participation { /// A class representing a user's participation in a bet, including the amount of coins, date, user, and the associated bet.
var coinAmount: Int { get set } public class Participation: ObservableObject {
var date: Date { get set } /// The amount of coins involved in the participation.
var user: User { get set } var coinAmount: Int
var bet: Bet { get set }
/// The date and time when the participation occurred.
var date: Date
/// The user who participated in the bet.
var user: User
/// The bet in which the user participated.
var bet: Bet
/// Custom Constructor
///
/// - Parameters:
/// - coinAmount: The amount of coins involved in the participation.
/// - date: The date and time when the participation occurred.
/// - 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
self.date = date
self.user = user
self.bet = bet
}
} }

@ -5,6 +5,9 @@ import PackageDescription
let package = Package( let package = Package(
name: "StubLib", name: "StubLib",
platforms: [
.iOS(.v13)
],
products: [ products: [
// Products define the executables and libraries a package produces, and make them visible to other packages. // Products define the executables and libraries a package produces, and make them visible to other packages.
.library( .library(

Loading…
Cancel
Save