From d62d3420d66b577632a0a795672ea5afbefd5c35 Mon Sep 17 00:00:00 2001 From: baegteun Date: Sat, 10 Jun 2023 21:17:11 +0900 Subject: [PATCH 1/7] :sparkles: :: UserDomainModule --- .../Dependency+Target.swift | 12 +++++++++ .../ModulePaths.swift | 1 + .../Demo/Resources/LaunchScreen.storyboard | 25 +++++++++++++++++++ .../UserDomain/Demo/Sources/AppDelegate.swift | 19 ++++++++++++++ .../UserDomain/Interface/Interface.swift | 1 + Projects/Domain/UserDomain/Project.swift | 10 ++++++++ .../Domain/UserDomain/Sources/Source.swift | 1 + .../Domain/UserDomain/Testing/Testing.swift | 1 + .../UserDomain/Tests/UserDomainTest.swift | 11 ++++++++ 9 files changed, 81 insertions(+) create mode 100644 Projects/Domain/UserDomain/Demo/Resources/LaunchScreen.storyboard create mode 100644 Projects/Domain/UserDomain/Demo/Sources/AppDelegate.swift create mode 100644 Projects/Domain/UserDomain/Interface/Interface.swift create mode 100644 Projects/Domain/UserDomain/Project.swift create mode 100644 Projects/Domain/UserDomain/Sources/Source.swift create mode 100644 Projects/Domain/UserDomain/Testing/Testing.swift create mode 100644 Projects/Domain/UserDomain/Tests/UserDomainTest.swift diff --git a/Plugin/DependencyPlugin/ProjectDescriptionHelpers/Dependency+Target.swift b/Plugin/DependencyPlugin/ProjectDescriptionHelpers/Dependency+Target.swift index 89325365..0b2fbcc2 100644 --- a/Plugin/DependencyPlugin/ProjectDescriptionHelpers/Dependency+Target.swift +++ b/Plugin/DependencyPlugin/ProjectDescriptionHelpers/Dependency+Target.swift @@ -88,6 +88,18 @@ public extension TargetDependency.Feature { } public extension TargetDependency.Domain { + static let UserDomainTesting = TargetDependency.project( + target: ModulePaths.Domain.UserDomain.targetName(type: .testing), + path: .relativeToDomain(ModulePaths.Domain.UserDomain.rawValue) + ) + static let UserDomainInterface = TargetDependency.project( + target: ModulePaths.Domain.UserDomain.targetName(type: .interface), + path: .relativeToDomain(ModulePaths.Domain.UserDomain.rawValue) + ) + static let UserDomain = TargetDependency.project( + target: ModulePaths.Domain.UserDomain.targetName(type: .sources), + path: .relativeToDomain(ModulePaths.Domain.UserDomain.rawValue) + ) static let FileDomainTesting = TargetDependency.project( target: ModulePaths.Domain.FileDomain.targetName(type: .testing), path: .relativeToDomain(ModulePaths.Domain.FileDomain.rawValue) diff --git a/Plugin/DependencyPlugin/ProjectDescriptionHelpers/ModulePaths.swift b/Plugin/DependencyPlugin/ProjectDescriptionHelpers/ModulePaths.swift index c5f215cf..24462add 100644 --- a/Plugin/DependencyPlugin/ProjectDescriptionHelpers/ModulePaths.swift +++ b/Plugin/DependencyPlugin/ProjectDescriptionHelpers/ModulePaths.swift @@ -30,6 +30,7 @@ public extension ModulePaths { public extension ModulePaths { enum Domain: String { + case UserDomain case FileDomain case MajorDomain case StudentDomain diff --git a/Projects/Domain/UserDomain/Demo/Resources/LaunchScreen.storyboard b/Projects/Domain/UserDomain/Demo/Resources/LaunchScreen.storyboard new file mode 100644 index 00000000..865e9329 --- /dev/null +++ b/Projects/Domain/UserDomain/Demo/Resources/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Projects/Domain/UserDomain/Demo/Sources/AppDelegate.swift b/Projects/Domain/UserDomain/Demo/Sources/AppDelegate.swift new file mode 100644 index 00000000..ef2bae04 --- /dev/null +++ b/Projects/Domain/UserDomain/Demo/Sources/AppDelegate.swift @@ -0,0 +1,19 @@ +import UIKit + +@main +final class AppDelegate: UIResponder, UIApplicationDelegate { + var window: UIWindow? + + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil + ) -> Bool { + window = UIWindow(frame: UIScreen.main.bounds) + let viewController = UIViewController() + viewController.view.backgroundColor = .yellow + window?.rootViewController = viewController + window?.makeKeyAndVisible() + + return true + } +} diff --git a/Projects/Domain/UserDomain/Interface/Interface.swift b/Projects/Domain/UserDomain/Interface/Interface.swift new file mode 100644 index 00000000..b1853ce6 --- /dev/null +++ b/Projects/Domain/UserDomain/Interface/Interface.swift @@ -0,0 +1 @@ +// This is for Tuist diff --git a/Projects/Domain/UserDomain/Project.swift b/Projects/Domain/UserDomain/Project.swift new file mode 100644 index 00000000..c3c22934 --- /dev/null +++ b/Projects/Domain/UserDomain/Project.swift @@ -0,0 +1,10 @@ +import ProjectDescription +import ProjectDescriptionHelpers +import DependencyPlugin + +let project = Project.makeModule( + name: ModulePaths.Domain.UserDomain.rawValue, + product: .staticLibrary, + targets: [.interface, .testing, .unitTest, .demo], + internalDependencies: [] +) diff --git a/Projects/Domain/UserDomain/Sources/Source.swift b/Projects/Domain/UserDomain/Sources/Source.swift new file mode 100644 index 00000000..b1853ce6 --- /dev/null +++ b/Projects/Domain/UserDomain/Sources/Source.swift @@ -0,0 +1 @@ +// This is for Tuist diff --git a/Projects/Domain/UserDomain/Testing/Testing.swift b/Projects/Domain/UserDomain/Testing/Testing.swift new file mode 100644 index 00000000..b1853ce6 --- /dev/null +++ b/Projects/Domain/UserDomain/Testing/Testing.swift @@ -0,0 +1 @@ +// This is for Tuist diff --git a/Projects/Domain/UserDomain/Tests/UserDomainTest.swift b/Projects/Domain/UserDomain/Tests/UserDomainTest.swift new file mode 100644 index 00000000..e1c1e167 --- /dev/null +++ b/Projects/Domain/UserDomain/Tests/UserDomainTest.swift @@ -0,0 +1,11 @@ +import XCTest + +final class UserDomainTests: XCTestCase { + override func setUpWithError() throws {} + + override func tearDownWithError() throws {} + + func testExample() { + XCTAssertEqual(1, 1) + } +} From fe2c44b7c63c3671f52866056ab0a37b7ad53529 Mon Sep 17 00:00:00 2001 From: baegteun Date: Sat, 10 Jun 2023 21:37:37 +0900 Subject: [PATCH 2/7] :sparkles: :: UserDomain Interface --- Projects/App/Project.swift | 1 + .../Interface/DataSource/Local/LocalUserDataSource.swift | 6 ++++++ .../Domain/UserDomain/Interface/Enum/UserRoleType.swift | 6 ++++++ Projects/Domain/UserDomain/Interface/Interface.swift | 1 - .../UserDomain/Interface/Repository/UserRepository.swift | 6 ++++++ .../UserDomain/Interface/UseCase/LoadUserRoleUseCase.swift | 3 +++ .../UserDomain/Interface/UseCase/SaveUserRoleUseCase.swift | 5 +++++ Projects/Domain/UserDomain/Project.swift | 4 +++- Projects/Feature/InputInformationFeature/Project.swift | 3 ++- 9 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 Projects/Domain/UserDomain/Interface/DataSource/Local/LocalUserDataSource.swift create mode 100644 Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift delete mode 100644 Projects/Domain/UserDomain/Interface/Interface.swift create mode 100644 Projects/Domain/UserDomain/Interface/Repository/UserRepository.swift create mode 100644 Projects/Domain/UserDomain/Interface/UseCase/LoadUserRoleUseCase.swift create mode 100644 Projects/Domain/UserDomain/Interface/UseCase/SaveUserRoleUseCase.swift diff --git a/Projects/App/Project.swift b/Projects/App/Project.swift index 29c052f4..9740fc4b 100644 --- a/Projects/App/Project.swift +++ b/Projects/App/Project.swift @@ -50,6 +50,7 @@ let targets: [Target] = [ .Domain.StudentDomain, .Domain.FileDomain, .Domain.MajorDomain, + .Domain.UserDomain, .Core.JwtStore, .Shared.KeychainModule ], diff --git a/Projects/Domain/UserDomain/Interface/DataSource/Local/LocalUserDataSource.swift b/Projects/Domain/UserDomain/Interface/DataSource/Local/LocalUserDataSource.swift new file mode 100644 index 00000000..ff5fb1a5 --- /dev/null +++ b/Projects/Domain/UserDomain/Interface/DataSource/Local/LocalUserDataSource.swift @@ -0,0 +1,6 @@ +import Foundation + +public protocol LocalUserDataSource { + func saveUserRole(role: UserRoleType) + func loadUserRole() -> UserRoleType +} diff --git a/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift b/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift new file mode 100644 index 00000000..516e7a8e --- /dev/null +++ b/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift @@ -0,0 +1,6 @@ +import Foundation + +public enum UserRoleType: String { + case student = "ROLE_STUDENT" + case teacher = "ROLE_TEACHER" +} diff --git a/Projects/Domain/UserDomain/Interface/Interface.swift b/Projects/Domain/UserDomain/Interface/Interface.swift deleted file mode 100644 index b1853ce6..00000000 --- a/Projects/Domain/UserDomain/Interface/Interface.swift +++ /dev/null @@ -1 +0,0 @@ -// This is for Tuist diff --git a/Projects/Domain/UserDomain/Interface/Repository/UserRepository.swift b/Projects/Domain/UserDomain/Interface/Repository/UserRepository.swift new file mode 100644 index 00000000..03e3ee20 --- /dev/null +++ b/Projects/Domain/UserDomain/Interface/Repository/UserRepository.swift @@ -0,0 +1,6 @@ +import Foundation + +public protocol UserRepository { + func saveUserRole(role: UserRoleType) + func loadUserRole() -> UserRoleType +} diff --git a/Projects/Domain/UserDomain/Interface/UseCase/LoadUserRoleUseCase.swift b/Projects/Domain/UserDomain/Interface/UseCase/LoadUserRoleUseCase.swift new file mode 100644 index 00000000..75ac04e2 --- /dev/null +++ b/Projects/Domain/UserDomain/Interface/UseCase/LoadUserRoleUseCase.swift @@ -0,0 +1,3 @@ +public protocol LoadUserRoleUseCase { + func execute() -> UserRoleType +} diff --git a/Projects/Domain/UserDomain/Interface/UseCase/SaveUserRoleUseCase.swift b/Projects/Domain/UserDomain/Interface/UseCase/SaveUserRoleUseCase.swift new file mode 100644 index 00000000..b0411980 --- /dev/null +++ b/Projects/Domain/UserDomain/Interface/UseCase/SaveUserRoleUseCase.swift @@ -0,0 +1,5 @@ +import Foundation + +public protocol SaveUserRoleUseCase { + func execute(role: UserRoleType) +} diff --git a/Projects/Domain/UserDomain/Project.swift b/Projects/Domain/UserDomain/Project.swift index c3c22934..7df0efc8 100644 --- a/Projects/Domain/UserDomain/Project.swift +++ b/Projects/Domain/UserDomain/Project.swift @@ -6,5 +6,7 @@ let project = Project.makeModule( name: ModulePaths.Domain.UserDomain.rawValue, product: .staticLibrary, targets: [.interface, .testing, .unitTest, .demo], - internalDependencies: [] + internalDependencies: [ + .Domain.BaseDomain + ] ) diff --git a/Projects/Feature/InputInformationFeature/Project.swift b/Projects/Feature/InputInformationFeature/Project.swift index 40acab65..1ec00038 100644 --- a/Projects/Feature/InputInformationFeature/Project.swift +++ b/Projects/Feature/InputInformationFeature/Project.swift @@ -15,6 +15,7 @@ let project = Project.makeModule( .Feature.InputCertificateInfoFeatureInterface, .Feature.InputLanguageInfoFeatureInterface, .Domain.FileDomainInterface, - .Domain.StudentDomainInterface + .Domain.StudentDomainInterface, + .Domain.UserDomainInterface ] ) From 5ffb356e21048a73a695bcfbb44128fa375891d1 Mon Sep 17 00:00:00 2001 From: baegteun Date: Sat, 10 Jun 2023 21:38:54 +0900 Subject: [PATCH 3/7] :sparkles: :: UserDomainBuildable --- .../Domain/UserDomain/Interface/DI/UserDomainBuildable.swift | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Projects/Domain/UserDomain/Interface/DI/UserDomainBuildable.swift diff --git a/Projects/Domain/UserDomain/Interface/DI/UserDomainBuildable.swift b/Projects/Domain/UserDomain/Interface/DI/UserDomainBuildable.swift new file mode 100644 index 00000000..fe38f52a --- /dev/null +++ b/Projects/Domain/UserDomain/Interface/DI/UserDomainBuildable.swift @@ -0,0 +1,5 @@ +public protocol UserDomainBuildable { + var userRepository: any UserRepository { get } + var loadUserRoleUseCase: any LoadUserRoleUseCase { get } + var saveUserRoleUseCase: any SaveUserRoleUseCase { get } +} From 42d405ea4dcf9edb9af1ffd4ff359ffdb1ad4793 Mon Sep 17 00:00:00 2001 From: baegteun Date: Sat, 10 Jun 2023 21:54:50 +0900 Subject: [PATCH 4/7] =?UTF-8?q?:sparkles:=20::=20UserDomain=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Application/NeedleGenerated.swift | 1 + .../Interface/Enum/UserRoleType.swift | 1 + .../Sources/DI/UserDomainComponent.swift | 19 +++++++++++++ .../DataSource/LocalUserDataSourceImpl.swift | 27 +++++++++++++++++++ .../Repository/UserRepositoryImpl.swift | 18 +++++++++++++ .../Domain/UserDomain/Sources/Source.swift | 1 - .../UseCase/LoadUserRoleUseCaseImpl.swift | 13 +++++++++ .../UseCase/SaveUserRoleUseCaseImpl.swift | 13 +++++++++ 8 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 Projects/Domain/UserDomain/Sources/DI/UserDomainComponent.swift create mode 100644 Projects/Domain/UserDomain/Sources/DataSource/LocalUserDataSourceImpl.swift create mode 100644 Projects/Domain/UserDomain/Sources/Repository/UserRepositoryImpl.swift delete mode 100644 Projects/Domain/UserDomain/Sources/Source.swift create mode 100644 Projects/Domain/UserDomain/Sources/UseCase/LoadUserRoleUseCaseImpl.swift create mode 100644 Projects/Domain/UserDomain/Sources/UseCase/SaveUserRoleUseCaseImpl.swift diff --git a/Projects/App/Sources/Application/NeedleGenerated.swift b/Projects/App/Sources/Application/NeedleGenerated.swift index 23cdec95..6cfe9e3f 100644 --- a/Projects/App/Sources/Application/NeedleGenerated.swift +++ b/Projects/App/Sources/Application/NeedleGenerated.swift @@ -33,6 +33,7 @@ import SigninFeatureInterface import StudentDomain import StudentDomainInterface import SwiftUI +import UserDomainInterface // swiftlint:disable unused_declaration private let needleDependenciesHash : String? = nil diff --git a/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift b/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift index 516e7a8e..d0d7cbf7 100644 --- a/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift +++ b/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift @@ -3,4 +3,5 @@ import Foundation public enum UserRoleType: String { case student = "ROLE_STUDENT" case teacher = "ROLE_TEACHER" + case guest } diff --git a/Projects/Domain/UserDomain/Sources/DI/UserDomainComponent.swift b/Projects/Domain/UserDomain/Sources/DI/UserDomainComponent.swift new file mode 100644 index 00000000..cfaaf451 --- /dev/null +++ b/Projects/Domain/UserDomain/Sources/DI/UserDomainComponent.swift @@ -0,0 +1,19 @@ +import NeedleFoundation +import UserDomainInterface + +public protocol UserDomainDependency: Dependency {} + +public final class UserDomainComponent: Component, UserDomainBuildable { + public var saveUserRoleUseCase: any SaveUserRoleUseCase { + SaveUserRoleUseCaseImpl(userRepository: userRepository) + } + public var loadUserRoleUseCase: any LoadUserRoleUseCase { + LoadUserRoleUseCaseImpl(userRepository: userRepository) + } + public var userRepository: any UserRepository { + UserRepositoryImpl(localUserDataSource: localUserDataSource) + } + var localUserDataSource: any LocalUserDataSource { + LocalUserDataSourceImpl(userDefaults: .standard) + } +} diff --git a/Projects/Domain/UserDomain/Sources/DataSource/LocalUserDataSourceImpl.swift b/Projects/Domain/UserDomain/Sources/DataSource/LocalUserDataSourceImpl.swift new file mode 100644 index 00000000..ec8d8339 --- /dev/null +++ b/Projects/Domain/UserDomain/Sources/DataSource/LocalUserDataSourceImpl.swift @@ -0,0 +1,27 @@ +import Foundation +import UserDomainInterface + +struct LocalUserDataSourceImpl: LocalUserDataSource { + private enum UserDefaultsKey { + static let userRole = "USER_ROLE" + } + + private let userDefaults: UserDefaults + + init(userDefaults: UserDefaults) { + self.userDefaults = userDefaults + } + + func saveUserRole(role: UserRoleType) { + userDefaults.setValue(role.rawValue, forKey: UserDefaultsKey.userRole) + } + + func loadUserRole() -> UserRoleType { + let userRole = userDefaults.string(forKey: UserDefaultsKey.userRole) + if let userRole { + return UserRoleType(rawValue: userRole) ?? .guest + } else { + return .guest + } + } +} diff --git a/Projects/Domain/UserDomain/Sources/Repository/UserRepositoryImpl.swift b/Projects/Domain/UserDomain/Sources/Repository/UserRepositoryImpl.swift new file mode 100644 index 00000000..e69a8c76 --- /dev/null +++ b/Projects/Domain/UserDomain/Sources/Repository/UserRepositoryImpl.swift @@ -0,0 +1,18 @@ +import Foundation +import UserDomainInterface + +struct UserRepositoryImpl: UserRepository { + private let localUserDataSource: any LocalUserDataSource + + init(localUserDataSource: any LocalUserDataSource) { + self.localUserDataSource = localUserDataSource + } + + func saveUserRole(role: UserRoleType) { + localUserDataSource.saveUserRole(role: role) + } + + func loadUserRole() -> UserRoleType { + localUserDataSource.loadUserRole() + } +} diff --git a/Projects/Domain/UserDomain/Sources/Source.swift b/Projects/Domain/UserDomain/Sources/Source.swift deleted file mode 100644 index b1853ce6..00000000 --- a/Projects/Domain/UserDomain/Sources/Source.swift +++ /dev/null @@ -1 +0,0 @@ -// This is for Tuist diff --git a/Projects/Domain/UserDomain/Sources/UseCase/LoadUserRoleUseCaseImpl.swift b/Projects/Domain/UserDomain/Sources/UseCase/LoadUserRoleUseCaseImpl.swift new file mode 100644 index 00000000..c4e39254 --- /dev/null +++ b/Projects/Domain/UserDomain/Sources/UseCase/LoadUserRoleUseCaseImpl.swift @@ -0,0 +1,13 @@ +import UserDomainInterface + +struct LoadUserRoleUseCaseImpl: LoadUserRoleUseCase { + private let userRepository: any UserRepository + + init(userRepository: any UserRepository) { + self.userRepository = userRepository + } + + func execute() -> UserRoleType { + userRepository.loadUserRole() + } +} diff --git a/Projects/Domain/UserDomain/Sources/UseCase/SaveUserRoleUseCaseImpl.swift b/Projects/Domain/UserDomain/Sources/UseCase/SaveUserRoleUseCaseImpl.swift new file mode 100644 index 00000000..2b1ecd06 --- /dev/null +++ b/Projects/Domain/UserDomain/Sources/UseCase/SaveUserRoleUseCaseImpl.swift @@ -0,0 +1,13 @@ +import UserDomainInterface + +struct SaveUserRoleUseCaseImpl: SaveUserRoleUseCase { + private let userRepository: any UserRepository + + init(userRepository: any UserRepository) { + self.userRepository = userRepository + } + + func execute(role: UserRoleType) { + userRepository.loadUserRole() + } +} From 8850b5062f6f52ad9c497b57211d4a558b2b9cc0 Mon Sep 17 00:00:00 2001 From: baegteun Date: Sat, 10 Jun 2023 21:56:06 +0900 Subject: [PATCH 5/7] :sparkles: :: UserDomain DI --- .../Sources/Application/DI/AppComponent.swift | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Projects/App/Sources/Application/DI/AppComponent.swift b/Projects/App/Sources/Application/DI/AppComponent.swift index a75fcd09..c7d4042c 100644 --- a/Projects/App/Sources/Application/DI/AppComponent.swift +++ b/Projects/App/Sources/Application/DI/AppComponent.swift @@ -1,12 +1,8 @@ import AuthDomain import AuthDomainInterface -import StudentDomain -import StudentDomainInterface +import BaseDomain import FileDomain import FileDomainInterface -import MajorDomain -import MajorDomainInterface -import BaseDomain import InputCertificateInfoFeature import InputCertificateInfoFeatureInterface import InputInformationFeature @@ -21,15 +17,21 @@ import InputSchoolLifeInfoFeature import InputSchoolLifeInfoFeatureInterface import InputWorkInfoFeature import InputWorkInfoFeatureInterface -import RootFeature import JwtStore import JwtStoreInterface import KeychainModule import KeychainModuleInterface +import MajorDomain +import MajorDomainInterface import NeedleFoundation +import RootFeature import SigninFeature import SigninFeatureInterface +import StudentDomain +import StudentDomainInterface import SwiftUI +import UserDomain +import UserDomainInterface final class AppComponent: BootstrapComponent { func makeRootView() -> some View { @@ -88,6 +90,10 @@ final class AppComponent: BootstrapComponent { FileDomainComponent(parent: self) } + var userDomainBuildable: any UserDomainBuildable { + UserDomainComponent(parent: self) + } + var jwtStoreBuildable: any JwtStoreBuildable { JwtStoreComponent(parent: self) } From cd280d373f1c98fa88d02d91f9c785707b1adff8 Mon Sep 17 00:00:00 2001 From: baegteun Date: Sat, 10 Jun 2023 22:26:53 +0900 Subject: [PATCH 6/7] =?UTF-8?q?:sparkles:=20::=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=EC=8B=9C=20=EC=9C=A0=EC=A0=80=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Application/NeedleGenerated.swift | 22 +++++++++++++++++++ .../DataSource/RemoteAuthDataSource.swift | 2 +- .../Interface/Entity/IsAlreadySignUp.swift | 3 --- .../Entity/UserSignupInfoEntity.swift | 12 ++++++++++ .../Interface/Repository/AuthRepository.swift | 2 +- .../Interface/UseCase/LoginUseCase.swift | 2 +- Projects/Domain/AuthDomain/Project.swift | 6 ++++- .../DTO/Response/SigninResponseDTO.swift | 12 ++++++++++ .../DataSource/RemoteAuthDataSourceImpl.swift | 4 ++-- .../Repository/AuthRepositoryImpl.swift | 2 +- .../Sources/UseCase/LoginUseCaseImpl.swift | 2 +- .../Interface/Enum/UserRoleType.swift | 2 +- Projects/Feature/SigninFeature/Project.swift | 1 + .../Sources/DI/SigninComponent.swift | 5 ++++- .../Sources/Intent/SigninIntent.swift | 15 ++++++++----- 15 files changed, 74 insertions(+), 18 deletions(-) delete mode 100644 Projects/Domain/AuthDomain/Interface/Entity/IsAlreadySignUp.swift create mode 100644 Projects/Domain/AuthDomain/Interface/Entity/UserSignupInfoEntity.swift diff --git a/Projects/App/Sources/Application/NeedleGenerated.swift b/Projects/App/Sources/Application/NeedleGenerated.swift index 6cfe9e3f..4966c0c2 100644 --- a/Projects/App/Sources/Application/NeedleGenerated.swift +++ b/Projects/App/Sources/Application/NeedleGenerated.swift @@ -33,6 +33,7 @@ import SigninFeatureInterface import StudentDomain import StudentDomainInterface import SwiftUI +import UserDomain import UserDomainInterface // swiftlint:disable unused_declaration @@ -103,6 +104,9 @@ private class SigninDependencyde06a9d0b22764487733Provider: SigninDependency { var authDomainBuildable: any AuthDomainBuildable { return appComponent.authDomainBuildable } + var userDomainBuildable: any UserDomainBuildable { + return appComponent.userDomainBuildable + } private let appComponent: AppComponent init(appComponent: AppComponent) { self.appComponent = appComponent @@ -244,6 +248,17 @@ private class MajorDomainDependency4dd341ec0ebe68acad8bProvider: MajorDomainDepe private func factoryc6563cd3e82b012ec3bef47b58f8f304c97af4d5(_ component: NeedleFoundation.Scope) -> AnyObject { return MajorDomainDependency4dd341ec0ebe68acad8bProvider(appComponent: parent1(component) as! AppComponent) } +private class UserDomainDependencyf39d2a2922733361cbe1Provider: UserDomainDependency { + + + init() { + + } +} +/// ^->AppComponent->UserDomainComponent +private func factory46488402f315d7f9530ce3b0c44298fc1c149afb(_ component: NeedleFoundation.Scope) -> AnyObject { + return UserDomainDependencyf39d2a2922733361cbe1Provider() +} #else extension JwtStoreComponent: Registration { @@ -281,6 +296,7 @@ extension RootComponent: Registration { extension SigninComponent: Registration { public func registerItems() { keyPathToName[\SigninDependency.authDomainBuildable] = "authDomainBuildable-any AuthDomainBuildable" + keyPathToName[\SigninDependency.userDomainBuildable] = "userDomainBuildable-any UserDomainBuildable" } } extension InputMilitaryInfoComponent: Registration { @@ -335,6 +351,11 @@ extension MajorDomainComponent: Registration { keyPathToName[\MajorDomainDependency.jwtStoreBuildable] = "jwtStoreBuildable-any JwtStoreBuildable" } } +extension UserDomainComponent: Registration { + public func registerItems() { + + } +} #endif @@ -367,6 +388,7 @@ private func registerProviderFactory(_ componentPath: String, _ factory: @escapi registerProviderFactory("^->AppComponent->StudentDomainComponent", factory2686a7e321a220c3265af47b58f8f304c97af4d5) registerProviderFactory("^->AppComponent->AuthDomainComponent", factoryc9b20c320bb79402d4c1f47b58f8f304c97af4d5) registerProviderFactory("^->AppComponent->MajorDomainComponent", factoryc6563cd3e82b012ec3bef47b58f8f304c97af4d5) + registerProviderFactory("^->AppComponent->UserDomainComponent", factory46488402f315d7f9530ce3b0c44298fc1c149afb) } #endif diff --git a/Projects/Domain/AuthDomain/Interface/DataSource/RemoteAuthDataSource.swift b/Projects/Domain/AuthDomain/Interface/DataSource/RemoteAuthDataSource.swift index e36832f9..7bbc6961 100644 --- a/Projects/Domain/AuthDomain/Interface/DataSource/RemoteAuthDataSource.swift +++ b/Projects/Domain/AuthDomain/Interface/DataSource/RemoteAuthDataSource.swift @@ -1,5 +1,5 @@ import Foundation public protocol RemoteAuthDataSource { - func login(code: String) async throws -> IsAlreadySignUp + func login(code: String) async throws -> UserSignupInfoEntity } diff --git a/Projects/Domain/AuthDomain/Interface/Entity/IsAlreadySignUp.swift b/Projects/Domain/AuthDomain/Interface/Entity/IsAlreadySignUp.swift deleted file mode 100644 index bf2954b2..00000000 --- a/Projects/Domain/AuthDomain/Interface/Entity/IsAlreadySignUp.swift +++ /dev/null @@ -1,3 +0,0 @@ -import Foundation - -public typealias IsAlreadySignUp = Bool diff --git a/Projects/Domain/AuthDomain/Interface/Entity/UserSignupInfoEntity.swift b/Projects/Domain/AuthDomain/Interface/Entity/UserSignupInfoEntity.swift new file mode 100644 index 00000000..bc8f2762 --- /dev/null +++ b/Projects/Domain/AuthDomain/Interface/Entity/UserSignupInfoEntity.swift @@ -0,0 +1,12 @@ +import Foundation +import UserDomainInterface + +public struct UserSignupInfoEntity: Equatable { + public let isAlreadySignup: Bool + public let userRole: UserRoleType + + public init(isAlreadySignup: Bool, userRole: UserRoleType) { + self.isAlreadySignup = isAlreadySignup + self.userRole = userRole + } +} diff --git a/Projects/Domain/AuthDomain/Interface/Repository/AuthRepository.swift b/Projects/Domain/AuthDomain/Interface/Repository/AuthRepository.swift index a798f25a..25a7799d 100644 --- a/Projects/Domain/AuthDomain/Interface/Repository/AuthRepository.swift +++ b/Projects/Domain/AuthDomain/Interface/Repository/AuthRepository.swift @@ -1,5 +1,5 @@ import Foundation public protocol AuthRepository { - func login(code: String) async throws -> IsAlreadySignUp + func login(code: String) async throws -> UserSignupInfoEntity } diff --git a/Projects/Domain/AuthDomain/Interface/UseCase/LoginUseCase.swift b/Projects/Domain/AuthDomain/Interface/UseCase/LoginUseCase.swift index e552cbc1..86615c2b 100644 --- a/Projects/Domain/AuthDomain/Interface/UseCase/LoginUseCase.swift +++ b/Projects/Domain/AuthDomain/Interface/UseCase/LoginUseCase.swift @@ -1,5 +1,5 @@ import Foundation public protocol LoginUseCase { - func execute(code: String) async throws -> IsAlreadySignUp + func execute(code: String) async throws -> UserSignupInfoEntity } diff --git a/Projects/Domain/AuthDomain/Project.swift b/Projects/Domain/AuthDomain/Project.swift index 222d0b2a..3f266f2a 100644 --- a/Projects/Domain/AuthDomain/Project.swift +++ b/Projects/Domain/AuthDomain/Project.swift @@ -7,6 +7,10 @@ let project = Project.makeModule( product: .staticLibrary, targets: [.interface, .testing, .unitTest], internalDependencies: [ - .Domain.BaseDomain + .Domain.BaseDomain, + .Domain.UserDomainInterface + ], + interfaceDependencies: [ + .Domain.UserDomainInterface ] ) diff --git a/Projects/Domain/AuthDomain/Sources/DTO/Response/SigninResponseDTO.swift b/Projects/Domain/AuthDomain/Sources/DTO/Response/SigninResponseDTO.swift index 5e3e711f..d04c8dcf 100644 --- a/Projects/Domain/AuthDomain/Sources/DTO/Response/SigninResponseDTO.swift +++ b/Projects/Domain/AuthDomain/Sources/DTO/Response/SigninResponseDTO.swift @@ -1,5 +1,17 @@ +import AuthDomainInterface import Foundation +import UserDomainInterface struct SigninResponseDTO: Decodable { let isExist: Bool + let role: UserRoleType +} + +extension SigninResponseDTO { + func toDomain() -> UserSignupInfoEntity { + UserSignupInfoEntity( + isAlreadySignup: isExist, + userRole: role + ) + } } diff --git a/Projects/Domain/AuthDomain/Sources/DataSource/RemoteAuthDataSourceImpl.swift b/Projects/Domain/AuthDomain/Sources/DataSource/RemoteAuthDataSourceImpl.swift index 00909a0e..cc6fb2b3 100644 --- a/Projects/Domain/AuthDomain/Sources/DataSource/RemoteAuthDataSourceImpl.swift +++ b/Projects/Domain/AuthDomain/Sources/DataSource/RemoteAuthDataSourceImpl.swift @@ -2,8 +2,8 @@ import AuthDomainInterface import BaseDomain final class RemoteAuthDataSourceImpl: BaseRemoteDataSource, RemoteAuthDataSource { - func login(code: String) async throws -> IsAlreadySignUp { + func login(code: String) async throws -> UserSignupInfoEntity { try await request(.signin(code: code), dto: SigninResponseDTO.self) - .isExist + .toDomain() } } diff --git a/Projects/Domain/AuthDomain/Sources/Repository/AuthRepositoryImpl.swift b/Projects/Domain/AuthDomain/Sources/Repository/AuthRepositoryImpl.swift index 3ec70557..2bbdb685 100644 --- a/Projects/Domain/AuthDomain/Sources/Repository/AuthRepositoryImpl.swift +++ b/Projects/Domain/AuthDomain/Sources/Repository/AuthRepositoryImpl.swift @@ -8,7 +8,7 @@ struct AuthRepositoryImpl: AuthRepository { self.remoteAuthDataSource = remoteAuthDataSource } - func login(code: String) async throws -> IsAlreadySignUp { + func login(code: String) async throws -> UserSignupInfoEntity { try await remoteAuthDataSource.login(code: code) } } diff --git a/Projects/Domain/AuthDomain/Sources/UseCase/LoginUseCaseImpl.swift b/Projects/Domain/AuthDomain/Sources/UseCase/LoginUseCaseImpl.swift index 0e031096..9db01e24 100644 --- a/Projects/Domain/AuthDomain/Sources/UseCase/LoginUseCaseImpl.swift +++ b/Projects/Domain/AuthDomain/Sources/UseCase/LoginUseCaseImpl.swift @@ -7,7 +7,7 @@ struct LoginUseCaseImpl: LoginUseCase { self.authRepository = authRepository } - func execute(code: String) async throws -> IsAlreadySignUp { + func execute(code: String) async throws -> UserSignupInfoEntity { try await authRepository.login(code: code) } } diff --git a/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift b/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift index d0d7cbf7..4cdf1359 100644 --- a/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift +++ b/Projects/Domain/UserDomain/Interface/Enum/UserRoleType.swift @@ -1,6 +1,6 @@ import Foundation -public enum UserRoleType: String { +public enum UserRoleType: String, Codable { case student = "ROLE_STUDENT" case teacher = "ROLE_TEACHER" case guest diff --git a/Projects/Feature/SigninFeature/Project.swift b/Projects/Feature/SigninFeature/Project.swift index 0eca4dd4..69effb0b 100644 --- a/Projects/Feature/SigninFeature/Project.swift +++ b/Projects/Feature/SigninFeature/Project.swift @@ -11,6 +11,7 @@ let project = Project.makeModule( ], internalDependencies: [ .Domain.AuthDomainInterface, + .Domain.UserDomainInterface, .Feature.BaseFeature ] ) diff --git a/Projects/Feature/SigninFeature/Sources/DI/SigninComponent.swift b/Projects/Feature/SigninFeature/Sources/DI/SigninComponent.swift index 49b819b1..a21a0a71 100644 --- a/Projects/Feature/SigninFeature/Sources/DI/SigninComponent.swift +++ b/Projects/Feature/SigninFeature/Sources/DI/SigninComponent.swift @@ -1,11 +1,13 @@ import AuthDomainInterface import SwiftUI import SigninFeatureInterface +import UserDomainInterface import BaseFeature import NeedleFoundation public protocol SigninDependency: Dependency { var authDomainBuildable: any AuthDomainBuildable { get } + var userDomainBuildable: any UserDomainBuildable { get } } public final class SigninComponent: Component, SigninBuildable { @@ -14,7 +16,8 @@ public final class SigninComponent: Component, SigninBuildable let intent = SigninIntent( model: model, signinDelegate: delegate, - loginUseCase: dependency.authDomainBuildable.loginUseCase + loginUseCase: dependency.authDomainBuildable.loginUseCase, + saveUserRoleUseCase: dependency.userDomainBuildable.saveUserRoleUseCase ) let container = MVIContainer( intent: intent as SigninIntentProtocol, diff --git a/Projects/Feature/SigninFeature/Sources/Intent/SigninIntent.swift b/Projects/Feature/SigninFeature/Sources/Intent/SigninIntent.swift index 27c9d3f7..7e845a6c 100644 --- a/Projects/Feature/SigninFeature/Sources/Intent/SigninIntent.swift +++ b/Projects/Feature/SigninFeature/Sources/Intent/SigninIntent.swift @@ -1,28 +1,33 @@ import AuthDomainInterface import Combine import Foundation +import UserDomainInterface import SigninFeatureInterface final class SigninIntent: SigninIntentProtocol { private weak var model: (any SigninActionProtocol)? private weak var signinDelegate: (any SigninDelegate)? private let loginUseCase: any LoginUseCase + private let saveUserRoleUseCase: any SaveUserRoleUseCase init( model: any SigninActionProtocol, signinDelegate: any SigninDelegate, - loginUseCase: any LoginUseCase + loginUseCase: any LoginUseCase, + saveUserRoleUseCase: any SaveUserRoleUseCase ) { - self.loginUseCase = loginUseCase - self.signinDelegate = signinDelegate self.model = model + self.signinDelegate = signinDelegate + self.loginUseCase = loginUseCase + self.saveUserRoleUseCase = saveUserRoleUseCase } func signin(code: String) { Task { do { - let isAlreadySignup = try await loginUseCase.execute(code: code) - signinDelegate?.successToSignin(isAlreadySignUp: isAlreadySignup) + let userSignupInfo = try await self.loginUseCase.execute(code: code) + saveUserRoleUseCase.execute(role: userSignupInfo.userRole) + signinDelegate?.successToSignin(isAlreadySignUp: userSignupInfo.isAlreadySignup) } catch { model?.updateIsError(isError: true) } From bb1062ed966dbd5ca00070c7127faa16994e05c6 Mon Sep 17 00:00:00 2001 From: baegteun Date: Sat, 10 Jun 2023 22:48:05 +0900 Subject: [PATCH 7/7] =?UTF-8?q?:sparkles:=20::=20API=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20Test=20Double=EC=97=90=EB=8F=84=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Testing/DataSource/RemoteAuthDataSourceSpy.swift | 5 +++-- .../AuthDomain/Testing/Repository/AuthRepositorySpy.swift | 4 ++-- .../Domain/AuthDomain/Testing/UseCase/LoginUseCaseSpy.swift | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Projects/Domain/AuthDomain/Testing/DataSource/RemoteAuthDataSourceSpy.swift b/Projects/Domain/AuthDomain/Testing/DataSource/RemoteAuthDataSourceSpy.swift index 2cb31835..fd91ce51 100644 --- a/Projects/Domain/AuthDomain/Testing/DataSource/RemoteAuthDataSourceSpy.swift +++ b/Projects/Domain/AuthDomain/Testing/DataSource/RemoteAuthDataSourceSpy.swift @@ -1,12 +1,13 @@ import AuthDomainInterface +import UserDomainInterface final class RemoteAuthDataSourceSpy: RemoteAuthDataSource { var loginCallCount = 0 - func login(code: String) async throws -> IsAlreadySignUp { + func login(code: String) async throws -> UserSignupInfoEntity { loginCallCount += 1 if code.isEmpty { throw AuthDomainError.failedToGAuthSignin } - return true + return .init(isAlreadySignup: true, userRole: .guest) } } diff --git a/Projects/Domain/AuthDomain/Testing/Repository/AuthRepositorySpy.swift b/Projects/Domain/AuthDomain/Testing/Repository/AuthRepositorySpy.swift index f703f815..095a9c7d 100644 --- a/Projects/Domain/AuthDomain/Testing/Repository/AuthRepositorySpy.swift +++ b/Projects/Domain/AuthDomain/Testing/Repository/AuthRepositorySpy.swift @@ -2,11 +2,11 @@ import AuthDomainInterface final class AuthRepositorySpy: AuthRepository { var loginCallCount = 0 - func login(code: String) async throws -> IsAlreadySignUp { + func login(code: String) async throws -> UserSignupInfoEntity { loginCallCount += 1 if code.isEmpty { throw AuthDomainError.failedToGAuthSignin } - return true + return .init(isAlreadySignup: true, userRole: .guest) } } diff --git a/Projects/Domain/AuthDomain/Testing/UseCase/LoginUseCaseSpy.swift b/Projects/Domain/AuthDomain/Testing/UseCase/LoginUseCaseSpy.swift index c8ff0913..f464ddee 100644 --- a/Projects/Domain/AuthDomain/Testing/UseCase/LoginUseCaseSpy.swift +++ b/Projects/Domain/AuthDomain/Testing/UseCase/LoginUseCaseSpy.swift @@ -2,11 +2,11 @@ import AuthDomainInterface final class LoginUseCaseSpy: LoginUseCase { var callCount = 0 - func execute(code: String) async throws -> IsAlreadySignUp { + func execute(code: String) async throws -> UserSignupInfoEntity { callCount += 1 if code.isEmpty { throw AuthDomainError.failedToGAuthSignin } - return true + return .init(isAlreadySignup: true, userRole: .guest) } }