diff --git a/Sources/AllIn.xcworkspace/contents.xcworkspacedata b/Sources/AllIn.xcworkspace/contents.xcworkspacedata
index 2a84f3c..d92865d 100644
--- a/Sources/AllIn.xcworkspace/contents.xcworkspacedata
+++ b/Sources/AllIn.xcworkspace/contents.xcworkspacedata
@@ -2,12 +2,18 @@
+ location = "group:AllInApp/AllInApp.xcodeproj">
+ location = "group:StubLib">
+ location = "group:ViewModel">
+
+
+
+
diff --git a/Sources/AllInApp/AllIn/AllInApp.swift b/Sources/AllInApp/AllIn/AllInApp.swift
index 8843e72..910f49f 100644
--- a/Sources/AllInApp/AllIn/AllInApp.swift
+++ b/Sources/AllInApp/AllIn/AllInApp.swift
@@ -7,6 +7,9 @@
import SwiftUI
import DependencyInjection
+import Model
+import ViewModel
+import StubLib
@main
struct AllInApp: App {
@@ -16,6 +19,7 @@ struct AllInApp: App {
init() {
DI.addSingleton(IAuthService.self, AuthService())
+ DI.addSingleton(ManagerVM.self, ManagerVM(withModel: Manager(withBetDataManager: BetStubManager(), withUserDataManager: UserStubManager(username: "Imri"))))
}
var body: some Scene {
diff --git a/Sources/AllInApp/AllIn/AppState.swift b/Sources/AllInApp/AllIn/AppState.swift
index 5713c35..d2d6693 100644
--- a/Sources/AllInApp/AllIn/AppState.swift
+++ b/Sources/AllInApp/AllIn/AppState.swift
@@ -6,11 +6,13 @@
//
import SwiftUI
+import Model
class AppStateContainer: ObservableObject {
static let shared = AppStateContainer()
let loggedState: LoggedState = LoggedState()
var onlineStatus: OnlineStatus = OnlineStatus()
+ var user: User?
@AppStorage("authenticationRefresh") var authenticationRefresh: String?
}
diff --git a/Sources/AllInApp/AllIn/Components/AllcoinsCounter.swift b/Sources/AllInApp/AllIn/Components/AllcoinsCounter.swift
index d7b1115..eb21bd1 100644
--- a/Sources/AllInApp/AllIn/Components/AllcoinsCounter.swift
+++ b/Sources/AllInApp/AllIn/Components/AllcoinsCounter.swift
@@ -13,7 +13,7 @@ struct AllcoinsCounter: View {
Image("allcoinIcon")
.resizable()
.frame(width: 17, height: 17, alignment: .leading)
- Text("541")
+ Text(String(AppStateContainer.shared.user?.nbCoins ?? 0))
.fontWeight(.black)
.foregroundColor(AllInColors.primaryColor)
}
diff --git a/Sources/AllInApp/AllIn/Components/Menu.swift b/Sources/AllInApp/AllIn/Components/Menu.swift
index 7ffd148..c2b0d1b 100644
--- a/Sources/AllInApp/AllIn/Components/Menu.swift
+++ b/Sources/AllInApp/AllIn/Components/Menu.swift
@@ -19,7 +19,7 @@ struct Menu: View {
.scaledToFit()
.frame(width: 100, height: 100)
.cornerRadius(180)
- Text("Pseudo")
+ Text(AppStateContainer.shared.user?.username.capitalized ?? "")
.fontWeight(.medium)
.font(.system(size: 17))
.foregroundColor(.white)
diff --git a/Sources/AllInApp/AllIn/ContentView.swift b/Sources/AllInApp/AllIn/ContentView.swift
index 75d6bb9..29d03fc 100644
--- a/Sources/AllInApp/AllIn/ContentView.swift
+++ b/Sources/AllInApp/AllIn/ContentView.swift
@@ -15,17 +15,20 @@ struct ContentView: View {
var body: some View {
VStack {
- NavigationView {
- if loggedState.connectedUser {
+ if loggedState.connectedUser {
+ NavigationView {
MainView(page: "Bet")
- } else {
+ }
+ .navigationViewStyle(StackNavigationViewStyle())
+ } else {
+ NavigationView {
WelcomeView()
}
+ .navigationViewStyle(StackNavigationViewStyle())
}
- .navigationViewStyle(StackNavigationViewStyle())
}
.onAppear {
- //authService.refreshAuthentication() { status in }
+ authService.refreshAuthentication()
}
}
}
diff --git a/Sources/AllInApp/AllIn/Models/User.swift b/Sources/AllInApp/AllIn/Models/User.swift
deleted file mode 100644
index d0cfac8..0000000
--- a/Sources/AllInApp/AllIn/Models/User.swift
+++ /dev/null
@@ -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
- }
-}
diff --git a/Sources/AllInApp/AllIn/Services/AuthService.swift b/Sources/AllInApp/AllIn/Services/AuthService.swift
index da682fa..7f22be8 100644
--- a/Sources/AllInApp/AllIn/Services/AuthService.swift
+++ b/Sources/AllInApp/AllIn/Services/AuthService.swift
@@ -6,6 +6,7 @@
//
import Foundation
+import Model
class AuthService: IAuthService {
@@ -30,9 +31,14 @@ class AuthService: IAuthService {
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)
}
}.resume()
@@ -56,19 +62,33 @@ class AuthService: IAuthService {
URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in
print ("ALLIN : Process REGISTER")
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)
}
}.resume()
}
}
- func refreshAuthentication(completion: @escaping (Int) -> ()) {
+ func refreshAuthentication() {
guard let token = AppStateContainer.shared.authenticationRefresh else {
- completion(401)
return
}
+ print(token)
+
let url = URL(string: Config.allInApi + "users/token")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
@@ -76,13 +96,45 @@ class AuthService: IAuthService {
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
URLSession.shared.dataTask(with: request) { data, response, error in
- if let httpResponse = response as? HTTPURLResponse {
- completion(httpResponse.statusCode)
+ if let data = data,
+ let httpResponse = response as? HTTPURLResponse {
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) {
+ 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")!
+ 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) {
+ completion(httpResponse.statusCode)
+ AppStateContainer.shared.user = user
+ }
+ } else {
+ completion(httpResponse.statusCode)
+ }
+ } else {
+ completion(500)
+ }
+ }.resume()
+ }
+
+
}
diff --git a/Sources/AllInApp/AllIn/Services/IAuthService.swift b/Sources/AllInApp/AllIn/Services/IAuthService.swift
index b9d8b50..cafd070 100644
--- a/Sources/AllInApp/AllIn/Services/IAuthService.swift
+++ b/Sources/AllInApp/AllIn/Services/IAuthService.swift
@@ -10,5 +10,5 @@ import Foundation
protocol IAuthService {
func login(login: String, password: String, completion : @escaping (Int)-> ())
func register(username: String, email: String, password: String, completion : @escaping (Int)-> ())
- func refreshAuthentication(completion: @escaping (Int) -> ())
+ func refreshAuthentication()
}
diff --git a/Sources/AllInApp/AllIn/ViewModels/BetViewModel.swift b/Sources/AllInApp/AllIn/ViewModels/BetViewModel.swift
new file mode 100644
index 0000000..522af33
--- /dev/null
+++ b/Sources/AllInApp/AllIn/ViewModels/BetViewModel.swift
@@ -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) {
+
+ }
+}
diff --git a/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift b/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift
new file mode 100644
index 0000000..f5818cc
--- /dev/null
+++ b/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift
@@ -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
+ }
+ }
+}
diff --git a/Sources/AllInApp/AllIn/ViewModels/FriendsViewModel.swift b/Sources/AllInApp/AllIn/ViewModels/FriendsViewModel.swift
new file mode 100644
index 0000000..a98dfbf
--- /dev/null
+++ b/Sources/AllInApp/AllIn/ViewModels/FriendsViewModel.swift
@@ -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) {
+
+ }
+}
diff --git a/Sources/AllInApp/AllIn/ViewModels/RankingViewModel.swift b/Sources/AllInApp/AllIn/ViewModels/RankingViewModel.swift
new file mode 100644
index 0000000..d9bfcbd
--- /dev/null
+++ b/Sources/AllInApp/AllIn/ViewModels/RankingViewModel.swift
@@ -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) {
+
+ }
+}
diff --git a/Sources/AllInApp/AllIn/Views/BetView.swift b/Sources/AllInApp/AllIn/Views/BetView.swift
index 9e09671..1ef638f 100644
--- a/Sources/AllInApp/AllIn/Views/BetView.swift
+++ b/Sources/AllInApp/AllIn/Views/BetView.swift
@@ -9,6 +9,7 @@ import SwiftUI
struct BetView: View {
+ @StateObject private var viewModel = BetViewModel()
@Binding var showMenu: Bool
@State private var showingSheet = false
diff --git a/Sources/AllInApp/AllIn/Views/CreationBetView.swift b/Sources/AllInApp/AllIn/Views/CreationBetView.swift
index d350926..68ae1e0 100644
--- a/Sources/AllInApp/AllIn/Views/CreationBetView.swift
+++ b/Sources/AllInApp/AllIn/Views/CreationBetView.swift
@@ -9,26 +9,25 @@ import SwiftUI
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 showDescriptionPopover: Bool = false
@State private var showRegistrationEndDatePopover: Bool = false
@State private var showBetEndDatePopover: 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 = {
let calendar = Calendar.current
let startDate = Date()
let endDate = calendar.date(byAdding: .year, value: 10, to: startDate)!
return startDate ... endDate
}()
+ let screenWidth = UIScreen.main.bounds.width
+
@State private var response = ""
@State private var values: [String] = []
@@ -40,8 +39,7 @@ struct CreationBetView: View {
]
@State var groupedItems: [[String]] = [[String]] ()
- let screenWidth = UIScreen.main.bounds.width
-
+
private func updateGroupedItems() {
var updatedGroupedItems: [[String]] = [[String]] ()
@@ -99,7 +97,7 @@ struct CreationBetView: View {
.frame(width: 340)
.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)
.font(.system(size: 14))
.fontWeight(.light))
@@ -134,7 +132,7 @@ struct CreationBetView: View {
.frame(width: 340)
.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)
.font(.system(size: 14))
.fontWeight(.light), axis: .vertical)
@@ -171,7 +169,7 @@ struct CreationBetView: View {
HStack(spacing: 5) {
DatePicker(
"",
- selection: $endRegisterDate,
+ selection: $viewModel.endRegisterDate,
in: dateRange,
displayedComponents: [.date, .hourAndMinute]
)
@@ -201,7 +199,7 @@ struct CreationBetView: View {
}
DatePicker(
"",
- selection: $endBetDate,
+ selection: $viewModel.endBetDate,
in: dateRange,
displayedComponents: [.date, .hourAndMinute]
)
@@ -227,15 +225,15 @@ struct CreationBetView: View {
.padding(.leading, 10)
HStack(spacing: 5) {
- ConfidentialityButton(image: "globe", text: "Public", selected: !selectedConfidentiality)
+ ConfidentialityButton(image: "globe", text: "Public", selected: viewModel.isPublic)
.onTapGesture {
- selectedConfidentiality = false
+ viewModel.isPublic = true
}
.padding(.trailing, 5)
- ConfidentialityButton(image: "lock", text: "Privé", selected: selectedConfidentiality)
+ ConfidentialityButton(image: "lock", text: "Privé", selected: !viewModel.isPublic)
.onTapGesture {
- selectedConfidentiality = true
+ viewModel.isPublic = false
}
Spacer()
}
@@ -243,10 +241,10 @@ struct CreationBetView: View {
.frame(width: 340)
.padding(.bottom, 10)
-
+
VStack(spacing: 10) {
- if self.selectedConfidentiality {
+ if !self.viewModel.isPublic {
DropDownFriends()
.padding(.bottom, 30)
}
@@ -277,7 +275,9 @@ struct CreationBetView: View {
Spacer()
HStack() {
Spacer()
- Button(action: {}) {
+ Button(action: {
+ viewModel.create()
+ }) {
Text("Publier le bet")
.font(.system(size: 24))
.fontWeight(.bold)
diff --git a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj
index 72c1896..c72f194 100644
--- a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj
+++ b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj
@@ -36,7 +36,6 @@
EC6B96AD2B24B4CC00FC1C58 /* AllInTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96AC2B24B4CC00FC1C58 /* AllInTests.swift */; };
EC6B96B72B24B4CC00FC1C58 /* AllInUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96B62B24B4CC00FC1C58 /* AllInUITests.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 */; };
EC6B96CF2B24B8D900FC1C58 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96CE2B24B8D900FC1C58 /* Config.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 */; };
EC7A882F2B28E6BE004F226A /* ConfidentialityButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC7A882E2B28E6BE004F226A /* ConfidentialityButton.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 */; };
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 */; };
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 */; };
ECB7BC6A2B2F410A002A6654 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC692B2F410A002A6654 /* AppDelegate.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; };
EC6B96B62B24B4CC00FC1C58 /* AllInUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllInUITests.swift; sourceTree = ""; };
EC6B96B82B24B4CC00FC1C58 /* AllInUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllInUITestsLaunchTests.swift; sourceTree = ""; };
- EC6B96C62B24B5A100FC1C58 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; };
EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAuthService.swift; sourceTree = ""; };
EC6B96CE2B24B8D900FC1C58 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = ""; };
EC6B96D02B24BAE800FC1C58 /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthService.swift; sourceTree = ""; };
@@ -132,6 +137,10 @@
EC89F7BC2B250D66003821CE /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = ""; };
ECA9D1C82B2D9ADA0076E0EC /* UserInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInfo.swift; sourceTree = ""; };
ECA9D1CA2B2DA2320076E0EC /* DropDownFriends.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDownFriends.swift; sourceTree = ""; };
+ ECB26A122B406A9400FE06B3 /* BetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BetViewModel.swift; sourceTree = ""; };
+ ECB26A162B4073F100FE06B3 /* CreationBetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreationBetViewModel.swift; sourceTree = ""; };
+ ECB26A182B40744F00FE06B3 /* RankingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RankingViewModel.swift; sourceTree = ""; };
+ ECB26A1A2B40746C00FE06B3 /* FriendsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsViewModel.swift; sourceTree = ""; };
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; };
ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = ""; };
@@ -145,7 +154,10 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ EC8B9CCE2B42C9D3002806F3 /* StubLib in Frameworks */,
+ ECB357352B3E13A400045D41 /* Model in Frameworks */,
ECB357312B3CA69300045D41 /* DependencyInjection.framework in Frameworks */,
+ ECB26A152B406B4800FE06B3 /* ViewModel in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -196,14 +208,13 @@
EC6B96D22B24BC4F00FC1C58 /* Extensions */,
EC6B96CD2B24B8A300FC1C58 /* Ressources */,
EC6B96CA2B24B7B300FC1C58 /* Services */,
- EC6B96C52B24B58700FC1C58 /* Models */,
EC6B969B2B24B4CC00FC1C58 /* AllInApp.swift */,
EC6B969D2B24B4CC00FC1C58 /* ContentView.swift */,
EC6B969F2B24B4CC00FC1C58 /* Assets.xcassets */,
- EC6B96A12B24B4CC00FC1C58 /* Preview Content */,
EC650A612B28CB72003AFCAD /* Launch Screen.storyboard */,
ECB7BC692B2F410A002A6654 /* AppDelegate.swift */,
ECB7BC6B2B2F43EE002A6654 /* AppState.swift */,
+ EC6B96A12B24B4CC00FC1C58 /* Preview Content */,
);
path = AllIn;
sourceTree = "";
@@ -233,14 +244,6 @@
path = AllInUITests;
sourceTree = "";
};
- EC6B96C52B24B58700FC1C58 /* Models */ = {
- isa = PBXGroup;
- children = (
- EC6B96C62B24B5A100FC1C58 /* User.swift */,
- );
- path = Models;
- sourceTree = "";
- };
EC6B96CA2B24B7B300FC1C58 /* Services */ = {
isa = PBXGroup;
children = (
@@ -322,6 +325,10 @@
children = (
ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */,
ECB7BC6F2B336E28002A6654 /* RegisterViewModel.swift */,
+ ECB26A122B406A9400FE06B3 /* BetViewModel.swift */,
+ ECB26A162B4073F100FE06B3 /* CreationBetViewModel.swift */,
+ ECB26A182B40744F00FE06B3 /* RankingViewModel.swift */,
+ ECB26A1A2B40746C00FE06B3 /* FriendsViewModel.swift */,
);
path = ViewModels;
sourceTree = "";
@@ -344,6 +351,9 @@
);
name = AllIn;
packageProductDependencies = (
+ ECB357342B3E13A400045D41 /* Model */,
+ ECB26A142B406B4800FE06B3 /* ViewModel */,
+ EC8B9CCD2B42C9D3002806F3 /* StubLib */,
);
productName = AllIn;
productReference = EC6B96982B24B4CC00FC1C58 /* AllIn.app */;
@@ -463,14 +473,17 @@
buildActionMask = 2147483647;
files = (
EC6B96CC2B24B7E500FC1C58 /* IAuthService.swift in Sources */,
+ ECB26A172B4073F100FE06B3 /* CreationBetViewModel.swift in Sources */,
EC3077092B24CF7F0060E34D /* Colors.swift in Sources */,
ECB7BC6A2B2F410A002A6654 /* AppDelegate.swift in Sources */,
EC6B969E2B24B4CC00FC1C58 /* ContentView.swift in Sources */,
EC89F7BD2B250D66003821CE /* LoginView.swift in Sources */,
EC650A442B25CDF3003AFCAD /* ParameterMenu.swift in Sources */,
+ ECB26A132B406A9400FE06B3 /* BetViewModel.swift in Sources */,
EC30770F2B24FCB00060E34D /* RegisterView.swift in Sources */,
EC650A522B2794DD003AFCAD /* BetView.swift in Sources */,
EC6B969C2B24B4CC00FC1C58 /* AllInApp.swift in Sources */,
+ ECB26A192B40744F00FE06B3 /* RankingViewModel.swift in Sources */,
EC650A502B2793D5003AFCAD /* TextCapsule.swift in Sources */,
EC650A482B25DCFF003AFCAD /* UsersPreview.swift in Sources */,
EC650A462B25D686003AFCAD /* RankingRow.swift in Sources */,
@@ -480,7 +493,6 @@
ECB7BC702B336E28002A6654 /* RegisterViewModel.swift in Sources */,
EC650A4C2B25E9C7003AFCAD /* RankingView.swift in Sources */,
EC7A882B2B28D1E0004F226A /* DropDownMenu.swift in Sources */,
- EC6B96C72B24B5A100FC1C58 /* User.swift in Sources */,
EC7A882D2B28D8A1004F226A /* CreationBetView.swift in Sources */,
EC6B96CF2B24B8D900FC1C58 /* Config.swift in Sources */,
EC30770B2B24D9160060E34D /* WelcomeView.swift in Sources */,
@@ -492,6 +504,7 @@
EC3077072B24CB840060E34D /* SplashView.swift in Sources */,
EC01937E2B25C52E005D81E6 /* TopBar.swift in Sources */,
ECA9D1CB2B2DA2320076E0EC /* DropDownFriends.swift in Sources */,
+ ECB26A1B2B40746C00FE06B3 /* FriendsViewModel.swift in Sources */,
ECB7BC682B2F1ADF002A6654 /* LoginViewModel.swift in Sources */,
EC6B96D52B24BE0E00FC1C58 /* MainView.swift in Sources */,
EC650A562B279D68003AFCAD /* WinModal.swift in Sources */,
@@ -825,6 +838,21 @@
defaultConfigurationName = Release;
};
/* 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 */;
}
diff --git a/Sources/AllInApp/AllInTests/AllInTests.swift b/Sources/AllInApp/AllInTests/AllInTests.swift
index b8bfa77..72e24f1 100644
--- a/Sources/AllInApp/AllInTests/AllInTests.swift
+++ b/Sources/AllInApp/AllInTests/AllInTests.swift
@@ -10,43 +10,26 @@ import XCTest
final class AllInTests: 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())
+ override func setUpWithError() throws {
+ // Put setup code here. This method is called before the invocation of each test method in the class.
}
-
- class UserTest {
- public var age:Int
- init(age:Int) {
- self.age = age
- }
+
+ override func tearDownWithError() throws {
+ // Put teardown code here. This method is called after the invocation of each test method in the class.
}
-
- class View1 {
- @Inject private var user:UserTest
- func getAge() -> Int {
- return user.age
- }
- func setAge() {
- user.age = 20
- }
+
+ 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.
+ // 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.
+ // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}
-
- class View2 {
- @Inject private var user:UserTest
- func getAge() -> Int {
- return user.age
- }
- func setAge() {
- user.age = 40
+
+ func testPerformanceExample() throws {
+ // This is an example of a performance test case.
+ self.measure {
+ // Put the code you want to measure the time of here.
}
}
diff --git a/Sources/DependencyInjection/DependencyInjectionTests/DependencyInjectionTests.swift b/Sources/DependencyInjection/DependencyInjectionTests/DependencyInjectionTests.swift
index 519ba73..44e638e 100644
--- a/Sources/DependencyInjection/DependencyInjectionTests/DependencyInjectionTests.swift
+++ b/Sources/DependencyInjection/DependencyInjectionTests/DependencyInjectionTests.swift
@@ -32,5 +32,45 @@ class DependencyInjectionTests: XCTestCase {
// Put the code you want to measure the time of here.
}
}
+
+ 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
+ }
+ }
}
diff --git a/Sources/Model/Sources/Model/Bet.swift b/Sources/Model/Sources/Model/Bet.swift
new file mode 100644
index 0000000..c021ac9
--- /dev/null
+++ b/Sources/Model/Sources/Model/Bet.swift
@@ -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 }
+
+}
diff --git a/Sources/Model/Sources/Model/BetDataManager.swift b/Sources/Model/Sources/Model/BetDataManager.swift
new file mode 100644
index 0000000..4c3c51b
--- /dev/null
+++ b/Sources/Model/Sources/Model/BetDataManager.swift
@@ -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]
+}
diff --git a/Sources/Model/Sources/Model/BinaryBet.swift b/Sources/Model/Sources/Model/BinaryBet.swift
new file mode 100644
index 0000000..ad107cb
--- /dev/null
+++ b/Sources/Model/Sources/Model/BinaryBet.swift
@@ -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
+ }
+
+}
diff --git a/Sources/Model/Sources/Model/BinaryParticipation.swift b/Sources/Model/Sources/Model/BinaryParticipation.swift
new file mode 100644
index 0000000..33f391c
--- /dev/null
+++ b/Sources/Model/Sources/Model/BinaryParticipation.swift
@@ -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
+
+}
diff --git a/Sources/Model/Sources/Model/CustomBet.swift b/Sources/Model/Sources/Model/CustomBet.swift
new file mode 100644
index 0000000..10f1e92
--- /dev/null
+++ b/Sources/Model/Sources/Model/CustomBet.swift
@@ -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]
+
+}
diff --git a/Sources/Model/Sources/Model/CustomBetResponse.swift b/Sources/Model/Sources/Model/CustomBetResponse.swift
new file mode 100644
index 0000000..081ccdc
--- /dev/null
+++ b/Sources/Model/Sources/Model/CustomBetResponse.swift
@@ -0,0 +1,13 @@
+//
+// CustomBetResponse.swift
+//
+//
+// Created by Emre on 28/12/2023.
+//
+
+import Foundation
+
+public struct CustomBetResponse {
+ public var name: String
+
+}
diff --git a/Sources/Model/Sources/Model/CustomParticipation.swift b/Sources/Model/Sources/Model/CustomParticipation.swift
new file mode 100644
index 0000000..56ab055
--- /dev/null
+++ b/Sources/Model/Sources/Model/CustomParticipation.swift
@@ -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
+
+}
diff --git a/Sources/Model/Sources/Model/Manager.swift b/Sources/Model/Sources/Model/Manager.swift
new file mode 100644
index 0000000..2463e97
--- /dev/null
+++ b/Sources/Model/Sources/Model/Manager.swift
@@ -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
+ }
+
+}
diff --git a/Sources/Model/Sources/Model/MatchBet.swift b/Sources/Model/Sources/Model/MatchBet.swift
new file mode 100644
index 0000000..4d98567
--- /dev/null
+++ b/Sources/Model/Sources/Model/MatchBet.swift
@@ -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
+
+}
diff --git a/Sources/Model/Sources/Model/MatchParticipation.swift b/Sources/Model/Sources/Model/MatchParticipation.swift
new file mode 100644
index 0000000..cd1747e
--- /dev/null
+++ b/Sources/Model/Sources/Model/MatchParticipation.swift
@@ -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
+
+}
diff --git a/Sources/Model/Sources/Model/Model.swift b/Sources/Model/Sources/Model/Model.swift
deleted file mode 100644
index c88e2a8..0000000
--- a/Sources/Model/Sources/Model/Model.swift
+++ /dev/null
@@ -1,6 +0,0 @@
-public struct Model {
- public private(set) var text = "Hello, World!"
-
- public init() {
- }
-}
diff --git a/Sources/Model/Sources/Model/Participation.swift b/Sources/Model/Sources/Model/Participation.swift
new file mode 100644
index 0000000..6067ac4
--- /dev/null
+++ b/Sources/Model/Sources/Model/Participation.swift
@@ -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 }
+
+}
diff --git a/Sources/Model/Sources/Model/User.swift b/Sources/Model/Sources/Model/User.swift
new file mode 100644
index 0000000..784902f
--- /dev/null
+++ b/Sources/Model/Sources/Model/User.swift
@@ -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: [])
+ }
+}
diff --git a/Sources/Model/Sources/Model/UserDataManager.swift b/Sources/Model/Sources/Model/UserDataManager.swift
new file mode 100644
index 0000000..584add7
--- /dev/null
+++ b/Sources/Model/Sources/Model/UserDataManager.swift
@@ -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]
+}
diff --git a/Sources/Model/Tests/ModelTests/ModelTests.swift b/Sources/Model/Tests/ModelTests/ModelTests.swift
deleted file mode 100644
index 38c36bb..0000000
--- a/Sources/Model/Tests/ModelTests/ModelTests.swift
+++ /dev/null
@@ -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!")
- }
-}
diff --git a/Sources/StubLib/Package.swift b/Sources/StubLib/Package.swift
new file mode 100644
index 0000000..a8abfb8
--- /dev/null
+++ b/Sources/StubLib/Package.swift
@@ -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"]),
+ ]
+)
diff --git a/Sources/StubLib/README.md b/Sources/StubLib/README.md
new file mode 100644
index 0000000..9f7060e
--- /dev/null
+++ b/Sources/StubLib/README.md
@@ -0,0 +1,3 @@
+# StubLib
+
+A description of this package.
diff --git a/Sources/StubLib/Sources/StubLib/BetStubManager.swift b/Sources/StubLib/Sources/StubLib/BetStubManager.swift
new file mode 100644
index 0000000..b2bf7e1
--- /dev/null
+++ b/Sources/StubLib/Sources/StubLib/BetStubManager.swift
@@ -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)
+ }
+ }
+
+}
diff --git a/Sources/StubLib/Sources/StubLib/Stub.swift b/Sources/StubLib/Sources/StubLib/Stub.swift
new file mode 100644
index 0000000..c5d7e04
--- /dev/null
+++ b/Sources/StubLib/Sources/StubLib/Stub.swift
@@ -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)
+ }
+}
diff --git a/Sources/StubLib/Sources/StubLib/UserStubManager.swift b/Sources/StubLib/Sources/StubLib/UserStubManager.swift
new file mode 100644
index 0000000..a2f8b07
--- /dev/null
+++ b/Sources/StubLib/Sources/StubLib/UserStubManager.swift
@@ -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
+ }
+ }
+ }
+}
diff --git a/Sources/ViewModel/.gitignore b/Sources/ViewModel/.gitignore
new file mode 100644
index 0000000..3b29812
--- /dev/null
+++ b/Sources/ViewModel/.gitignore
@@ -0,0 +1,9 @@
+.DS_Store
+/.build
+/Packages
+/*.xcodeproj
+xcuserdata/
+DerivedData/
+.swiftpm/config/registries.json
+.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
+.netrc
diff --git a/Sources/ViewModel/Package.swift b/Sources/ViewModel/Package.swift
new file mode 100644
index 0000000..e1b79e7
--- /dev/null
+++ b/Sources/ViewModel/Package.swift
@@ -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"]),
+ ]
+)
diff --git a/Sources/ViewModel/README.md b/Sources/ViewModel/README.md
new file mode 100644
index 0000000..74e3704
--- /dev/null
+++ b/Sources/ViewModel/README.md
@@ -0,0 +1,3 @@
+# ViewModel
+
+A description of this package.
diff --git a/Sources/ViewModel/Sources/ViewModel/ManagerVM.swift b/Sources/ViewModel/Sources/ViewModel/ManagerVM.swift
new file mode 100644
index 0000000..91c1245
--- /dev/null
+++ b/Sources/ViewModel/Sources/ViewModel/ManagerVM.swift
@@ -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() {
+
+ }
+}