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")
let json = [
"email": email,
"email": email.lowercased(),
"username": username.lowercased(),
"password": password,
"nbCoins": "0"

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

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

@ -42,9 +42,7 @@ public struct UserApiManager: UserDataManager {
"response": [],
"createdBy": token
]
print (json)
if let jsonData = try? JSONSerialization.data(withJSONObject: json, options: []){
URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in
print ("ALLIN : Add BET")

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

@ -7,16 +7,56 @@
import Foundation
public protocol Bet {
//public private(set) var id: String
var theme: String { get set }
var phrase: String { get set }
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 }
/// A class representing a betting entity, including details about the bet theme, participants, and deadlines.
public class Bet: ObservableObject {
/// The theme or topic of the bet.
public var theme: String
/// 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
public struct BinaryBet: Bet {
public var theme: String
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]
/// A subclass of Bet that represents a binary bet, where participants make a choice between two possible outcomes.
public class BinaryBet: 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
// Custom Constructor
///
/// - 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)
}
}

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

@ -7,16 +7,7 @@
import Foundation
public struct CustomBet: Bet {
public var theme: String
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]
/// A subclass of Bet that represents a custom bet, allowing users to define their own parameters and rules.
public class CustomBet: Bet {
}

@ -7,7 +7,15 @@
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
/// 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
public struct CustomParticipation: Participation {
public var coinAmount: Int
public var date: Date
public var user: User
public var bet: Bet
/// 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)
}
}

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

@ -7,17 +7,31 @@
import Foundation
public struct MatchBet: Bet {
public var theme: String
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]
/// A subclass of Bet that represents a bet on a match between two teams.
public class MatchBet: Bet {
/// The name of the first team involved in the match.
public var nameTeam1: String
/// The name of the second team involved in the match.
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
public struct MatchParticipation: Participation {
public var coinAmount: Int
public var date: Date
public var user: User
public var bet: Bet
public var PointsTeam1: Int
public var PointsTeam2: Int
/// 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)
}
}

@ -7,10 +7,31 @@
import Foundation
public protocol Participation {
var coinAmount: Int { get set }
var date: Date { get set }
var user: User { get set }
var bet: Bet { get set }
/// A class representing a user's participation in a bet, including the amount of coins, date, user, and the associated bet.
public class Participation: ObservableObject {
/// The amount of coins involved in the participation.
var coinAmount: Int
/// 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(
name: "StubLib",
platforms: [
.iOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(

Loading…
Cancel
Save