From f88c2e38f5d49fdd86d842a166a8fc1d7314274a Mon Sep 17 00:00:00 2001 From: HELLOHIDI Date: Sun, 24 Nov 2024 02:40:55 +0900 Subject: [PATCH] =?UTF-8?q?[Feat/#118]=20=ED=99=94=EB=A9=B4=EC=A0=84?= =?UTF-8?q?=ED=99=98=EC=BD=94=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Demo/Sources/AuthServiceTestView.swift | 9 - .../Demo/Sources/Navigation/DIContainer.swift | 32 ++++ .../Navigation/NavigationDestination.swift | 3 +- .../Sources/Navigation/NavigationRouter.swift | 87 +++++----- .../Navigation/NavigationRoutingView.swift | 156 +++++++----------- .../Demo/Sources/NetworkDemoApp.swift | 3 + .../Demo/Sources/NetworkTestHomeView.swift | 20 +-- .../AuthServiceTest/AuthServiceView.swift | 7 +- .../AuthServiceViewModel.swift | 7 +- .../ChallengeServiceView.swift | 8 +- .../ChallengeServiceViewModel.swift | 10 +- .../PointServiceTest/PointServiceView.swift | 7 +- .../PointServiceViewModel.swift | 12 +- .../UserServiceTest/UserServiceView.swift | 7 +- .../UserServiceViewModel.swift | 7 +- .../Networks/Demo/Sources/ServiceType.swift | 8 +- .../Sources/Service/Auth/AuthService.swift | 7 +- .../Service/Challenge/ChallengeService.swift | 20 ++- .../Sources/Service/HMHServiceType.swift | 32 ++++ .../Sources/Service/User/UserService.swift | 12 +- 20 files changed, 256 insertions(+), 198 deletions(-) delete mode 100644 HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/AuthServiceTestView.swift create mode 100644 HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/DIContainer.swift create mode 100644 HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/HMHServiceType.swift diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/AuthServiceTestView.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/AuthServiceTestView.swift deleted file mode 100644 index b5d55454..00000000 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/AuthServiceTestView.swift +++ /dev/null @@ -1,9 +0,0 @@ -// -// AuthServiceTestView.swift -// NetworksDemo -// -// Created by 류희재 on 11/21/24. -// Copyright © 2024 HMH-iOS. All rights reserved. -// - -import Foundation diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/DIContainer.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/DIContainer.swift new file mode 100644 index 00000000..4425f930 --- /dev/null +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/DIContainer.swift @@ -0,0 +1,32 @@ +// +// DIContainer.swift +// NetworksDemo +// +// Created by 류희재 on 11/23/24. +// Copyright © 2024 HMH-iOS. All rights reserved. +// + +import Foundation + +typealias NavigationRoutableType = NavigationRoutable & ObservableObjectSettable + +final class DIContainer: ObservableObject { + + var service: HMHServiceType + var navigationRouter: NavigationRoutableType + + private init( + service: HMHServiceType, + navigationRouter: NavigationRoutableType = NavigationRouter() + ) { + self.service = service + self.navigationRouter = navigationRouter + + navigationRouter.setObjectWillChange(objectWillChange) + } +} + +extension DIContainer { + static let `default` = DIContainer(service: HMHService()) + static let stub = DIContainer(service: StubHMHSerivce()) +} diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationDestination.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationDestination.swift index e23321ec..c5debf1a 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationDestination.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationDestination.swift @@ -9,11 +9,10 @@ import Foundation enum NavigationDestination: Hashable { - case auth case challenge case point case user - + case home } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationRouter.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationRouter.swift index 6b1922e3..8a217920 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationRouter.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationRouter.swift @@ -6,41 +6,52 @@ //// Copyright © 2024 HMH-iOS. All rights reserved. //// // -//import Foundation -//import Combine -// -//protocol NavigationRoutable { -// var destinations: [NavigationDestination] { get set } -// -// func push(to view: NavigationDestination) -// func pop() -// func popToRootView() -//} -// -// -//class NavigationRouter: NavigationRoutable, ObservableObjectSettable { -// -// var objectWillChange: ObservableObjectPublisher? -// -// var destinations: [NavigationDestination] = [] { -// didSet { -// objectWillChange?.send() -// } -// } -// -// func push(to view: NavigationDestination) { -// destinations.append(view) -// } -// -// func pop() { -// _ = destinations.popLast() -// } -// -// func popToRootView() { -// destinations = [] -// } -// -// -//} -// -// +import Foundation +import Combine + +import Combine + +protocol ObservableObjectSettable: AnyObject { + var objectWillChange: ObservableObjectPublisher? { get set } + func setObjectWillChange(_ objectWillChange: ObservableObjectPublisher?) +} + +extension ObservableObjectSettable { + func setObjectWillChange(_ objectWillChange: ObservableObjectPublisher?) { + self.objectWillChange = objectWillChange + } +} + +protocol NavigationRoutable { + var destinations: [NavigationDestination] { get set } + + func push(to view: NavigationDestination) + func pop() + func popToRootView() +} + + +class NavigationRouter: NavigationRoutable, ObservableObjectSettable { + + var objectWillChange: ObservableObjectPublisher? + + var destinations: [NavigationDestination] = [] { + didSet { + objectWillChange?.send() + } + } + + func push(to view: NavigationDestination) { + destinations.append(view) + } + + func pop() { + _ = destinations.popLast() + } + + func popToRootView() { + destinations = [] + } +} + + diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationRoutingView.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationRoutingView.swift index 9c62b2fc..7fbe87a6 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationRoutingView.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/Navigation/NavigationRoutingView.swift @@ -6,100 +6,62 @@ //// Copyright © 2024 HMH-iOS. All rights reserved. //// // -//import Foundation -//import SwiftUI -// -//struct NavigationRoutingView: View { -// -// @EnvironmentObject var container: DIContainer -// @State var destination: NavigationDestination -// -// var body: some View { -// switch destination { -// case let .editRoom(viewType): -// EditRoomInfoView( -// viewModel: .init( -// viewType: viewType, -// roomService: container.service.roomService, -// navigationRouter: container.navigationRouter -// )) -// case let .makeMission(roomInfo): -// EditMissionView( -// viewModel: EditMissionViewModel( -// roomInfo: roomInfo, -// navigationRouter: container.navigationRouter -// ) -// ) -// case let .roomInfo(roomInfo, missionList): -// CheckRoomInfoView( -// viewModel: .init( -// roomInfo: roomInfo, -// missionList: missionList, -// roomService: container.service.roomService, -// navigationRouter: container.navigationRouter -// ) -// ) -// -// case .enterRoom: -// EnterRoomView( -// viewModel: .init( -// roomService: container.service.roomService, -// navigationRouter: container.navigationRouter -// ) -// ) -// case let .manitoWaitingRoom(roomDetail): -// ManitoWaitingRoomView( -// viewModel: .init( -// roomService: container.service.roomService, -// navigationRouter: container.navigationRouter, -// roomDetail: roomDetail -// ) -// ) -// -// case .myPage: -// MyPageView(viewModel: MyPageViewModel(navigationRouter: container.navigationRouter)) -// -// case .editUsername: -// EditUsernameView( -// viewModel: EditUsernameViewModel( -// userService: container.service.userService, -// navigationRouter: container.navigationRouter, -// windowRouter: container.windowRouter -// ) -// ) -// -// case .matchRoom(let roomID): -// MatchingView( -// viewModel: MatchingViewModel( -// roomService: container.service.roomService, -// navigationRouter: container.navigationRouter, -// roomID: roomID -// ) -// ) -// case .matchedRoom(let roomDetail): -// MatchingResultView( -// viewModel: MatchingResultViewModel( -// roomService: container.service.roomService, -// navigationRouter: container.navigationRouter, -// roomInfo: roomDetail -// ) -// ) -// case .finish(let roomDetail): -// FinishView(viewModel: FinishViewModel(roomService: container.service.roomService, navigationRouter: container.navigationRouter, roomInfo: roomDetail)) -// } -// -// } -//} -// -// -//extension View { -// -// func setSMNavigation() -> some View { -// self.navigationDestination(for: NavigationDestination.self) { destination in -// return NavigationRoutingView(destination: destination) -// } -// } -// -// -//} -// +import Foundation +import SwiftUI +import Networks + +struct NavigationRoutingView: View { + + @State var destination: NavigationDestination + @EnvironmentObject var container: DIContainer + + var body: some View { + switch destination { + case .home: + NetworkTestHomeView() + case .auth: + AuthServiceView( + viewModel: AuthServiceViewModel( + service: container.service.authService, + navigationRouter: container.navigationRouter + ) + ) + case .challenge: + ChallengeServiceView( + viewModel: ChallengeServiceViewModel( + service: container.service.challengeService, + navigationRouter: container.navigationRouter + ) + ) + .environmentObject(DIContainer.default) + case .point: + PointServiceView( + viewModel: PointServiceViewModel( + service: container.service.pointService, + navigationRouter: container.navigationRouter + ) + ) + case .user: + UserServiceView( + viewModel: UserServiceViewModel( + service: container.service.userService, + navigationRouter: container.navigationRouter + ) + ) + } + + } +} + + +extension View { + + func setHMHNavigation() -> some View { + self.navigationDestination(for: NavigationDestination.self) { destination in + return NavigationRoutingView(destination: destination) + } + } + + +} + diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/NetworkDemoApp.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/NetworkDemoApp.swift index 29eb5580..4b245433 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/NetworkDemoApp.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/NetworkDemoApp.swift @@ -20,9 +20,12 @@ struct NetworkTestApp: App { // print(Networks.Config.baseURL) } + @StateObject var container = DIContainer.default + var body: some Scene { WindowGroup { NetworkTestHomeView() + .environmentObject(container) } } } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/NetworkTestHomeView.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/NetworkTestHomeView.swift index 8dcf815d..89d68515 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/NetworkTestHomeView.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/NetworkTestHomeView.swift @@ -13,9 +13,10 @@ import Core //디버그(Debug) 모드와 릴리즈(Release) 모드에서 Xcode의 프리뷰(Preview) 활성화 여부 다름 So QA를 다시 debug로 변경 struct NetworkTestHomeView: View { + @EnvironmentObject var container: DIContainer var body: some View { - NavigationView { + NavigationStack(path: $container.navigationRouter.destinations) { VStack(alignment: .center) { Spacer() .frame(height: 25) @@ -51,8 +52,8 @@ struct NetworkTestHomeView: View { Spacer() ServiceButton( imageResource: .auth, - title: "Point") { - print("포인트 서비스 테스트로 이동") + title: "Auth") { + container.navigationRouter.push(to: .auth) } Spacer() @@ -61,7 +62,7 @@ struct NetworkTestHomeView: View { ServiceButton( imageResource: .challenge, title: "Challenge") { - print("포인트 서비스 테스트로 이동") + container.navigationRouter.push(to: .challenge) } Spacer() @@ -77,13 +78,7 @@ struct NetworkTestHomeView: View { ServiceButton( imageResource: .point, title: "Point") { -// NavigationLink(<#LocalizedStringKey#>, destination: PointServiceView( -// viewModel: PointServiceViewModel( -// service: PointService() -// ) -// ) -// ) -// + container.navigationRouter.push(to: .point) } Spacer() @@ -92,7 +87,7 @@ struct NetworkTestHomeView: View { ServiceButton( imageResource: .user, title: "User") { - print("포인트 서비스 테스트로 이동") + container.navigationRouter.push(to: .user) } Spacer() @@ -144,5 +139,6 @@ fileprivate struct ServiceButton : View { #Preview { return NetworkTestHomeView() + .environmentObject(DIContainer.default) } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/AuthServiceTest/AuthServiceView.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/AuthServiceTest/AuthServiceView.swift index 5e33fc2d..f29c9f03 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/AuthServiceTest/AuthServiceView.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/AuthServiceTest/AuthServiceView.swift @@ -12,7 +12,7 @@ import Core import Combine struct AuthServiceView: View { - + @EnvironmentObject var container: DIContainer @StateObject var viewModel: AuthServiceViewModel var body: some View { @@ -152,10 +152,13 @@ fileprivate struct ServiceCellView: View { } #Preview { + let container = DIContainer.stub return AuthServiceView( viewModel: AuthServiceViewModel( - service: AuthService() + service: container.service.authService, + navigationRouter: container.navigationRouter ) ) + .environmentObject(container) } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/AuthServiceTest/AuthServiceViewModel.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/AuthServiceTest/AuthServiceViewModel.swift index b794b3b8..39bafcf5 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/AuthServiceTest/AuthServiceViewModel.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/AuthServiceTest/AuthServiceViewModel.swift @@ -26,11 +26,14 @@ class AuthServiceViewModel: ObservableObject { //MARK: Dependency - let service: AuthServiceType + private let service: AuthServiceType + private var navigationRouter: NavigationRoutableType // MARK: - Init - init(service: AuthServiceType) { + + init(service: AuthServiceType, navigationRouter: NavigationRoutableType) { self.service = service + self.navigationRouter = navigationRouter self.state = State() } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/ChallengeServiceTest/ChallengeServiceView.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/ChallengeServiceTest/ChallengeServiceView.swift index ba4e78a6..00c95575 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/ChallengeServiceTest/ChallengeServiceView.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/ChallengeServiceTest/ChallengeServiceView.swift @@ -12,7 +12,7 @@ import Core import Combine struct ChallengeServiceView: View { - + @EnvironmentObject var container: DIContainer @StateObject var viewModel: ChallengeServiceViewModel var body: some View { @@ -157,9 +157,13 @@ fileprivate struct ServiceCellView: View { } #Preview { + let container = DIContainer.stub return ChallengeServiceView( viewModel: ChallengeServiceViewModel( - service: ChallengeService() + service: container.service.challengeService, + navigationRouter: container.navigationRouter ) ) + .environmentObject(container) } + diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/ChallengeServiceTest/ChallengeServiceViewModel.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/ChallengeServiceTest/ChallengeServiceViewModel.swift index d761a8c1..769d56c4 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/ChallengeServiceTest/ChallengeServiceViewModel.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/ChallengeServiceTest/ChallengeServiceViewModel.swift @@ -26,11 +26,17 @@ class ChallengeServiceViewModel: ObservableObject { //MARK: Dependency - let service: ChallengeServiceType + private let service: ChallengeServiceType + private var navigationRouter: NavigationRoutableType // MARK: - Init - init(service: ChallengeServiceType) { + + init( + service: ChallengeServiceType, + navigationRouter: NavigationRoutableType + ) { self.service = service + self.navigationRouter = navigationRouter self.state = State() } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/PointServiceTest/PointServiceView.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/PointServiceTest/PointServiceView.swift index 0f6bbb49..dab40250 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/PointServiceTest/PointServiceView.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/PointServiceTest/PointServiceView.swift @@ -12,7 +12,7 @@ import Core import Combine struct PointServiceView: View { - + @EnvironmentObject var container: DIContainer @StateObject var viewModel: PointServiceViewModel var body: some View { @@ -156,11 +156,14 @@ fileprivate struct ServiceCellView: View { } #Preview { + let container = DIContainer.stub return PointServiceView( viewModel: PointServiceViewModel( - service: PointService() + service: container.service.pointService, + navigationRouter: container.navigationRouter ) ) + .environmentObject(container) } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/PointServiceTest/PointServiceViewModel.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/PointServiceTest/PointServiceViewModel.swift index f76db109..0abb6bc1 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/PointServiceTest/PointServiceViewModel.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/PointServiceTest/PointServiceViewModel.swift @@ -26,15 +26,17 @@ class PointServiceViewModel: ObservableObject { //MARK: Dependency - let service: PointServiceType + private let service: PointServiceType + private var navigationRouter: NavigationRoutableType //MARK: Init - - - // MARK: - Init - init(service: PointServiceType) { + init( + service: PointServiceType, + navigationRouter: NavigationRoutableType + ) { self.service = service + self.navigationRouter = navigationRouter self.state = State() } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/UserServiceTest/UserServiceView.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/UserServiceTest/UserServiceView.swift index e1d97d66..1a46fefd 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/UserServiceTest/UserServiceView.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/UserServiceTest/UserServiceView.swift @@ -12,7 +12,7 @@ import Core import Combine struct UserServiceView: View { - + @EnvironmentObject var container: DIContainer @StateObject var viewModel: UserServiceViewModel var body: some View { @@ -154,9 +154,12 @@ fileprivate struct ServiceCellView: View { } #Preview { + let container = DIContainer.stub return UserServiceView( viewModel: UserServiceViewModel( - service: UserService() + service: container.service.userService, + navigationRouter: container.navigationRouter ) ) + .environmentObject(container) } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/UserServiceTest/UserServiceViewModel.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/UserServiceTest/UserServiceViewModel.swift index fa4bc2b3..6e87de57 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/UserServiceTest/UserServiceViewModel.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceTest/UserServiceTest/UserServiceViewModel.swift @@ -26,11 +26,14 @@ class UserServiceViewModel: ObservableObject { //MARK: Dependency - let service: UserServiceType + private let service: UserServiceType + private var navigationRouter: NavigationRoutableType // MARK: - Init - init(service: UserServiceType) { + + init(service: UserServiceType, navigationRouter: NavigationRoutableType) { self.service = service + self.navigationRouter = navigationRouter self.state = State() } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceType.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceType.swift index 2a8a3ea6..dc872cbb 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceType.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Demo/Sources/ServiceType.swift @@ -10,10 +10,10 @@ import Foundation import Networks enum ServiceType { - case auth(AuthService) - case point(PointService) - case challenge(ChallengeService) - case user(UserService) + case auth + case point + case challenge + case user var title: String { switch self { diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/Auth/AuthService.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/Auth/AuthService.swift index a4b95865..facc8f62 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/Auth/AuthService.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/Auth/AuthService.swift @@ -26,13 +26,14 @@ extension AuthService: AuthServiceType { } } -struct StubAuthService: AuthServiceType { - func signUp(request: SignUpRequest) -> AnyPublisher { +public struct StubAuthService: AuthServiceType { + public init() {} + public func signUp(request: SignUpRequest) -> AnyPublisher { return Just(.stub) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func socialLogin(request: SocialLoginRequest) -> AnyPublisher { + public func socialLogin(request: SocialLoginRequest) -> AnyPublisher { return Just(.stub) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/Challenge/ChallengeService.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/Challenge/ChallengeService.swift index f19d0feb..5c89e8b5 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/Challenge/ChallengeService.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/Challenge/ChallengeService.swift @@ -56,50 +56,52 @@ extension ChallengeService: ChallengeServiceType { } } -struct StubChallengeService: ChallengeServiceType { - func getDailyChallenge() -> AnyPublisher { +public struct StubChallengeService: ChallengeServiceType { + public init() {} + + public func getDailyChallenge() -> AnyPublisher { return Just(.stub1) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func getSuccesChallenge() -> AnyPublisher { + public func getSuccesChallenge() -> AnyPublisher { return Just(.stub) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func createChallenge(request: CreateChallengeRequest) -> AnyPublisher { + public func createChallenge(request: CreateChallengeRequest) -> AnyPublisher { return Just(()) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func getLockChallenge() -> AnyPublisher { + public func getLockChallenge() -> AnyPublisher { return Just(.stub) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func postLockChallenge() -> AnyPublisher { + public func postLockChallenge() -> AnyPublisher { return Just(()) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func deleteApp(request: DeleteAppRequest) -> AnyPublisher { + public func deleteApp(request: DeleteAppRequest) -> AnyPublisher { return Just(()) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func addApp(request: AddAppRequest) -> AnyPublisher { + public func addApp(request: AddAppRequest) -> AnyPublisher { return Just(()) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func getChallenge() -> AnyPublisher { + public func getChallenge() -> AnyPublisher { return Just(.stub1) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/HMHServiceType.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/HMHServiceType.swift new file mode 100644 index 00000000..8ab09232 --- /dev/null +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/HMHServiceType.swift @@ -0,0 +1,32 @@ +// +// HMHServiceType.swift +// NetworksDemo +// +// Created by 류희재 on 11/24/24. +// Copyright © 2024 HMH-iOS. All rights reserved. +// + +import Foundation +import Networks + + +protocol HMHServiceType { + var authService: AuthServiceType { get } + var challengeService: ChallengeServiceType { get } + var pointService: PointServiceType { get } + var userService: UserServiceType { get } +} + +final class HMHService: HMHServiceType { + var authService: AuthServiceType = AuthService() + var challengeService: ChallengeServiceType = ChallengeService() + var pointService: PointServiceType = PointService() + var userService: UserServiceType = UserService() +} + +final class StubHMHSerivce: HMHServiceType { + var authService: AuthServiceType = StubAuthService() + var challengeService: ChallengeServiceType = StubChallengeService() + var pointService: PointServiceType = StubPointService() + var userService: UserServiceType = StubUserService() +} diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/User/UserService.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/User/UserService.swift index 4031d3d5..71441456 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/User/UserService.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Service/User/UserService.swift @@ -38,26 +38,28 @@ extension UserService: UserServiceType { } } -struct StubUserService: UserServiceType { - func logout() -> AnyPublisher { +public struct StubUserService: UserServiceType { + public init() {} + + public func logout() -> AnyPublisher { return Just(()) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func deleteAccount() -> AnyPublisher { + public func deleteAccount() -> AnyPublisher { return Just(()) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func getUserData() -> AnyPublisher { + public func getUserData() -> AnyPublisher { return Just(.stub) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher() } - func getCurrentPoint() -> AnyPublisher { + public func getCurrentPoint() -> AnyPublisher { return Just(.stub) .setFailureType(to: HMHNetworkError.self) .eraseToAnyPublisher()