Add Model, ViewModel and Stublib, also upgrade the user authentication

feature/new-shortcut-ranking
Emre KARTAL 1 year ago
parent d5a9c75efb
commit 105b89c111

@ -2,12 +2,18 @@
<Workspace <Workspace
version = "1.0"> version = "1.0">
<FileRef <FileRef
location = "group:DependencyInjection/DependencyInjection.xcodeproj"> location = "group:AllInApp/AllInApp.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:Model"> location = "group:StubLib">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:AllInApp/AllInApp.xcodeproj"> location = "group:ViewModel">
</FileRef>
<FileRef
location = "group:DependencyInjection/DependencyInjection.xcodeproj">
</FileRef>
<FileRef
location = "group:Model">
</FileRef> </FileRef>
</Workspace> </Workspace>

@ -7,6 +7,9 @@
import SwiftUI import SwiftUI
import DependencyInjection import DependencyInjection
import Model
import ViewModel
import StubLib
@main @main
struct AllInApp: App { struct AllInApp: App {
@ -16,6 +19,7 @@ struct AllInApp: App {
init() { init() {
DI.addSingleton(IAuthService.self, AuthService()) DI.addSingleton(IAuthService.self, AuthService())
DI.addSingleton(ManagerVM.self, ManagerVM(withModel: Manager(withBetDataManager: BetStubManager(), withUserDataManager: UserStubManager(username: "Imri"))))
} }
var body: some Scene { var body: some Scene {

@ -6,11 +6,13 @@
// //
import SwiftUI import SwiftUI
import Model
class AppStateContainer: ObservableObject { class AppStateContainer: ObservableObject {
static let shared = AppStateContainer() static let shared = AppStateContainer()
let loggedState: LoggedState = LoggedState() let loggedState: LoggedState = LoggedState()
var onlineStatus: OnlineStatus = OnlineStatus() var onlineStatus: OnlineStatus = OnlineStatus()
var user: User?
@AppStorage("authenticationRefresh") var authenticationRefresh: String? @AppStorage("authenticationRefresh") var authenticationRefresh: String?
} }

@ -13,7 +13,7 @@ struct AllcoinsCounter: View {
Image("allcoinIcon") Image("allcoinIcon")
.resizable() .resizable()
.frame(width: 17, height: 17, alignment: .leading) .frame(width: 17, height: 17, alignment: .leading)
Text("541") Text(String(AppStateContainer.shared.user?.nbCoins ?? 0))
.fontWeight(.black) .fontWeight(.black)
.foregroundColor(AllInColors.primaryColor) .foregroundColor(AllInColors.primaryColor)
} }

@ -19,7 +19,7 @@ struct Menu: View {
.scaledToFit() .scaledToFit()
.frame(width: 100, height: 100) .frame(width: 100, height: 100)
.cornerRadius(180) .cornerRadius(180)
Text("Pseudo") Text(AppStateContainer.shared.user?.username.capitalized ?? "")
.fontWeight(.medium) .fontWeight(.medium)
.font(.system(size: 17)) .font(.system(size: 17))
.foregroundColor(.white) .foregroundColor(.white)

@ -15,17 +15,20 @@ struct ContentView: View {
var body: some View { var body: some View {
VStack { VStack {
NavigationView { if loggedState.connectedUser {
if loggedState.connectedUser { NavigationView {
MainView(page: "Bet") MainView(page: "Bet")
} else { }
.navigationViewStyle(StackNavigationViewStyle())
} else {
NavigationView {
WelcomeView() WelcomeView()
} }
.navigationViewStyle(StackNavigationViewStyle())
} }
.navigationViewStyle(StackNavigationViewStyle())
} }
.onAppear { .onAppear {
//authService.refreshAuthentication() { status in } authService.refreshAuthentication()
} }
} }
} }

@ -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
}
}

@ -6,6 +6,7 @@
// //
import Foundation import Foundation
import Model
class AuthService: IAuthService { class AuthService: IAuthService {
@ -30,9 +31,14 @@ class AuthService: IAuthService {
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let token = json["token"] as? String { let token = json["token"] as? String {
AppStateContainer.shared.authenticationRefresh = token; AppStateContainer.shared.authenticationRefresh = token;
self.initializeUser(withToken: token) { status in
if status != 200 {
completion(status)
AppStateContainer.shared.authenticationRefresh = nil;
}
}
} }
} }
completion(httpResponse.statusCode) completion(httpResponse.statusCode)
} }
}.resume() }.resume()
@ -56,19 +62,56 @@ class AuthService: IAuthService {
URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in
print ("ALLIN : Process REGISTER") print ("ALLIN : Process REGISTER")
if let httpResponse = response as? HTTPURLResponse { if let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 200 {
if let data = data,
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let token = json["token"] as? String {
AppStateContainer.shared.authenticationRefresh = token;
self.initializeUser(withToken: token) { status in
if status != 200 {
completion(status)
AppStateContainer.shared.authenticationRefresh = nil;
}
}
}
}
completion(httpResponse.statusCode) completion(httpResponse.statusCode)
} }
}.resume() }.resume()
} }
} }
func refreshAuthentication(completion: @escaping (Int) -> ()) { func refreshAuthentication() {
guard let token = AppStateContainer.shared.authenticationRefresh else { guard let token = AppStateContainer.shared.authenticationRefresh else {
completion(401)
return return
} }
print(token)
let url = URL(string: Config.allInApi + "users/token")!
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,
let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 200 {
if let userJson = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let user = User.mapUser(from: userJson) {
AppStateContainer.shared.user = user
AppStateContainer.shared.loggedState.connectedUser = true
}
} else {
AppStateContainer.shared.authenticationRefresh = nil
}
}
}.resume()
}
private func initializeUser(withToken token: String, completion: @escaping (Int) -> ()) {
let url = URL(string: Config.allInApi + "users/token")! let url = URL(string: Config.allInApi + "users/token")!
var request = URLRequest(url: url) var request = URLRequest(url: url)
request.httpMethod = "GET" request.httpMethod = "GET"
@ -76,13 +119,22 @@ class AuthService: IAuthService {
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
URLSession.shared.dataTask(with: request) { data, response, error in URLSession.shared.dataTask(with: request) { data, response, error in
if let httpResponse = response as? HTTPURLResponse { if let data = data,
completion(httpResponse.statusCode) let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 200 { if httpResponse.statusCode == 200 {
AppStateContainer.shared.loggedState.connectedUser = true if let userJson = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let user = User.mapUser(from: userJson) {
completion(httpResponse.statusCode)
AppStateContainer.shared.user = user
}
} else {
completion(httpResponse.statusCode)
} }
} else {
completion(500)
} }
}.resume() }.resume()
} }
} }

@ -10,5 +10,5 @@ import Foundation
protocol IAuthService { protocol IAuthService {
func login(login: String, password: String, completion : @escaping (Int)-> ()) func login(login: String, password: String, completion : @escaping (Int)-> ())
func register(username: String, email: String, password: String, completion : @escaping (Int)-> ()) func register(username: String, email: String, password: String, completion : @escaping (Int)-> ())
func refreshAuthentication(completion: @escaping (Int) -> ()) func refreshAuthentication()
} }

@ -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) {
}
}

@ -9,6 +9,7 @@ import SwiftUI
struct BetView: View { struct BetView: View {
@StateObject private var viewModel = BetViewModel()
@Binding var showMenu: Bool @Binding var showMenu: Bool
@State private var showingSheet = false @State private var showingSheet = false

@ -9,26 +9,25 @@ import SwiftUI
struct CreationBetView: View { struct CreationBetView: View {
@StateObject private var viewModel = CreationBetViewModel()
@Binding var showMenu: Bool
@State private var selectedTab = 0
// Popovers
@State private var showTitlePopover: Bool = false @State private var showTitlePopover: Bool = false
@State private var showDescriptionPopover: Bool = false @State private var showDescriptionPopover: Bool = false
@State private var showRegistrationEndDatePopover: Bool = false @State private var showRegistrationEndDatePopover: Bool = false
@State private var showBetEndDatePopover: Bool = false @State private var showBetEndDatePopover: Bool = false
@State private var showConfidentialityPopover: Bool = false @State private var showConfidentialityPopover: Bool = false
@State private var selectedTab = 0
@Binding var showMenu: Bool
@State var selectedConfidentiality = true
@State private var theme: String = ""
@State private var description: String = ""
@State var present = false
@State private var endRegisterDate = Date()
@State private var endBetDate = Date()
let dateRange: ClosedRange<Date> = { let dateRange: ClosedRange<Date> = {
let calendar = Calendar.current let calendar = Calendar.current
let startDate = Date() let startDate = Date()
let endDate = calendar.date(byAdding: .year, value: 10, to: startDate)! let endDate = calendar.date(byAdding: .year, value: 10, to: startDate)!
return startDate ... endDate return startDate ... endDate
}() }()
let screenWidth = UIScreen.main.bounds.width
@State private var response = "" @State private var response = ""
@State private var values: [String] = [] @State private var values: [String] = []
@ -40,7 +39,6 @@ struct CreationBetView: View {
] ]
@State var groupedItems: [[String]] = [[String]] () @State var groupedItems: [[String]] = [[String]] ()
let screenWidth = UIScreen.main.bounds.width
private func updateGroupedItems() { private func updateGroupedItems() {
@ -99,7 +97,7 @@ struct CreationBetView: View {
.frame(width: 340) .frame(width: 340)
.padding(.leading, 10) .padding(.leading, 10)
TextField("", text: $theme, prompt: Text("Études, sport, soirée...") TextField("", text: $viewModel.theme, prompt: Text("Études, sport, soirée...")
.foregroundColor(AllInColors.lightGrey300Color) .foregroundColor(AllInColors.lightGrey300Color)
.font(.system(size: 14)) .font(.system(size: 14))
.fontWeight(.light)) .fontWeight(.light))
@ -134,7 +132,7 @@ struct CreationBetView: View {
.frame(width: 340) .frame(width: 340)
.padding(.leading, 10) .padding(.leading, 10)
TextField("", text: $description, prompt: Text("David sera absent Lundi matin en cours ?") TextField("", text: $viewModel.description, prompt: Text("David sera absent Lundi matin en cours ?")
.foregroundColor(AllInColors.lightGrey300Color) .foregroundColor(AllInColors.lightGrey300Color)
.font(.system(size: 14)) .font(.system(size: 14))
.fontWeight(.light), axis: .vertical) .fontWeight(.light), axis: .vertical)
@ -171,7 +169,7 @@ struct CreationBetView: View {
HStack(spacing: 5) { HStack(spacing: 5) {
DatePicker( DatePicker(
"", "",
selection: $endRegisterDate, selection: $viewModel.endRegisterDate,
in: dateRange, in: dateRange,
displayedComponents: [.date, .hourAndMinute] displayedComponents: [.date, .hourAndMinute]
) )
@ -201,7 +199,7 @@ struct CreationBetView: View {
} }
DatePicker( DatePicker(
"", "",
selection: $endBetDate, selection: $viewModel.endBetDate,
in: dateRange, in: dateRange,
displayedComponents: [.date, .hourAndMinute] displayedComponents: [.date, .hourAndMinute]
) )
@ -227,15 +225,15 @@ struct CreationBetView: View {
.padding(.leading, 10) .padding(.leading, 10)
HStack(spacing: 5) { HStack(spacing: 5) {
ConfidentialityButton(image: "globe", text: "Public", selected: !selectedConfidentiality) ConfidentialityButton(image: "globe", text: "Public", selected: viewModel.isPublic)
.onTapGesture { .onTapGesture {
selectedConfidentiality = false viewModel.isPublic = true
} }
.padding(.trailing, 5) .padding(.trailing, 5)
ConfidentialityButton(image: "lock", text: "Privé", selected: selectedConfidentiality) ConfidentialityButton(image: "lock", text: "Privé", selected: !viewModel.isPublic)
.onTapGesture { .onTapGesture {
selectedConfidentiality = true viewModel.isPublic = false
} }
Spacer() Spacer()
} }
@ -246,7 +244,7 @@ struct CreationBetView: View {
VStack(spacing: 10) { VStack(spacing: 10) {
if self.selectedConfidentiality { if !self.viewModel.isPublic {
DropDownFriends() DropDownFriends()
.padding(.bottom, 30) .padding(.bottom, 30)
} }
@ -277,7 +275,9 @@ struct CreationBetView: View {
Spacer() Spacer()
HStack() { HStack() {
Spacer() Spacer()
Button(action: {}) { Button(action: {
viewModel.create()
}) {
Text("Publier le bet") Text("Publier le bet")
.font(.system(size: 24)) .font(.system(size: 24))
.fontWeight(.bold) .fontWeight(.bold)

@ -36,7 +36,6 @@
EC6B96AD2B24B4CC00FC1C58 /* AllInTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96AC2B24B4CC00FC1C58 /* AllInTests.swift */; }; EC6B96AD2B24B4CC00FC1C58 /* AllInTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96AC2B24B4CC00FC1C58 /* AllInTests.swift */; };
EC6B96B72B24B4CC00FC1C58 /* AllInUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96B62B24B4CC00FC1C58 /* AllInUITests.swift */; }; EC6B96B72B24B4CC00FC1C58 /* AllInUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96B62B24B4CC00FC1C58 /* AllInUITests.swift */; };
EC6B96B92B24B4CC00FC1C58 /* AllInUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96B82B24B4CC00FC1C58 /* AllInUITestsLaunchTests.swift */; }; EC6B96B92B24B4CC00FC1C58 /* AllInUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96B82B24B4CC00FC1C58 /* AllInUITestsLaunchTests.swift */; };
EC6B96C72B24B5A100FC1C58 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96C62B24B5A100FC1C58 /* User.swift */; };
EC6B96CC2B24B7E500FC1C58 /* IAuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */; }; EC6B96CC2B24B7E500FC1C58 /* IAuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */; };
EC6B96CF2B24B8D900FC1C58 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96CE2B24B8D900FC1C58 /* Config.swift */; }; EC6B96CF2B24B8D900FC1C58 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96CE2B24B8D900FC1C58 /* Config.swift */; };
EC6B96D12B24BAE800FC1C58 /* AuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96D02B24BAE800FC1C58 /* AuthService.swift */; }; EC6B96D12B24BAE800FC1C58 /* AuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96D02B24BAE800FC1C58 /* AuthService.swift */; };
@ -46,10 +45,17 @@
EC7A882D2B28D8A1004F226A /* CreationBetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC7A882C2B28D8A1004F226A /* CreationBetView.swift */; }; EC7A882D2B28D8A1004F226A /* CreationBetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC7A882C2B28D8A1004F226A /* CreationBetView.swift */; };
EC7A882F2B28E6BE004F226A /* ConfidentialityButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC7A882E2B28E6BE004F226A /* ConfidentialityButton.swift */; }; EC7A882F2B28E6BE004F226A /* ConfidentialityButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC7A882E2B28E6BE004F226A /* ConfidentialityButton.swift */; };
EC89F7BD2B250D66003821CE /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC89F7BC2B250D66003821CE /* LoginView.swift */; }; EC89F7BD2B250D66003821CE /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC89F7BC2B250D66003821CE /* LoginView.swift */; };
EC8B9CCE2B42C9D3002806F3 /* StubLib in Frameworks */ = {isa = PBXBuildFile; productRef = EC8B9CCD2B42C9D3002806F3 /* StubLib */; };
ECA9D1C92B2D9ADA0076E0EC /* UserInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA9D1C82B2D9ADA0076E0EC /* UserInfo.swift */; }; ECA9D1C92B2D9ADA0076E0EC /* UserInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA9D1C82B2D9ADA0076E0EC /* UserInfo.swift */; };
ECA9D1CB2B2DA2320076E0EC /* DropDownFriends.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA9D1CA2B2DA2320076E0EC /* DropDownFriends.swift */; }; ECA9D1CB2B2DA2320076E0EC /* DropDownFriends.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA9D1CA2B2DA2320076E0EC /* DropDownFriends.swift */; };
ECB26A132B406A9400FE06B3 /* BetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB26A122B406A9400FE06B3 /* BetViewModel.swift */; };
ECB26A152B406B4800FE06B3 /* ViewModel in Frameworks */ = {isa = PBXBuildFile; productRef = ECB26A142B406B4800FE06B3 /* ViewModel */; };
ECB26A172B4073F100FE06B3 /* CreationBetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB26A162B4073F100FE06B3 /* CreationBetViewModel.swift */; };
ECB26A192B40744F00FE06B3 /* RankingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB26A182B40744F00FE06B3 /* RankingViewModel.swift */; };
ECB26A1B2B40746C00FE06B3 /* FriendsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB26A1A2B40746C00FE06B3 /* FriendsViewModel.swift */; };
ECB357312B3CA69300045D41 /* DependencyInjection.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ECB357302B3CA69300045D41 /* DependencyInjection.framework */; }; ECB357312B3CA69300045D41 /* DependencyInjection.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ECB357302B3CA69300045D41 /* DependencyInjection.framework */; };
ECB357322B3CA69300045D41 /* DependencyInjection.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ECB357302B3CA69300045D41 /* DependencyInjection.framework */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; ECB357322B3CA69300045D41 /* DependencyInjection.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ECB357302B3CA69300045D41 /* DependencyInjection.framework */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
ECB357352B3E13A400045D41 /* Model in Frameworks */ = {isa = PBXBuildFile; productRef = ECB357342B3E13A400045D41 /* Model */; };
ECB7BC682B2F1ADF002A6654 /* LoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */; }; ECB7BC682B2F1ADF002A6654 /* LoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */; };
ECB7BC6A2B2F410A002A6654 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC692B2F410A002A6654 /* AppDelegate.swift */; }; ECB7BC6A2B2F410A002A6654 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC692B2F410A002A6654 /* AppDelegate.swift */; };
ECB7BC6C2B2F43EE002A6654 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC6B2B2F43EE002A6654 /* AppState.swift */; }; ECB7BC6C2B2F43EE002A6654 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC6B2B2F43EE002A6654 /* AppState.swift */; };
@ -120,7 +126,6 @@
EC6B96B22B24B4CC00FC1C58 /* AllInUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AllInUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; EC6B96B22B24B4CC00FC1C58 /* AllInUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AllInUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
EC6B96B62B24B4CC00FC1C58 /* AllInUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllInUITests.swift; sourceTree = "<group>"; }; EC6B96B62B24B4CC00FC1C58 /* AllInUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllInUITests.swift; sourceTree = "<group>"; };
EC6B96B82B24B4CC00FC1C58 /* AllInUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllInUITestsLaunchTests.swift; sourceTree = "<group>"; }; EC6B96B82B24B4CC00FC1C58 /* AllInUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllInUITestsLaunchTests.swift; sourceTree = "<group>"; };
EC6B96C62B24B5A100FC1C58 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAuthService.swift; sourceTree = "<group>"; }; EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAuthService.swift; sourceTree = "<group>"; };
EC6B96CE2B24B8D900FC1C58 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; }; EC6B96CE2B24B8D900FC1C58 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
EC6B96D02B24BAE800FC1C58 /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthService.swift; sourceTree = "<group>"; }; EC6B96D02B24BAE800FC1C58 /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthService.swift; sourceTree = "<group>"; };
@ -132,6 +137,10 @@
EC89F7BC2B250D66003821CE /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; }; EC89F7BC2B250D66003821CE /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
ECA9D1C82B2D9ADA0076E0EC /* UserInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInfo.swift; sourceTree = "<group>"; }; ECA9D1C82B2D9ADA0076E0EC /* UserInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInfo.swift; sourceTree = "<group>"; };
ECA9D1CA2B2DA2320076E0EC /* DropDownFriends.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDownFriends.swift; sourceTree = "<group>"; }; ECA9D1CA2B2DA2320076E0EC /* DropDownFriends.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDownFriends.swift; sourceTree = "<group>"; };
ECB26A122B406A9400FE06B3 /* BetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BetViewModel.swift; sourceTree = "<group>"; };
ECB26A162B4073F100FE06B3 /* CreationBetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreationBetViewModel.swift; sourceTree = "<group>"; };
ECB26A182B40744F00FE06B3 /* RankingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RankingViewModel.swift; sourceTree = "<group>"; };
ECB26A1A2B40746C00FE06B3 /* FriendsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsViewModel.swift; sourceTree = "<group>"; };
ECB3572E2B3CA3C300045D41 /* DependencyInjection.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DependencyInjection.framework; sourceTree = BUILT_PRODUCTS_DIR; }; ECB3572E2B3CA3C300045D41 /* DependencyInjection.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DependencyInjection.framework; sourceTree = BUILT_PRODUCTS_DIR; };
ECB357302B3CA69300045D41 /* DependencyInjection.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DependencyInjection.framework; sourceTree = BUILT_PRODUCTS_DIR; }; ECB357302B3CA69300045D41 /* DependencyInjection.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DependencyInjection.framework; sourceTree = BUILT_PRODUCTS_DIR; };
ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = "<group>"; }; ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = "<group>"; };
@ -145,7 +154,10 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
EC8B9CCE2B42C9D3002806F3 /* StubLib in Frameworks */,
ECB357352B3E13A400045D41 /* Model in Frameworks */,
ECB357312B3CA69300045D41 /* DependencyInjection.framework in Frameworks */, ECB357312B3CA69300045D41 /* DependencyInjection.framework in Frameworks */,
ECB26A152B406B4800FE06B3 /* ViewModel in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -196,14 +208,13 @@
EC6B96D22B24BC4F00FC1C58 /* Extensions */, EC6B96D22B24BC4F00FC1C58 /* Extensions */,
EC6B96CD2B24B8A300FC1C58 /* Ressources */, EC6B96CD2B24B8A300FC1C58 /* Ressources */,
EC6B96CA2B24B7B300FC1C58 /* Services */, EC6B96CA2B24B7B300FC1C58 /* Services */,
EC6B96C52B24B58700FC1C58 /* Models */,
EC6B969B2B24B4CC00FC1C58 /* AllInApp.swift */, EC6B969B2B24B4CC00FC1C58 /* AllInApp.swift */,
EC6B969D2B24B4CC00FC1C58 /* ContentView.swift */, EC6B969D2B24B4CC00FC1C58 /* ContentView.swift */,
EC6B969F2B24B4CC00FC1C58 /* Assets.xcassets */, EC6B969F2B24B4CC00FC1C58 /* Assets.xcassets */,
EC6B96A12B24B4CC00FC1C58 /* Preview Content */,
EC650A612B28CB72003AFCAD /* Launch Screen.storyboard */, EC650A612B28CB72003AFCAD /* Launch Screen.storyboard */,
ECB7BC692B2F410A002A6654 /* AppDelegate.swift */, ECB7BC692B2F410A002A6654 /* AppDelegate.swift */,
ECB7BC6B2B2F43EE002A6654 /* AppState.swift */, ECB7BC6B2B2F43EE002A6654 /* AppState.swift */,
EC6B96A12B24B4CC00FC1C58 /* Preview Content */,
); );
path = AllIn; path = AllIn;
sourceTree = "<group>"; sourceTree = "<group>";
@ -233,14 +244,6 @@
path = AllInUITests; path = AllInUITests;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
EC6B96C52B24B58700FC1C58 /* Models */ = {
isa = PBXGroup;
children = (
EC6B96C62B24B5A100FC1C58 /* User.swift */,
);
path = Models;
sourceTree = "<group>";
};
EC6B96CA2B24B7B300FC1C58 /* Services */ = { EC6B96CA2B24B7B300FC1C58 /* Services */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -322,6 +325,10 @@
children = ( children = (
ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */, ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */,
ECB7BC6F2B336E28002A6654 /* RegisterViewModel.swift */, ECB7BC6F2B336E28002A6654 /* RegisterViewModel.swift */,
ECB26A122B406A9400FE06B3 /* BetViewModel.swift */,
ECB26A162B4073F100FE06B3 /* CreationBetViewModel.swift */,
ECB26A182B40744F00FE06B3 /* RankingViewModel.swift */,
ECB26A1A2B40746C00FE06B3 /* FriendsViewModel.swift */,
); );
path = ViewModels; path = ViewModels;
sourceTree = "<group>"; sourceTree = "<group>";
@ -344,6 +351,9 @@
); );
name = AllIn; name = AllIn;
packageProductDependencies = ( packageProductDependencies = (
ECB357342B3E13A400045D41 /* Model */,
ECB26A142B406B4800FE06B3 /* ViewModel */,
EC8B9CCD2B42C9D3002806F3 /* StubLib */,
); );
productName = AllIn; productName = AllIn;
productReference = EC6B96982B24B4CC00FC1C58 /* AllIn.app */; productReference = EC6B96982B24B4CC00FC1C58 /* AllIn.app */;
@ -463,14 +473,17 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
EC6B96CC2B24B7E500FC1C58 /* IAuthService.swift in Sources */, EC6B96CC2B24B7E500FC1C58 /* IAuthService.swift in Sources */,
ECB26A172B4073F100FE06B3 /* CreationBetViewModel.swift in Sources */,
EC3077092B24CF7F0060E34D /* Colors.swift in Sources */, EC3077092B24CF7F0060E34D /* Colors.swift in Sources */,
ECB7BC6A2B2F410A002A6654 /* AppDelegate.swift in Sources */, ECB7BC6A2B2F410A002A6654 /* AppDelegate.swift in Sources */,
EC6B969E2B24B4CC00FC1C58 /* ContentView.swift in Sources */, EC6B969E2B24B4CC00FC1C58 /* ContentView.swift in Sources */,
EC89F7BD2B250D66003821CE /* LoginView.swift in Sources */, EC89F7BD2B250D66003821CE /* LoginView.swift in Sources */,
EC650A442B25CDF3003AFCAD /* ParameterMenu.swift in Sources */, EC650A442B25CDF3003AFCAD /* ParameterMenu.swift in Sources */,
ECB26A132B406A9400FE06B3 /* BetViewModel.swift in Sources */,
EC30770F2B24FCB00060E34D /* RegisterView.swift in Sources */, EC30770F2B24FCB00060E34D /* RegisterView.swift in Sources */,
EC650A522B2794DD003AFCAD /* BetView.swift in Sources */, EC650A522B2794DD003AFCAD /* BetView.swift in Sources */,
EC6B969C2B24B4CC00FC1C58 /* AllInApp.swift in Sources */, EC6B969C2B24B4CC00FC1C58 /* AllInApp.swift in Sources */,
ECB26A192B40744F00FE06B3 /* RankingViewModel.swift in Sources */,
EC650A502B2793D5003AFCAD /* TextCapsule.swift in Sources */, EC650A502B2793D5003AFCAD /* TextCapsule.swift in Sources */,
EC650A482B25DCFF003AFCAD /* UsersPreview.swift in Sources */, EC650A482B25DCFF003AFCAD /* UsersPreview.swift in Sources */,
EC650A462B25D686003AFCAD /* RankingRow.swift in Sources */, EC650A462B25D686003AFCAD /* RankingRow.swift in Sources */,
@ -480,7 +493,6 @@
ECB7BC702B336E28002A6654 /* RegisterViewModel.swift in Sources */, ECB7BC702B336E28002A6654 /* RegisterViewModel.swift in Sources */,
EC650A4C2B25E9C7003AFCAD /* RankingView.swift in Sources */, EC650A4C2B25E9C7003AFCAD /* RankingView.swift in Sources */,
EC7A882B2B28D1E0004F226A /* DropDownMenu.swift in Sources */, EC7A882B2B28D1E0004F226A /* DropDownMenu.swift in Sources */,
EC6B96C72B24B5A100FC1C58 /* User.swift in Sources */,
EC7A882D2B28D8A1004F226A /* CreationBetView.swift in Sources */, EC7A882D2B28D8A1004F226A /* CreationBetView.swift in Sources */,
EC6B96CF2B24B8D900FC1C58 /* Config.swift in Sources */, EC6B96CF2B24B8D900FC1C58 /* Config.swift in Sources */,
EC30770B2B24D9160060E34D /* WelcomeView.swift in Sources */, EC30770B2B24D9160060E34D /* WelcomeView.swift in Sources */,
@ -492,6 +504,7 @@
EC3077072B24CB840060E34D /* SplashView.swift in Sources */, EC3077072B24CB840060E34D /* SplashView.swift in Sources */,
EC01937E2B25C52E005D81E6 /* TopBar.swift in Sources */, EC01937E2B25C52E005D81E6 /* TopBar.swift in Sources */,
ECA9D1CB2B2DA2320076E0EC /* DropDownFriends.swift in Sources */, ECA9D1CB2B2DA2320076E0EC /* DropDownFriends.swift in Sources */,
ECB26A1B2B40746C00FE06B3 /* FriendsViewModel.swift in Sources */,
ECB7BC682B2F1ADF002A6654 /* LoginViewModel.swift in Sources */, ECB7BC682B2F1ADF002A6654 /* LoginViewModel.swift in Sources */,
EC6B96D52B24BE0E00FC1C58 /* MainView.swift in Sources */, EC6B96D52B24BE0E00FC1C58 /* MainView.swift in Sources */,
EC650A562B279D68003AFCAD /* WinModal.swift in Sources */, EC650A562B279D68003AFCAD /* WinModal.swift in Sources */,
@ -825,6 +838,21 @@
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
/* End XCConfigurationList section */ /* End XCConfigurationList section */
/* Begin XCSwiftPackageProductDependency section */
EC8B9CCD2B42C9D3002806F3 /* StubLib */ = {
isa = XCSwiftPackageProductDependency;
productName = StubLib;
};
ECB26A142B406B4800FE06B3 /* ViewModel */ = {
isa = XCSwiftPackageProductDependency;
productName = ViewModel;
};
ECB357342B3E13A400045D41 /* Model */ = {
isa = XCSwiftPackageProductDependency;
productName = Model;
};
/* End XCSwiftPackageProductDependency section */
}; };
rootObject = EC6B96902B24B4CC00FC1C58 /* Project object */; rootObject = EC6B96902B24B4CC00FC1C58 /* Project object */;
} }

@ -10,43 +10,26 @@ import XCTest
final class AllInTests: XCTestCase { final class AllInTests: XCTestCase {
func testInstance() { override func setUpWithError() throws {
DependencyInjection.shared.addSingleton(UserTest.self, UserTest(age: 10)) // Put setup code here. This method is called before the invocation of each test method in the class.
let view1 = View1()
let view2 = View2()
XCTAssertEqual(view1.getAge(), view2.getAge())
view1.setAge()
XCTAssertEqual(view1.getAge(), view2.getAge())
view2.setAge()
XCTAssertEqual(view1.getAge(), view2.getAge())
} }
class UserTest { override func tearDownWithError() throws {
public var age:Int // Put teardown code here. This method is called after the invocation of each test method in the class.
init(age:Int) {
self.age = age
}
} }
class View1 { func testExample() throws {
@Inject private var user:UserTest // This is an example of a functional test case.
func getAge() -> Int { // Use XCTAssert and related functions to verify your tests produce the correct results.
return user.age // Any test you write for XCTest can be annotated as throws and async.
} // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
func setAge() { // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
user.age = 20
}
} }
class View2 { func testPerformanceExample() throws {
@Inject private var user:UserTest // This is an example of a performance test case.
func getAge() -> Int { self.measure {
return user.age // Put the code you want to measure the time of here.
}
func setAge() {
user.age = 40
} }
} }

@ -33,4 +33,44 @@ class DependencyInjectionTests: XCTestCase {
} }
} }
func testInstance() {
DependencyInjection.shared.addSingleton(UserTest.self, UserTest(age: 10))
let view1 = View1()
let view2 = View2()
XCTAssertEqual(view1.getAge(), view2.getAge())
view1.setAge()
XCTAssertEqual(view1.getAge(), view2.getAge())
view2.setAge()
XCTAssertEqual(view1.getAge(), view2.getAge())
}
class UserTest {
public var age:Int
init(age:Int) {
self.age = age
}
}
class View1 {
@Inject private var user:UserTest
func getAge() -> Int {
return user.age
}
func setAge() {
user.age = 20
}
}
class View2 {
@Inject private var user:UserTest
func getAge() -> Int {
return user.age
}
func setAge() {
user.age = 40
}
}
} }

@ -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…
Cancel
Save