feature/new-shortcut-ranking
parent
d5a9c75efb
commit
105b89c111
@ -1,22 +0,0 @@
|
||||
//
|
||||
// User.swift
|
||||
// AllIn
|
||||
//
|
||||
// Created by Emre on 11/10/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class User {
|
||||
|
||||
public var username: String
|
||||
public var email: String
|
||||
public var nbCoins: Int
|
||||
|
||||
public init(username: String, email: String, nbCoins: Int)
|
||||
{
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.nbCoins = nbCoins
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// BetViewModel.swift
|
||||
// AllIn
|
||||
//
|
||||
// Created by Emre on 30/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import DependencyInjection
|
||||
import ViewModel
|
||||
|
||||
class BetViewModel: ObservableObject {
|
||||
|
||||
@Inject var manager: ManagerVM
|
||||
|
||||
init() {
|
||||
getItems()
|
||||
}
|
||||
|
||||
func getItems() {
|
||||
|
||||
}
|
||||
|
||||
func deleteItem(indexSet: IndexSet) {
|
||||
|
||||
}
|
||||
|
||||
func moveltem(from: IndexSet, to: Int) {
|
||||
|
||||
}
|
||||
|
||||
func addItem(title: String) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
//
|
||||
// CreationBetViewModel.swift
|
||||
// AllIn
|
||||
//
|
||||
// Created by Emre on 30/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import DependencyInjection
|
||||
import ViewModel
|
||||
|
||||
class CreationBetViewModel: ObservableObject {
|
||||
|
||||
@Inject var manager: ManagerVM
|
||||
@Published var theme: String = ""
|
||||
@Published var description: String = ""
|
||||
@Published var isPublic = true
|
||||
@Published var endRegisterDate = Date()
|
||||
@Published var endBetDate = Date()
|
||||
|
||||
@Published var themeFieldError: String?
|
||||
@Published var descriptionFieldError: String?
|
||||
@Published var endRegisterDateFieldError: String?
|
||||
@Published var endBetDateFieldError: String?
|
||||
|
||||
func create() {
|
||||
manager.addBet()
|
||||
}
|
||||
|
||||
func checkAndSetError(forLogin checkLogin: Bool, forPassword checkPassword: Bool) -> Bool {
|
||||
/*var newLoginIdentifierFieldError: String?
|
||||
var newLoginPasswordFieldError: String?
|
||||
var hasError = false
|
||||
|
||||
// Login
|
||||
if checkLogin, loginIdentifier.isEmpty {
|
||||
newLoginIdentifierFieldError = "Veuillez saisir votre identifiant."
|
||||
hasError = true
|
||||
}
|
||||
|
||||
// Password
|
||||
if checkPassword, loginPassword.isEmpty {
|
||||
newLoginPasswordFieldError = "Veuillez saisir votre mot de passe."
|
||||
hasError = true
|
||||
}
|
||||
|
||||
if !hasError {
|
||||
// No error
|
||||
return true
|
||||
}
|
||||
|
||||
withAnimation {
|
||||
loginIdentifierFieldError = newLoginIdentifierFieldError
|
||||
loginPasswordFieldError = newLoginPasswordFieldError
|
||||
}*/
|
||||
return false
|
||||
}
|
||||
|
||||
func resetAllFieldErrors() {
|
||||
withAnimation {
|
||||
themeFieldError = nil
|
||||
descriptionFieldError = nil
|
||||
endRegisterDateFieldError = nil
|
||||
endBetDateFieldError = nil
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// FriendsViewModel.swift
|
||||
// AllIn
|
||||
//
|
||||
// Created by Emre on 30/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import DependencyInjection
|
||||
import ViewModel
|
||||
|
||||
class FriendsViewModel: ObservableObject {
|
||||
|
||||
@Inject var manager: ManagerVM
|
||||
|
||||
init() {
|
||||
getItems()
|
||||
}
|
||||
|
||||
func getItems ( ) {
|
||||
|
||||
}
|
||||
|
||||
func deleteItem(indexSet: IndexSet) {
|
||||
|
||||
}
|
||||
|
||||
func moveltem(from: IndexSet, to: Int) {
|
||||
|
||||
}
|
||||
|
||||
func addItem(title: String) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
//
|
||||
// RankingViewModel.swift
|
||||
// AllIn
|
||||
//
|
||||
// Created by Emre on 30/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import DependencyInjection
|
||||
import ViewModel
|
||||
|
||||
class RankingViewModel: ObservableObject {
|
||||
|
||||
@Inject var manager: ManagerVM
|
||||
|
||||
init() {
|
||||
getItems()
|
||||
}
|
||||
|
||||
func getItems ( ) {
|
||||
|
||||
}
|
||||
|
||||
func deleteItem(indexSet: IndexSet) {
|
||||
|
||||
}
|
||||
|
||||
func moveltem(from: IndexSet, to: Int) {
|
||||
|
||||
}
|
||||
|
||||
func addItem(title: String) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Bet.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
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 }
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
//
|
||||
// BetDataManager.swift
|
||||
//
|
||||
//
|
||||
// Created by étudiant on 29/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol BetDataManager {
|
||||
func getBets(withIndex index: Int, withCount count: Int) -> [Bet]
|
||||
func getUsers(username: String) -> [User]
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
//
|
||||
// BinaryBet.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
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]
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// BinaryParticipation.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
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
|
||||
public var answer: YesNo
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// CustomBet.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
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]
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
//
|
||||
// CustomBetResponse.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct CustomBetResponse {
|
||||
public var name: String
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// CustomParticipation.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct CustomParticipation: Participation {
|
||||
public var coinAmount: Int
|
||||
public var date: Date
|
||||
public var user: User
|
||||
public var bet: Bet
|
||||
public var answer: CustomBetResponse
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Manager.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 29/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct Manager {
|
||||
let betDataManager: BetDataManager
|
||||
let userDataManager: UserDataManager
|
||||
|
||||
public init(withBetDataManager betDataManager: BetDataManager, withUserDataManager userDataManager: UserDataManager){
|
||||
self.betDataManager = betDataManager
|
||||
self.userDataManager = userDataManager
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
//
|
||||
// MatchBet.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
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]
|
||||
public var nameTeam1: String
|
||||
public var nameTeam2: String
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
//
|
||||
// MatchParticipation.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
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
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
public struct Model {
|
||||
public private(set) var text = "Hello, World!"
|
||||
|
||||
public init() {
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
//
|
||||
// Participation.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 28/12/2023.
|
||||
//
|
||||
|
||||
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 }
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
//
|
||||
// User.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 11/10/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct User {
|
||||
public var username: String
|
||||
public var email: String
|
||||
public var nbCoins: Int
|
||||
public var friends: [User]
|
||||
|
||||
public init(username: String, email: String, nbCoins: Int, friends: [User]) {
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.nbCoins = nbCoins
|
||||
self.friends = friends
|
||||
}
|
||||
|
||||
public mutating func addFriend(user: User) {
|
||||
self.friends.append(user)
|
||||
}
|
||||
|
||||
public static func mapUser(from json: [String: Any]) -> User? {
|
||||
guard let username = json["username"] as? String,
|
||||
let email = json["email"] as? String,
|
||||
let nbCoins = json["nbCoins"] as? Int else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return User(username: username, email: email, nbCoins: nbCoins, friends: [])
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
//
|
||||
// UserDataManager.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 29/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol UserDataManager {
|
||||
func getBets(withIndex index: Int, withCount count: Int) -> [Bet]
|
||||
func addBet(bet: Bet)
|
||||
func getFriends() -> [User]
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
import XCTest
|
||||
@testable import Model
|
||||
|
||||
final class ModelTests: XCTestCase {
|
||||
func testExample() throws {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct
|
||||
// results.
|
||||
XCTAssertEqual(Model().text, "Hello, World!")
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
// swift-tools-version: 5.8
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "StubLib",
|
||||
products: [
|
||||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||
.library(
|
||||
name: "StubLib",
|
||||
targets: ["StubLib"]),
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
// .package(url: /* package url */, from: "1.0.0"),
|
||||
.package(name: "Model", path: "../Model")
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||
.target(
|
||||
name: "StubLib",
|
||||
dependencies: ["Model"]),
|
||||
.testTarget(
|
||||
name: "StubLibTests",
|
||||
dependencies: ["StubLib"]),
|
||||
]
|
||||
)
|
@ -0,0 +1,3 @@
|
||||
# StubLib
|
||||
|
||||
A description of this package.
|
@ -0,0 +1,26 @@
|
||||
//
|
||||
// BetStubManager.swift
|
||||
//
|
||||
//
|
||||
// Created by étudiant on 31/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Model
|
||||
|
||||
public struct BetStubManager: BetDataManager {
|
||||
|
||||
public init() {}
|
||||
|
||||
public func getBets(withIndex index: Int, withCount count: Int) -> [Bet] {
|
||||
return Stub.shared.bets
|
||||
}
|
||||
|
||||
public func getUsers(username: String) -> [User] {
|
||||
return Stub.shared.users
|
||||
.filter { user in
|
||||
user.username.contains(username)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
//
|
||||
// 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 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)
|
||||
|
||||
var 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)
|
||||
|
||||
}
|
||||
|
||||
public mutating func add(bet: Bet) {
|
||||
self.bets.append(bet)
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
//
|
||||
// UserStubManager.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 31/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Model
|
||||
|
||||
public struct UserStubManager: UserDataManager {
|
||||
|
||||
private var username: String
|
||||
|
||||
public init(username: String) {
|
||||
self.username = username
|
||||
}
|
||||
|
||||
public func getBets(withIndex index: Int, withCount count: Int) -> [Bet] {
|
||||
return Stub.shared.bets.filter { bet in
|
||||
bet.registered.contains { user in
|
||||
user.username == self.username
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func addBet(bet: Bet) {
|
||||
Stub.shared.add(bet: bet)
|
||||
}
|
||||
|
||||
public func getFriends() -> [User] {
|
||||
return Stub.shared.users.filter { user in
|
||||
user.friends.contains { friend in
|
||||
friend.username == self.username
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/Packages
|
||||
/*.xcodeproj
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
.swiftpm/config/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
@ -0,0 +1,32 @@
|
||||
// swift-tools-version: 5.8
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "ViewModel",
|
||||
platforms: [
|
||||
.iOS(.v13)
|
||||
],
|
||||
products: [
|
||||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||
.library(
|
||||
name: "ViewModel",
|
||||
targets: ["ViewModel"]),
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
// .package(url: /* package url */, from: "1.0.0"),
|
||||
.package(name: "Model", path: "../Model")
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||
.target(
|
||||
name: "ViewModel",
|
||||
dependencies: ["Model"]),
|
||||
.testTarget(
|
||||
name: "ViewModelTests",
|
||||
dependencies: ["ViewModel"]),
|
||||
]
|
||||
)
|
@ -0,0 +1,3 @@
|
||||
# ViewModel
|
||||
|
||||
A description of this package.
|
@ -0,0 +1,25 @@
|
||||
//
|
||||
// ManagerVM.swift
|
||||
//
|
||||
//
|
||||
// Created by Emre on 30/12/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Model
|
||||
|
||||
public class ManagerVM: ObservableObject {
|
||||
@Published var model: Manager
|
||||
|
||||
public init(withModel model: Manager) {
|
||||
self.model = model
|
||||
}
|
||||
|
||||
public func getPublicBets() {
|
||||
|
||||
}
|
||||
|
||||
public func addBet() {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue