From d5a9c75efbfff4f20d512504b1b36b5166332b04 Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Wed, 27 Dec 2023 19:44:26 +0100 Subject: [PATCH 1/5] Add a framework projet for the DI --- .../contents.xcworkspacedata | 3 + Sources/AllInApp/AllIn/AllInApp.swift | 1 + Sources/AllInApp/AllIn/ContentView.swift | 1 + .../AllIn/ViewModels/LoginViewModel.swift | 1 + .../AllIn/ViewModels/RegisterViewModel.swift | 1 + .../AllInApp.xcodeproj/project.pbxproj | 34 +- .../project.pbxproj | 486 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../DependencyInjection.md | 13 + .../DependencyInjection/DependencyInjection.h | 18 + .../DependencyInjection.swift} | 20 +- .../DependencyInjectionTests.swift | 36 ++ 13 files changed, 615 insertions(+), 14 deletions(-) create mode 100644 Sources/DependencyInjection/DependencyInjection.xcodeproj/project.pbxproj create mode 100644 Sources/DependencyInjection/DependencyInjection.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Sources/DependencyInjection/DependencyInjection.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100755 Sources/DependencyInjection/DependencyInjection/DependencyInjection.docc/DependencyInjection.md create mode 100644 Sources/DependencyInjection/DependencyInjection/DependencyInjection.h rename Sources/{AllInApp/AllIn/Models/DependancyInjection.swift => DependencyInjection/DependencyInjection/DependencyInjection.swift} (68%) create mode 100644 Sources/DependencyInjection/DependencyInjectionTests/DependencyInjectionTests.swift diff --git a/Sources/AllIn.xcworkspace/contents.xcworkspacedata b/Sources/AllIn.xcworkspace/contents.xcworkspacedata index 63d1fa8..2a84f3c 100644 --- a/Sources/AllIn.xcworkspace/contents.xcworkspacedata +++ b/Sources/AllIn.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + diff --git a/Sources/AllInApp/AllIn/AllInApp.swift b/Sources/AllInApp/AllIn/AllInApp.swift index 2840c90..8843e72 100644 --- a/Sources/AllInApp/AllIn/AllInApp.swift +++ b/Sources/AllInApp/AllIn/AllInApp.swift @@ -6,6 +6,7 @@ // import SwiftUI +import DependencyInjection @main struct AllInApp: App { diff --git a/Sources/AllInApp/AllIn/ContentView.swift b/Sources/AllInApp/AllIn/ContentView.swift index f00a6ca..75d6bb9 100644 --- a/Sources/AllInApp/AllIn/ContentView.swift +++ b/Sources/AllInApp/AllIn/ContentView.swift @@ -6,6 +6,7 @@ // import SwiftUI +import DependencyInjection struct ContentView: View { diff --git a/Sources/AllInApp/AllIn/ViewModels/LoginViewModel.swift b/Sources/AllInApp/AllIn/ViewModels/LoginViewModel.swift index 342d479..2d5e698 100644 --- a/Sources/AllInApp/AllIn/ViewModels/LoginViewModel.swift +++ b/Sources/AllInApp/AllIn/ViewModels/LoginViewModel.swift @@ -7,6 +7,7 @@ import Foundation import SwiftUI +import DependencyInjection class LoginViewModel: ObservableObject { diff --git a/Sources/AllInApp/AllIn/ViewModels/RegisterViewModel.swift b/Sources/AllInApp/AllIn/ViewModels/RegisterViewModel.swift index c206362..8cd0aa3 100644 --- a/Sources/AllInApp/AllIn/ViewModels/RegisterViewModel.swift +++ b/Sources/AllInApp/AllIn/ViewModels/RegisterViewModel.swift @@ -7,6 +7,7 @@ import Foundation import SwiftUI +import DependencyInjection class RegisterViewModel: ObservableObject { diff --git a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj index a726e81..72c1896 100644 --- a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj +++ b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj @@ -37,7 +37,6 @@ 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 */; }; - EC6B96C92B24B69B00FC1C58 /* DependancyInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96C82B24B69B00FC1C58 /* DependancyInjection.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 */; }; @@ -49,6 +48,8 @@ EC89F7BD2B250D66003821CE /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC89F7BC2B250D66003821CE /* LoginView.swift */; }; ECA9D1C92B2D9ADA0076E0EC /* UserInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA9D1C82B2D9ADA0076E0EC /* UserInfo.swift */; }; ECA9D1CB2B2DA2320076E0EC /* DropDownFriends.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA9D1CA2B2DA2320076E0EC /* DropDownFriends.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, ); }; }; 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 */; }; @@ -72,6 +73,20 @@ }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + ECB357332B3CA69300045D41 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ECB357322B3CA69300045D41 /* DependencyInjection.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ EC0193772B25BF16005D81E6 /* AllcoinsCapsule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllcoinsCapsule.swift; sourceTree = ""; }; EC0193792B25C12B005D81E6 /* BetCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BetCard.swift; sourceTree = ""; }; @@ -106,7 +121,6 @@ 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 = ""; }; - EC6B96C82B24B69B00FC1C58 /* DependancyInjection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependancyInjection.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 = ""; }; @@ -118,6 +132,8 @@ 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 = ""; }; + 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 = ""; }; ECB7BC692B2F410A002A6654 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; ECB7BC6B2B2F43EE002A6654 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = ""; }; @@ -129,6 +145,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + ECB357312B3CA69300045D41 /* DependencyInjection.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -156,6 +173,7 @@ EC6B96AB2B24B4CC00FC1C58 /* AllInTests */, EC6B96B52B24B4CC00FC1C58 /* AllInUITests */, EC6B96992B24B4CC00FC1C58 /* Products */, + ECB3572D2B3CA3BD00045D41 /* Frameworks */, ); sourceTree = ""; }; @@ -219,7 +237,6 @@ isa = PBXGroup; children = ( EC6B96C62B24B5A100FC1C58 /* User.swift */, - EC6B96C82B24B69B00FC1C58 /* DependancyInjection.swift */, ); path = Models; sourceTree = ""; @@ -291,6 +308,15 @@ path = Components; sourceTree = ""; }; + ECB3572D2B3CA3BD00045D41 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ECB357302B3CA69300045D41 /* DependencyInjection.framework */, + ECB3572E2B3CA3C300045D41 /* DependencyInjection.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; ECB7BC662B2F1AAD002A6654 /* ViewModels */ = { isa = PBXGroup; children = ( @@ -310,6 +336,7 @@ EC6B96942B24B4CC00FC1C58 /* Sources */, EC6B96952B24B4CC00FC1C58 /* Frameworks */, EC6B96962B24B4CC00FC1C58 /* Resources */, + ECB357332B3CA69300045D41 /* Embed Frameworks */, ); buildRules = ( ); @@ -449,7 +476,6 @@ EC650A462B25D686003AFCAD /* RankingRow.swift in Sources */, EC01937A2B25C12B005D81E6 /* BetCard.swift in Sources */, EC650A422B25C817003AFCAD /* Friend.swift in Sources */, - EC6B96C92B24B69B00FC1C58 /* DependancyInjection.swift in Sources */, EC7A882F2B28E6BE004F226A /* ConfidentialityButton.swift in Sources */, ECB7BC702B336E28002A6654 /* RegisterViewModel.swift in Sources */, EC650A4C2B25E9C7003AFCAD /* RankingView.swift in Sources */, diff --git a/Sources/DependencyInjection/DependencyInjection.xcodeproj/project.pbxproj b/Sources/DependencyInjection/DependencyInjection.xcodeproj/project.pbxproj new file mode 100644 index 0000000..2c08517 --- /dev/null +++ b/Sources/DependencyInjection/DependencyInjection.xcodeproj/project.pbxproj @@ -0,0 +1,486 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + ECB3572C2B3CA37800045D41 /* DependencyInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB3572B2B3CA37800045D41 /* DependencyInjection.swift */; }; + ECEE18B82B3C9CF400C95E8A /* DependencyInjection.docc in Sources */ = {isa = PBXBuildFile; fileRef = ECEE18B72B3C9CF400C95E8A /* DependencyInjection.docc */; }; + ECEE18BE2B3C9CF400C95E8A /* DependencyInjection.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ECEE18B32B3C9CF400C95E8A /* DependencyInjection.framework */; }; + ECEE18C32B3C9CF400C95E8A /* DependencyInjectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECEE18C22B3C9CF400C95E8A /* DependencyInjectionTests.swift */; }; + ECEE18C42B3C9CF400C95E8A /* DependencyInjection.h in Headers */ = {isa = PBXBuildFile; fileRef = ECEE18B62B3C9CF400C95E8A /* DependencyInjection.h */; settings = {ATTRIBUTES = (Public, ); }; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + ECEE18BF2B3C9CF400C95E8A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = ECEE18AA2B3C9CF400C95E8A /* Project object */; + proxyType = 1; + remoteGlobalIDString = ECEE18B22B3C9CF400C95E8A; + remoteInfo = DependencyInjection; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + ECB3572B2B3CA37800045D41 /* DependencyInjection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyInjection.swift; sourceTree = ""; }; + ECEE18B32B3C9CF400C95E8A /* DependencyInjection.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DependencyInjection.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + ECEE18B62B3C9CF400C95E8A /* DependencyInjection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DependencyInjection.h; sourceTree = ""; }; + ECEE18B72B3C9CF400C95E8A /* DependencyInjection.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = DependencyInjection.docc; sourceTree = ""; }; + ECEE18BD2B3C9CF400C95E8A /* DependencyInjectionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DependencyInjectionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + ECEE18C22B3C9CF400C95E8A /* DependencyInjectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyInjectionTests.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + ECEE18B02B3C9CF400C95E8A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + ECEE18BA2B3C9CF400C95E8A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ECEE18BE2B3C9CF400C95E8A /* DependencyInjection.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + ECEE18A92B3C9CF400C95E8A = { + isa = PBXGroup; + children = ( + ECEE18B52B3C9CF400C95E8A /* DependencyInjection */, + ECEE18C12B3C9CF400C95E8A /* DependencyInjectionTests */, + ECEE18B42B3C9CF400C95E8A /* Products */, + ); + sourceTree = ""; + }; + ECEE18B42B3C9CF400C95E8A /* Products */ = { + isa = PBXGroup; + children = ( + ECEE18B32B3C9CF400C95E8A /* DependencyInjection.framework */, + ECEE18BD2B3C9CF400C95E8A /* DependencyInjectionTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + ECEE18B52B3C9CF400C95E8A /* DependencyInjection */ = { + isa = PBXGroup; + children = ( + ECEE18B62B3C9CF400C95E8A /* DependencyInjection.h */, + ECEE18B72B3C9CF400C95E8A /* DependencyInjection.docc */, + ECB3572B2B3CA37800045D41 /* DependencyInjection.swift */, + ); + path = DependencyInjection; + sourceTree = ""; + }; + ECEE18C12B3C9CF400C95E8A /* DependencyInjectionTests */ = { + isa = PBXGroup; + children = ( + ECEE18C22B3C9CF400C95E8A /* DependencyInjectionTests.swift */, + ); + path = DependencyInjectionTests; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + ECEE18AE2B3C9CF400C95E8A /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + ECEE18C42B3C9CF400C95E8A /* DependencyInjection.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + ECEE18B22B3C9CF400C95E8A /* DependencyInjection */ = { + isa = PBXNativeTarget; + buildConfigurationList = ECEE18C72B3C9CF400C95E8A /* Build configuration list for PBXNativeTarget "DependencyInjection" */; + buildPhases = ( + ECEE18AE2B3C9CF400C95E8A /* Headers */, + ECEE18AF2B3C9CF400C95E8A /* Sources */, + ECEE18B02B3C9CF400C95E8A /* Frameworks */, + ECEE18B12B3C9CF400C95E8A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = DependencyInjection; + productName = DependencyInjection; + productReference = ECEE18B32B3C9CF400C95E8A /* DependencyInjection.framework */; + productType = "com.apple.product-type.framework"; + }; + ECEE18BC2B3C9CF400C95E8A /* DependencyInjectionTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = ECEE18CA2B3C9CF400C95E8A /* Build configuration list for PBXNativeTarget "DependencyInjectionTests" */; + buildPhases = ( + ECEE18B92B3C9CF400C95E8A /* Sources */, + ECEE18BA2B3C9CF400C95E8A /* Frameworks */, + ECEE18BB2B3C9CF400C95E8A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ECEE18C02B3C9CF400C95E8A /* PBXTargetDependency */, + ); + name = DependencyInjectionTests; + productName = DependencyInjectionTests; + productReference = ECEE18BD2B3C9CF400C95E8A /* DependencyInjectionTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + ECEE18AA2B3C9CF400C95E8A /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1430; + LastUpgradeCheck = 1430; + TargetAttributes = { + ECEE18B22B3C9CF400C95E8A = { + CreatedOnToolsVersion = 14.3.1; + }; + ECEE18BC2B3C9CF400C95E8A = { + CreatedOnToolsVersion = 14.3.1; + }; + }; + }; + buildConfigurationList = ECEE18AD2B3C9CF400C95E8A /* Build configuration list for PBXProject "DependencyInjection" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = ECEE18A92B3C9CF400C95E8A; + productRefGroup = ECEE18B42B3C9CF400C95E8A /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + ECEE18B22B3C9CF400C95E8A /* DependencyInjection */, + ECEE18BC2B3C9CF400C95E8A /* DependencyInjectionTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + ECEE18B12B3C9CF400C95E8A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + ECEE18BB2B3C9CF400C95E8A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + ECEE18AF2B3C9CF400C95E8A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ECB3572C2B3CA37800045D41 /* DependencyInjection.swift in Sources */, + ECEE18B82B3C9CF400C95E8A /* DependencyInjection.docc in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + ECEE18B92B3C9CF400C95E8A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ECEE18C32B3C9CF400C95E8A /* DependencyInjectionTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + ECEE18C02B3C9CF400C95E8A /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = ECEE18B22B3C9CF400C95E8A /* DependencyInjection */; + targetProxy = ECEE18BF2B3C9CF400C95E8A /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + ECEE18C52B3C9CF400C95E8A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + ECEE18C62B3C9CF400C95E8A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + ECEE18C82B3C9CF400C95E8A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + LD_RUNPATH_SEARCH_PATHS = ( + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = ( + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 13.3; + MARKETING_VERSION = 1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; + PRODUCT_BUNDLE_IDENTIFIER = com.alldev.DependencyInjection; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SDKROOT = auto; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + ECEE18C92B3C9CF400C95E8A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + LD_RUNPATH_SEARCH_PATHS = ( + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = ( + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 13.3; + MARKETING_VERSION = 1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; + PRODUCT_BUNDLE_IDENTIFIER = com.alldev.DependencyInjection; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SDKROOT = auto; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + ECEE18CB2B3C9CF400C95E8A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + MACOSX_DEPLOYMENT_TARGET = 13.3; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.alldev.DependencyInjectionTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + ECEE18CC2B3C9CF400C95E8A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + MACOSX_DEPLOYMENT_TARGET = 13.3; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.alldev.DependencyInjectionTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = auto; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + ECEE18AD2B3C9CF400C95E8A /* Build configuration list for PBXProject "DependencyInjection" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + ECEE18C52B3C9CF400C95E8A /* Debug */, + ECEE18C62B3C9CF400C95E8A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + ECEE18C72B3C9CF400C95E8A /* Build configuration list for PBXNativeTarget "DependencyInjection" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + ECEE18C82B3C9CF400C95E8A /* Debug */, + ECEE18C92B3C9CF400C95E8A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + ECEE18CA2B3C9CF400C95E8A /* Build configuration list for PBXNativeTarget "DependencyInjectionTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + ECEE18CB2B3C9CF400C95E8A /* Debug */, + ECEE18CC2B3C9CF400C95E8A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = ECEE18AA2B3C9CF400C95E8A /* Project object */; +} diff --git a/Sources/DependencyInjection/DependencyInjection.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Sources/DependencyInjection/DependencyInjection.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Sources/DependencyInjection/DependencyInjection.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Sources/DependencyInjection/DependencyInjection.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Sources/DependencyInjection/DependencyInjection.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Sources/DependencyInjection/DependencyInjection.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Sources/DependencyInjection/DependencyInjection/DependencyInjection.docc/DependencyInjection.md b/Sources/DependencyInjection/DependencyInjection/DependencyInjection.docc/DependencyInjection.md new file mode 100755 index 0000000..fa1150c --- /dev/null +++ b/Sources/DependencyInjection/DependencyInjection/DependencyInjection.docc/DependencyInjection.md @@ -0,0 +1,13 @@ +# ``DependencyInjection`` + +Summary + +## Overview + +Text + +## Topics + +### Group + +- ``Symbol`` \ No newline at end of file diff --git a/Sources/DependencyInjection/DependencyInjection/DependencyInjection.h b/Sources/DependencyInjection/DependencyInjection/DependencyInjection.h new file mode 100644 index 0000000..2d655f3 --- /dev/null +++ b/Sources/DependencyInjection/DependencyInjection/DependencyInjection.h @@ -0,0 +1,18 @@ +// +// DependencyInjection.h +// DependencyInjection +// +// Created by Emre on 27/12/2023. +// + +#import + +//! Project version number for DependencyInjection. +FOUNDATION_EXPORT double DependencyInjectionVersionNumber; + +//! Project version string for DependencyInjection. +FOUNDATION_EXPORT const unsigned char DependencyInjectionVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/Sources/AllInApp/AllIn/Models/DependancyInjection.swift b/Sources/DependencyInjection/DependencyInjection/DependencyInjection.swift similarity index 68% rename from Sources/AllInApp/AllIn/Models/DependancyInjection.swift rename to Sources/DependencyInjection/DependencyInjection/DependencyInjection.swift index a5cd5fd..1824314 100644 --- a/Sources/AllInApp/AllIn/Models/DependancyInjection.swift +++ b/Sources/DependencyInjection/DependencyInjection/DependencyInjection.swift @@ -1,38 +1,38 @@ // -// DependancyInjection.swift -// AllIn +// DependencyInjection.swift +// DependencyInjection // -// Created by Emre on 20/10/2023. +// Created by Emre on 27/12/2023. // import Foundation -class DependencyInjection { - static var shared = DependencyInjection() +public class DependencyInjection { + public static var shared = DependencyInjection() private var singletons = [String: Any]() @discardableResult - func addSingleton(_ type: T.Type, _ instance: T) -> DependencyInjection { + public func addSingleton(_ type: T.Type, _ instance: T) -> DependencyInjection { let key = String(describing: T.self) singletons[key] = instance return self } - func resolve(_ type: T.Type) -> T? { + public func resolve(_ type: T.Type) -> T? { let key = String(describing: T.self) return singletons[key] as? T } } @propertyWrapper -struct Inject { +public struct Inject { private var value: T? - init() { + public init() { self.value = DependencyInjection.shared.resolve(T.self) } - var wrappedValue: T { + public var wrappedValue: T { get { if let value = value { return value diff --git a/Sources/DependencyInjection/DependencyInjectionTests/DependencyInjectionTests.swift b/Sources/DependencyInjection/DependencyInjectionTests/DependencyInjectionTests.swift new file mode 100644 index 0000000..519ba73 --- /dev/null +++ b/Sources/DependencyInjection/DependencyInjectionTests/DependencyInjectionTests.swift @@ -0,0 +1,36 @@ +// +// DependencyInjectionTests.swift +// DependencyInjectionTests +// +// Created by Emre on 27/12/2023. +// + +import XCTest +@testable import DependencyInjection + +class DependencyInjectionTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + 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. + } + + 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. + } + } + +} -- 2.36.3 From 105b89c1119319684de8a5e799aa56ecb1dcf509 Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Mon, 1 Jan 2024 12:58:31 +0100 Subject: [PATCH 2/5] Add Model, ViewModel and Stublib, also upgrade the user authentication :white_check_mark: --- .../contents.xcworkspacedata | 12 ++- Sources/AllInApp/AllIn/AllInApp.swift | 4 + Sources/AllInApp/AllIn/AppState.swift | 2 + .../AllIn/Components/AllcoinsCounter.swift | 2 +- Sources/AllInApp/AllIn/Components/Menu.swift | 2 +- Sources/AllInApp/AllIn/ContentView.swift | 13 ++- Sources/AllInApp/AllIn/Models/User.swift | 22 ----- .../AllInApp/AllIn/Services/AuthService.swift | 64 +++++++++++-- .../AllIn/Services/IAuthService.swift | 2 +- .../AllIn/ViewModels/BetViewModel.swift | 35 +++++++ .../ViewModels/CreationBetViewModel.swift | 68 ++++++++++++++ .../AllIn/ViewModels/FriendsViewModel.swift | 35 +++++++ .../AllIn/ViewModels/RankingViewModel.swift | 35 +++++++ Sources/AllInApp/AllIn/Views/BetView.swift | 1 + .../AllIn/Views/CreationBetView.swift | 42 ++++----- .../AllInApp.xcodeproj/project.pbxproj | 54 ++++++++--- Sources/AllInApp/AllInTests/AllInTests.swift | 51 ++++------- .../DependencyInjectionTests.swift | 40 ++++++++ Sources/Model/Sources/Model/Bet.swift | 22 +++++ .../Model/Sources/Model/BetDataManager.swift | 13 +++ Sources/Model/Sources/Model/BinaryBet.swift | 43 +++++++++ .../Sources/Model/BinaryParticipation.swift | 22 +++++ Sources/Model/Sources/Model/CustomBet.swift | 22 +++++ .../Sources/Model/CustomBetResponse.swift | 13 +++ .../Sources/Model/CustomParticipation.swift | 17 ++++ Sources/Model/Sources/Model/Manager.swift | 19 ++++ Sources/Model/Sources/Model/MatchBet.swift | 23 +++++ .../Sources/Model/MatchParticipation.swift | 18 ++++ Sources/Model/Sources/Model/Model.swift | 6 -- .../Model/Sources/Model/Participation.swift | 16 ++++ Sources/Model/Sources/Model/User.swift | 36 ++++++++ .../Model/Sources/Model/UserDataManager.swift | 14 +++ .../Model/Tests/ModelTests/ModelTests.swift | 11 --- Sources/StubLib/Package.swift | 29 ++++++ Sources/StubLib/README.md | 3 + .../Sources/StubLib/BetStubManager.swift | 26 ++++++ Sources/StubLib/Sources/StubLib/Stub.swift | 91 +++++++++++++++++++ .../Sources/StubLib/UserStubManager.swift | 38 ++++++++ Sources/ViewModel/.gitignore | 9 ++ Sources/ViewModel/Package.swift | 32 +++++++ Sources/ViewModel/README.md | 3 + .../Sources/ViewModel/ManagerVM.swift | 25 +++++ 42 files changed, 911 insertions(+), 124 deletions(-) delete mode 100644 Sources/AllInApp/AllIn/Models/User.swift create mode 100644 Sources/AllInApp/AllIn/ViewModels/BetViewModel.swift create mode 100644 Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift create mode 100644 Sources/AllInApp/AllIn/ViewModels/FriendsViewModel.swift create mode 100644 Sources/AllInApp/AllIn/ViewModels/RankingViewModel.swift create mode 100644 Sources/Model/Sources/Model/Bet.swift create mode 100644 Sources/Model/Sources/Model/BetDataManager.swift create mode 100644 Sources/Model/Sources/Model/BinaryBet.swift create mode 100644 Sources/Model/Sources/Model/BinaryParticipation.swift create mode 100644 Sources/Model/Sources/Model/CustomBet.swift create mode 100644 Sources/Model/Sources/Model/CustomBetResponse.swift create mode 100644 Sources/Model/Sources/Model/CustomParticipation.swift create mode 100644 Sources/Model/Sources/Model/Manager.swift create mode 100644 Sources/Model/Sources/Model/MatchBet.swift create mode 100644 Sources/Model/Sources/Model/MatchParticipation.swift delete mode 100644 Sources/Model/Sources/Model/Model.swift create mode 100644 Sources/Model/Sources/Model/Participation.swift create mode 100644 Sources/Model/Sources/Model/User.swift create mode 100644 Sources/Model/Sources/Model/UserDataManager.swift delete mode 100644 Sources/Model/Tests/ModelTests/ModelTests.swift create mode 100644 Sources/StubLib/Package.swift create mode 100644 Sources/StubLib/README.md create mode 100644 Sources/StubLib/Sources/StubLib/BetStubManager.swift create mode 100644 Sources/StubLib/Sources/StubLib/Stub.swift create mode 100644 Sources/StubLib/Sources/StubLib/UserStubManager.swift create mode 100644 Sources/ViewModel/.gitignore create mode 100644 Sources/ViewModel/Package.swift create mode 100644 Sources/ViewModel/README.md create mode 100644 Sources/ViewModel/Sources/ViewModel/ManagerVM.swift 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() { + + } +} -- 2.36.3 From 66f13688a5cb89f010f5a6f16b9e4230bc905ac0 Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Mon, 8 Jan 2024 08:44:10 +0100 Subject: [PATCH 3/5] add small correction --- .../ViewModels/CreationBetViewModel.swift | 49 ++++++++++++++----- .../Model/Sources/Model/BetDataManager.swift | 2 +- .../Sources/StubLib/BetStubManager.swift | 2 +- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift b/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift index f5818cc..f844fa0 100644 --- a/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift +++ b/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift @@ -25,23 +25,46 @@ class CreationBetViewModel: ObservableObject { @Published var endBetDateFieldError: String? func create() { + + guard checkAndSetError(forTheme: true, forDescription: true, forEndRegisterDate: true, forEndBetDate: true) else { + return + } + + resetAllFieldErrors() + manager.addBet() } - func checkAndSetError(forLogin checkLogin: Bool, forPassword checkPassword: Bool) -> Bool { - /*var newLoginIdentifierFieldError: String? - var newLoginPasswordFieldError: String? + func checkAndSetError(forTheme checkTheme: Bool, forDescription checkDescription: Bool, forEndRegisterDate checkEndRegisterDate: Bool, forEndBetDate checkEndBetDate: Bool) -> Bool { + + var newThemeFieldError: String? + var newDescriptionFieldError: String? + var newEndRegisterDateFieldError: String? + var newEndBetDateFieldError: String? + var hasError = false - // Login - if checkLogin, loginIdentifier.isEmpty { - newLoginIdentifierFieldError = "Veuillez saisir votre identifiant." + // Theme + if checkTheme, theme.isEmpty { + newThemeFieldError = "Veuillez saisir le thème." hasError = true } - // Password - if checkPassword, loginPassword.isEmpty { - newLoginPasswordFieldError = "Veuillez saisir votre mot de passe." + // Description + if checkDescription, description.isEmpty { + newDescriptionFieldError = "Veuillez saisir la description." + hasError = true + } + + // End Register Date + if checkEndRegisterDate, endRegisterDate < Date() { + newEndRegisterDateFieldError = "La date de fin des inscriptions doit être ultérieure à la date actuelle." + hasError = true + } + + // End Bet Date + if checkEndBetDate, endBetDate < endRegisterDate { + newEndBetDateFieldError = "La date de fin des paris doit être ultérieure à la date de fin des inscriptions." hasError = true } @@ -51,9 +74,11 @@ class CreationBetViewModel: ObservableObject { } withAnimation { - loginIdentifierFieldError = newLoginIdentifierFieldError - loginPasswordFieldError = newLoginPasswordFieldError - }*/ + themeFieldError = newThemeFieldError + descriptionFieldError = newDescriptionFieldError + endRegisterDateFieldError = newEndRegisterDateFieldError + endBetDateFieldError = newEndBetDateFieldError + } return false } diff --git a/Sources/Model/Sources/Model/BetDataManager.swift b/Sources/Model/Sources/Model/BetDataManager.swift index 4c3c51b..1a3fef2 100644 --- a/Sources/Model/Sources/Model/BetDataManager.swift +++ b/Sources/Model/Sources/Model/BetDataManager.swift @@ -2,7 +2,7 @@ // BetDataManager.swift // // -// Created by étudiant on 29/12/2023. +// Created by Emre on 29/12/2023. // import Foundation diff --git a/Sources/StubLib/Sources/StubLib/BetStubManager.swift b/Sources/StubLib/Sources/StubLib/BetStubManager.swift index b2bf7e1..c9c8347 100644 --- a/Sources/StubLib/Sources/StubLib/BetStubManager.swift +++ b/Sources/StubLib/Sources/StubLib/BetStubManager.swift @@ -2,7 +2,7 @@ // BetStubManager.swift // // -// Created by étudiant on 31/12/2023. +// Created by Emre on 31/12/2023. // import Foundation -- 2.36.3 From e7ab05a42345bcb54a4932244ebd13af194a56bc Mon Sep 17 00:00:00 2001 From: ludelanier Date: Mon, 8 Jan 2024 09:39:51 +0100 Subject: [PATCH 4/5] Add the new shortcut on the menuView for ranking View --- .../rankingImage.imageset/Contents.json | 21 +++++++++ .../rankingImage.imageset/Trophy.png | Bin 0 -> 7170 bytes Sources/AllInApp/AllIn/Components/Menu.swift | 5 +++ .../AllIn/Components/ParameterMenu.swift | 2 + .../AllInApp.xcodeproj/project.pbxproj | 42 +++++++++++------- Sources/Model/Package.swift | 3 -- Sources/StubLib/Package.swift | 3 -- Sources/ViewModel/Package.swift | 3 -- 8 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 Sources/AllInApp/AllIn/Assets.xcassets/rankingImage.imageset/Contents.json create mode 100644 Sources/AllInApp/AllIn/Assets.xcassets/rankingImage.imageset/Trophy.png diff --git a/Sources/AllInApp/AllIn/Assets.xcassets/rankingImage.imageset/Contents.json b/Sources/AllInApp/AllIn/Assets.xcassets/rankingImage.imageset/Contents.json new file mode 100644 index 0000000..5a28f80 --- /dev/null +++ b/Sources/AllInApp/AllIn/Assets.xcassets/rankingImage.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Trophy.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Sources/AllInApp/AllIn/Assets.xcassets/rankingImage.imageset/Trophy.png b/Sources/AllInApp/AllIn/Assets.xcassets/rankingImage.imageset/Trophy.png new file mode 100644 index 0000000000000000000000000000000000000000..b64d02e256f013eb719501a10d402ff536e5e54e GIT binary patch literal 7170 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 Date: Wed, 10 Jan 2024 12:52:18 +0100 Subject: [PATCH 5/5] Add Api package --- .../contents.xcworkspacedata | 3 + Sources/AllInApp/AllIn/AllInApp.swift | 3 +- .../AllInApp/AllIn/Services/AuthService.swift | 2 +- .../ViewModels/CreationBetViewModel.swift | 4 +- .../AllIn/Views/CreationBetView.swift | 140 +++++++++++------- .../AllInApp.xcodeproj/project.pbxproj | 7 + Sources/Api/Package.swift | 25 ++++ Sources/Api/README.md | 3 + Sources/Api/Sources/Api/UserApiManager.swift | 52 +++++++ Sources/Model/Package.swift | 3 - .../Sources/Model/Factory/FactoryBet.swift | 14 ++ Sources/Model/Sources/Model/Manager.swift | 4 + Sources/StubLib/Package.swift | 3 - Sources/StubLib/Sources/StubLib/Stub.swift | 2 +- Sources/ViewModel/Package.swift | 3 - .../Sources/ViewModel/ManagerVM.swift | 4 +- 16 files changed, 201 insertions(+), 71 deletions(-) create mode 100644 Sources/Api/Package.swift create mode 100644 Sources/Api/README.md create mode 100644 Sources/Api/Sources/Api/UserApiManager.swift create mode 100644 Sources/Model/Sources/Model/Factory/FactoryBet.swift diff --git a/Sources/AllIn.xcworkspace/contents.xcworkspacedata b/Sources/AllIn.xcworkspace/contents.xcworkspacedata index d92865d..50d956e 100644 --- a/Sources/AllIn.xcworkspace/contents.xcworkspacedata +++ b/Sources/AllIn.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + diff --git a/Sources/AllInApp/AllIn/AllInApp.swift b/Sources/AllInApp/AllIn/AllInApp.swift index 910f49f..fdd165e 100644 --- a/Sources/AllInApp/AllIn/AllInApp.swift +++ b/Sources/AllInApp/AllIn/AllInApp.swift @@ -10,6 +10,7 @@ import DependencyInjection import Model import ViewModel import StubLib +import Api @main struct AllInApp: App { @@ -19,7 +20,7 @@ struct AllInApp: App { init() { DI.addSingleton(IAuthService.self, AuthService()) - DI.addSingleton(ManagerVM.self, ManagerVM(withModel: Manager(withBetDataManager: BetStubManager(), withUserDataManager: UserStubManager(username: "Imri")))) + DI.addSingleton(ManagerVM.self, ManagerVM(withModel: Manager(withBetDataManager: BetStubManager(), withUserDataManager: UserApiManager()))) } var body: some Scene { diff --git a/Sources/AllInApp/AllIn/Services/AuthService.swift b/Sources/AllInApp/AllIn/Services/AuthService.swift index 7f22be8..b318d98 100644 --- a/Sources/AllInApp/AllIn/Services/AuthService.swift +++ b/Sources/AllInApp/AllIn/Services/AuthService.swift @@ -62,7 +62,7 @@ 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 httpResponse.statusCode == 201 { if let data = data, let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let token = json["token"] as? String { diff --git a/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift b/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift index f844fa0..ea137b7 100644 --- a/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift +++ b/Sources/AllInApp/AllIn/ViewModels/CreationBetViewModel.swift @@ -32,7 +32,9 @@ class CreationBetViewModel: ObservableObject { resetAllFieldErrors() - manager.addBet() + if let user = AppStateContainer.shared.user { + manager.addBet(theme: theme, description: description, endRegister: endRegisterDate, endBet: endBetDate, isPublic: isPublic, creator: user) + } } func checkAndSetError(forTheme checkTheme: Bool, forDescription checkDescription: Bool, forEndRegisterDate checkEndRegisterDate: Bool, forEndBetDate checkEndBetDate: Bool) -> Bool { diff --git a/Sources/AllInApp/AllIn/Views/CreationBetView.swift b/Sources/AllInApp/AllIn/Views/CreationBetView.swift index 68ae1e0..6aa4975 100644 --- a/Sources/AllInApp/AllIn/Views/CreationBetView.swift +++ b/Sources/AllInApp/AllIn/Views/CreationBetView.swift @@ -97,23 +97,29 @@ struct CreationBetView: View { .frame(width: 340) .padding(.leading, 10) - TextField("", text: $viewModel.theme, prompt: Text("Études, sport, soirée...") - .foregroundColor(AllInColors.lightGrey300Color) - .font(.system(size: 14)) - .fontWeight(.light)) - .padding() - .background( - RoundedRectangle(cornerRadius: 9) - .fill(AllInColors.componentBackgroundColor) - .frame(height: 40) - ) - .frame(width: 350, height: 40) - .foregroundColor(.black) - .overlay( - RoundedRectangle(cornerRadius: 10, style: .continuous) - .stroke(AllInColors.delimiterGrey, lineWidth: 1) - ) - .padding(.bottom, 5) + VStack { + if let themeError = $viewModel.themeFieldError.wrappedValue { + Text(themeError) + .textStyle(weight: .bold, color: .red, size: 10) + } + TextField("", text: $viewModel.theme, prompt: Text("Études, sport, soirée...") + .foregroundColor(AllInColors.lightGrey300Color) + .font(.system(size: 14)) + .fontWeight(.light)) + .padding() + .background( + RoundedRectangle(cornerRadius: 9) + .fill(AllInColors.componentBackgroundColor) + .frame(height: 40) + ) + .frame(width: 350, height: 40) + .foregroundColor(.black) + .overlay( + RoundedRectangle(cornerRadius: 10, style: .continuous) + .stroke(AllInColors.delimiterGrey, lineWidth: 1) + ) + .padding(.bottom, 5) + } } HStack(spacing: 5) { @@ -132,24 +138,30 @@ struct CreationBetView: View { .frame(width: 340) .padding(.leading, 10) - TextField("", text: $viewModel.description, prompt: Text("David sera absent Lundi matin en cours ?") - .foregroundColor(AllInColors.lightGrey300Color) - .font(.system(size: 14)) - .fontWeight(.light), axis: .vertical) - .lineLimit(4, reservesSpace: true) - .padding() - .background( - RoundedRectangle(cornerRadius: 9) - .fill(AllInColors.componentBackgroundColor) - .frame(height: 110) - ) - .frame(width: 350, height: 110) - .foregroundColor(.black) - .overlay( - RoundedRectangle(cornerRadius: 10, style: .continuous) - .stroke(AllInColors.delimiterGrey, lineWidth: 1) - ) - .padding(.bottom, 30) + VStack { + if let descriptionError = $viewModel.descriptionFieldError.wrappedValue { + Text(descriptionError) + .textStyle(weight: .bold, color: .red, size: 10) + } + TextField("", text: $viewModel.description, prompt: Text("David sera absent Lundi matin en cours ?") + .foregroundColor(AllInColors.lightGrey300Color) + .font(.system(size: 14)) + .fontWeight(.light), axis: .vertical) + .lineLimit(4, reservesSpace: true) + .padding() + .background( + RoundedRectangle(cornerRadius: 9) + .fill(AllInColors.componentBackgroundColor) + .frame(height: 110) + ) + .frame(width: 350, height: 110) + .foregroundColor(.black) + .overlay( + RoundedRectangle(cornerRadius: 10, style: .continuous) + .stroke(AllInColors.delimiterGrey, lineWidth: 1) + ) + .padding(.bottom, 30) + } HStack(spacing: 5) { Text("Date de fin des inscriptions") @@ -166,19 +178,25 @@ struct CreationBetView: View { .frame(width: 340) .padding(.leading, 10) - HStack(spacing: 5) { - DatePicker( - "", - selection: $viewModel.endRegisterDate, - in: dateRange, - displayedComponents: [.date, .hourAndMinute] - ) - .accentColor(AllInColors.lightPurpleColor) - .labelsHidden() - .padding(.bottom, 10) - Spacer() + VStack { + if let endRegisterError = $viewModel.endRegisterDateFieldError.wrappedValue { + Text(endRegisterError) + .textStyle(weight: .bold, color: .red, size: 10) + } + HStack(spacing: 5) { + DatePicker( + "", + selection: $viewModel.endRegisterDate, + in: dateRange, + displayedComponents: [.date, .hourAndMinute] + ) + .accentColor(AllInColors.lightPurpleColor) + .labelsHidden() + .padding(.bottom, 10) + Spacer() + } + .frame(width: 340) } - .frame(width: 340) VStack(alignment: .leading, spacing: 5) { VStack() { @@ -197,15 +215,25 @@ struct CreationBetView: View { } .padding(.leading, 10) } - DatePicker( - "", - selection: $viewModel.endBetDate, - in: dateRange, - displayedComponents: [.date, .hourAndMinute] - ) - .accentColor(AllInColors.lightPurpleColor) - .labelsHidden() - .padding(.bottom, 40) + + VStack { + if let endBetError = $viewModel.endBetDateFieldError.wrappedValue { + Text(endBetError) + .textStyle(weight: .bold, color: .red, size: 10) + } + HStack(spacing: 5) { + DatePicker( + "", + selection: $viewModel.endBetDate, + in: dateRange, + displayedComponents: [.date, .hourAndMinute] + ) + .accentColor(AllInColors.lightPurpleColor) + .labelsHidden() + .padding(.bottom, 40) + Spacer() + } + } } .frame(width: 340) diff --git a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj index c72f194..8e23970 100644 --- a/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj +++ b/Sources/AllInApp/AllInApp.xcodeproj/project.pbxproj @@ -60,6 +60,7 @@ ECB7BC6A2B2F410A002A6654 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC692B2F410A002A6654 /* AppDelegate.swift */; }; ECB7BC6C2B2F43EE002A6654 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC6B2B2F43EE002A6654 /* AppState.swift */; }; ECB7BC702B336E28002A6654 /* RegisterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC6F2B336E28002A6654 /* RegisterViewModel.swift */; }; + ECCD244A2B4DE8010071FA9E /* Api in Frameworks */ = {isa = PBXBuildFile; productRef = ECCD24492B4DE8010071FA9E /* Api */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -156,6 +157,7 @@ files = ( EC8B9CCE2B42C9D3002806F3 /* StubLib in Frameworks */, ECB357352B3E13A400045D41 /* Model in Frameworks */, + ECCD244A2B4DE8010071FA9E /* Api in Frameworks */, ECB357312B3CA69300045D41 /* DependencyInjection.framework in Frameworks */, ECB26A152B406B4800FE06B3 /* ViewModel in Frameworks */, ); @@ -354,6 +356,7 @@ ECB357342B3E13A400045D41 /* Model */, ECB26A142B406B4800FE06B3 /* ViewModel */, EC8B9CCD2B42C9D3002806F3 /* StubLib */, + ECCD24492B4DE8010071FA9E /* Api */, ); productName = AllIn; productReference = EC6B96982B24B4CC00FC1C58 /* AllIn.app */; @@ -852,6 +855,10 @@ isa = XCSwiftPackageProductDependency; productName = Model; }; + ECCD24492B4DE8010071FA9E /* Api */ = { + isa = XCSwiftPackageProductDependency; + productName = Api; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = EC6B96902B24B4CC00FC1C58 /* Project object */; diff --git a/Sources/Api/Package.swift b/Sources/Api/Package.swift new file mode 100644 index 0000000..5f646b4 --- /dev/null +++ b/Sources/Api/Package.swift @@ -0,0 +1,25 @@ +// 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: "Api", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "Api", + targets: ["Api"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + 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: "Api", + dependencies: []), + ] +) diff --git a/Sources/Api/README.md b/Sources/Api/README.md new file mode 100644 index 0000000..c22c038 --- /dev/null +++ b/Sources/Api/README.md @@ -0,0 +1,3 @@ +# Api + +A description of this package. diff --git a/Sources/Api/Sources/Api/UserApiManager.swift b/Sources/Api/Sources/Api/UserApiManager.swift new file mode 100644 index 0000000..9624e17 --- /dev/null +++ b/Sources/Api/Sources/Api/UserApiManager.swift @@ -0,0 +1,52 @@ +// +// UserApiManager.swift +// +// +// Created by Emre on 31/12/2023. +// + +import Foundation +import Model + +let allInApi = "https://codefirst.iut.uca.fr/containers/AllDev-api" + +public struct UserApiManager: UserDataManager { + + public init() { + } + + public func getBets(withIndex index: Int, withCount count: Int) -> [Bet] { + fatalError("Not implemented yet") + } + + public func addBet(bet: Bet) { + + let url = URL(string: allInApi + "bets/add")! + var request = URLRequest(url: url) + request.httpMethod = "POST" + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + + let json = [ + "theme": bet.theme, + "sentenceBet": bet.phrase, + "endRegistration": dateFormatter.string(from: bet.endRegisterDate), + "endBet": dateFormatter.string(from: bet.endBetDate), + "isPrivate": String(bet.isPublic), + "response": "", + "createdBy": "" + ] + + if let jsonData = try? JSONSerialization.data(withJSONObject: json, options: []){ + URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in + + }.resume() + } + } + + public func getFriends() -> [User] { + fatalError("Not implemented yet") + } +} diff --git a/Sources/Model/Package.swift b/Sources/Model/Package.swift index 3495d60..5e7194a 100644 --- a/Sources/Model/Package.swift +++ b/Sources/Model/Package.swift @@ -21,8 +21,5 @@ let package = Package( .target( name: "Model", dependencies: []), - .testTarget( - name: "ModelTests", - dependencies: ["Model"]), ] ) diff --git a/Sources/Model/Sources/Model/Factory/FactoryBet.swift b/Sources/Model/Sources/Model/Factory/FactoryBet.swift new file mode 100644 index 0000000..bb26240 --- /dev/null +++ b/Sources/Model/Sources/Model/Factory/FactoryBet.swift @@ -0,0 +1,14 @@ +// +// FactoryBet.swift +// +// +// Created by Emre on 09/01/2024. +// + +import Foundation + +public protocol FactoryBet { + func toResponse() + func toModel() -> Bet + func toModel(theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User, type: Int) -> Bet +} diff --git a/Sources/Model/Sources/Model/Manager.swift b/Sources/Model/Sources/Model/Manager.swift index 2463e97..eba7463 100644 --- a/Sources/Model/Sources/Model/Manager.swift +++ b/Sources/Model/Sources/Model/Manager.swift @@ -16,4 +16,8 @@ public struct Manager { self.userDataManager = userDataManager } + public func addBet(bet: Bet) { + userDataManager.addBet(bet: bet) + } + } diff --git a/Sources/StubLib/Package.swift b/Sources/StubLib/Package.swift index a8abfb8..75b012d 100644 --- a/Sources/StubLib/Package.swift +++ b/Sources/StubLib/Package.swift @@ -22,8 +22,5 @@ let package = Package( .target( name: "StubLib", dependencies: ["Model"]), - .testTarget( - name: "StubLibTests", - dependencies: ["StubLib"]), ] ) diff --git a/Sources/StubLib/Sources/StubLib/Stub.swift b/Sources/StubLib/Sources/StubLib/Stub.swift index c5d7e04..fe9e225 100644 --- a/Sources/StubLib/Sources/StubLib/Stub.swift +++ b/Sources/StubLib/Sources/StubLib/Stub.swift @@ -27,7 +27,7 @@ struct Stub { users.append(user2) user1.addFriend(user: user2) - var user3 = User(username: "Arthur", email: "arthur.valin@etu.uca.fr", nbCoins: 30, friends: [user2]) + let user3 = User(username: "Arthur", email: "arthur.valin@etu.uca.fr", nbCoins: 30, friends: [user2]) users.append(user3) user2.addFriend(user: user3) diff --git a/Sources/ViewModel/Package.swift b/Sources/ViewModel/Package.swift index e1b79e7..67fd2cf 100644 --- a/Sources/ViewModel/Package.swift +++ b/Sources/ViewModel/Package.swift @@ -25,8 +25,5 @@ let package = Package( .target( name: "ViewModel", dependencies: ["Model"]), - .testTarget( - name: "ViewModelTests", - dependencies: ["ViewModel"]), ] ) diff --git a/Sources/ViewModel/Sources/ViewModel/ManagerVM.swift b/Sources/ViewModel/Sources/ViewModel/ManagerVM.swift index 91c1245..2bcb8b0 100644 --- a/Sources/ViewModel/Sources/ViewModel/ManagerVM.swift +++ b/Sources/ViewModel/Sources/ViewModel/ManagerVM.swift @@ -19,7 +19,7 @@ public class ManagerVM: ObservableObject { } - public func addBet() { - + public func addBet(theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User) { + model.addBet(bet: BinaryBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, totalStakes: 0, isPublic: isPublic, invited: [], author: creator, registered: [])) } } -- 2.36.3