Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] Auth관련 VC들 MVVM(Combine)-C으로 변경 (#164) #165

Merged
merged 12 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 56 additions & 16 deletions LionHeart-iOS/LionHeart-iOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

49 changes: 0 additions & 49 deletions LionHeart-iOS/LionHeart-iOS/Global/Extensions/Combine+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,52 +78,3 @@ extension UIButton {
.eraseToAnyPublisher()
}
}


extension Publisher {

func tryAwaitMap<T>(_ transform: @escaping (Self.Output) async throws -> T) -> Publishers.FlatMap<Future<T, NetworkError>, Self> {
flatMap { value in
Future { promise in
Task {
do {
let result = try await transform(value)
promise(.success(result))
}
catch {
promise(.failure(error as! NetworkError))
}
}
}
}
}

func task<T>(maxPublishers: Subscribers.Demand = .unlimited, _ transform: @escaping (Output) async -> T)
-> Publishers.FlatMap<Deferred<Future<T, Never>>, Self> {
flatMap(maxPublishers: maxPublishers) { value in
Deferred {
Future { promise in
Task {
let output = await transform(value)
promise(.success(output))
}
}
}
}
}

func errorTask<T>(maxPublishers: Subscribers.Demand = .unlimited, _ transform: @escaping (Output) async throws -> T)
-> Publishers.FlatMap<Deferred<Future<T, Never>>, Self> {
flatMap(maxPublishers: maxPublishers) { value in
Deferred {
Future { promise in
Task {
let output = try await transform(value)
promise(.success(output))
}
}
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ final class LHNavigationBarView: UIView {

private let titleLabel = LHLabel(type: .head4, color: .white)

private let leftBarItem: UIButton = {
let leftBarItem: UIButton = {
let button = UIButton()
button.tintColor = .designSystem(.white)
button.marginImageWithText(margin: 14)
return button
}()

private let rightFirstBarItem: UIButton = {
let rightFirstBarItem: UIButton = {
let button = UIButton()
button.setImage(ImageLiterals.NavigationBar.bookMark, for: .normal)
button.tintColor = .designSystem(.white)
button.marginImageWithText(margin: 14)
return button
}()

private let rightSecondBarItem: UIButton = {
let rightSecondBarItem: UIButton = {
let button = UIButton()
button.setImage(ImageLiterals.NavigationBar.profile, for: .normal)
button.tintColor = .designSystem(.white)
Expand Down
4 changes: 2 additions & 2 deletions LionHeart-iOS/LionHeart-iOS/Scenes/Adaptor/AuthAdaptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

typealias EntireAuthNaviation = LoginNavigation & OnboardingNavigation & CompleteOnbardingNavigation
typealias EntireAuthNaviation = LoginNavigation & OnboardingNavigation & CompleteOnboardingNavigation

final class AuthAdaptor: EntireAuthNaviation {

Expand All @@ -21,7 +21,7 @@ final class AuthAdaptor: EntireAuthNaviation {
}

func onboardingCompleted(data: UserOnboardingModel) {
self.coordinator.showOnboardingCompleteViewController(data: data)
self.coordinator.showCompleteOnboardingViewController(data: data)
}

func startButtonTapped() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ protocol ViewModel where Self: AnyObject {

func transform(input: Input) -> Output
}

protocol LoginViewModelPresentable {
var navigator: LoginNavigation { get set } // Coordinator
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

protocol OnboardingViewControllerable where Self: UIViewController {
var navigator: OnboardingNavigation { get set }
func setKakaoAccessToken(_ token: String?)
}
//protocol OnboardingViewControllerable where Self: UIViewController {
// var navigator: OnboardingNavigation { get set }
// func setKakaoAccessToken(_ token: String?)
//}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ final class AuthCoordinatorImpl: AuthCoordinator {
splashCoorinator?.showTabbarViewContoller()
}

func showOnboardingCompleteViewController(data: UserOnboardingModel) {
let completeViewController = factory.makeCompleteOnbardingViewController(coordinator: self)
completeViewController.userData = data
func showCompleteOnboardingViewController(data: UserOnboardingModel) {
let completeViewController = factory.makeCompleteOnboardingViewController(coordinator: self, data: data)
self.navigationController.pushViewController(completeViewController, animated: true)
}

Expand All @@ -46,12 +45,10 @@ final class AuthCoordinatorImpl: AuthCoordinator {
case .verified:
splashCoorinator?.showTabbarViewContoller()
case .nonVerified:
let onboardingViewController = factory.makeOnboardingViewController(coordinator: self)
onboardingViewController.setKakaoAccessToken(kakaoToken)
let onboardingViewController = factory.makeOnboardingViewController(token: kakaoToken, coordinator: self)
DispatchQueue.main.async {
self.navigationController.pushViewController(onboardingViewController, animated: true)
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
protocol AuthCoordinator: Coordinator {
func showLoginViewController()
func showTabbarController()
func showOnboardingCompleteViewController(data: UserOnboardingModel)
func showCompleteOnboardingViewController(data: UserOnboardingModel)
func showTabbarOrOnboardingViewController(userState: UserState, kakaoToken: String?)
func pop()
func exitApplication()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,23 @@
import UIKit

struct AuthFactoryImpl: AuthFactory {
func makeCompleteOnboardingViewModel(coordinator: AuthCoordinator, data: UserOnboardingModel) -> any CompleteOnboardingViewModel & CompleteOnboardingViewModelPresentable {
let adaptor = self.makeAuthAdaptor(coordinator: coordinator)
let viewModel = CompleteOnboardingViewModelImpl(navigator: adaptor)
viewModel.setUserData(data)
return viewModel
}

func makeOnboardingViewModel(coordinator: AuthCoordinator) -> any OnboardingViewModel & OnboardingViewModelPresentable {
let adaptor = self.makeAuthAdaptor(coordinator: coordinator)
let apiService = APIService()
let serviceImpl = AuthServiceImpl(apiService: apiService)
let managerImpl = OnboardingManagerImpl(authService: serviceImpl)
return OnboardingViewModelImpl(navigator: adaptor, manager: managerImpl)
}

func makeLoginViewModel(coordinator: AuthCoordinator) -> any LoginViewModel & LoginViewModelPresentable {
let adaptor = self.makeAuthAdaptor(coordinator: coordinator)

let apiService = APIService()
let serviceImpl = AuthServiceImpl(apiService: apiService)
let managerImpl = LoginMangerImpl(authService: serviceImpl)
Expand All @@ -22,21 +35,20 @@ struct AuthFactoryImpl: AuthFactory {
return AuthAdaptor(coordinator: coordinator)
}

func makeLoginViewController(coordinator: AuthCoordinator) -> LoginViewController {
func makeLoginViewController(coordinator: AuthCoordinator) -> LoginViewControllerable {
let viewModel = self.makeLoginViewModel(coordinator: coordinator)
return LoginViewController(viewModel: viewModel)
}

func makeCompleteOnbardingViewController(coordinator: AuthCoordinator) -> CompleteOnbardingViewControllerable {
let adaptor = self.makeAuthAdaptor(coordinator: coordinator)
let completeViewController = CompleteOnbardingViewController(navigator: adaptor)
return completeViewController
func makeCompleteOnboardingViewController(coordinator: AuthCoordinator, data: UserOnboardingModel) -> CompleteOnboardingViewControllerable {
let viewModel = self.makeCompleteOnboardingViewModel(coordinator: coordinator, data: data)
return CompleteOnboardingViewController(viewModel: viewModel)
}

func makeOnboardingViewController(coordinator: AuthCoordinator) -> OnboardingViewControllerable {
let onboardingViewController = OnboardingViewController(manager: OnboardingManagerImpl(authService: AuthServiceImpl(apiService: APIService())), navigator: self.makeAuthAdaptor(coordinator: coordinator))
return onboardingViewController

func makeOnboardingViewController(token: String?, coordinator: AuthCoordinator) -> OnboardingViewControllerable {
let viewModel = self.makeOnboardingViewModel(coordinator: coordinator)
viewModel.setKakaoAccessToken(token)
return OnboardingViewController(viewModel: viewModel)
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@
import UIKit

struct SplashFactoryImpl: SplashFactory {
func makeSplashViewModel(coordinator: SplashCoordinator) -> any SplashViewModel & SplashViewModelPresentable {
let adaptor = self.makeSplashAdaptor(coordinator: coordinator)
let apiService = APIService()
let serviceImpl = AuthServiceImpl(apiService: apiService)
let managerImpl = SplashManagerImpl(authService: serviceImpl)
return SplashViewModelImpl(navigator: adaptor, manager: managerImpl)
}

func makeSplashAdaptor(coordinator: SplashCoordinator) -> EntireSplashNavigation {
return SplashAdaptor(coordinator: coordinator)
}

func makeSplashViewController(coordinator: SplashCoordinator) -> SplashViewControllerable {
return SplashViewController(manager: SplashManagerImpl(authService: AuthServiceImpl(apiService: APIService())), adaptor: self.makeSplashAdaptor(coordinator: coordinator))
let viewModel = self.makeSplashViewModel(coordinator: coordinator)
return SplashViewController(viewModel: viewModel)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
import Foundation

protocol AuthFactory {

func makeLoginViewModel(coordinator: AuthCoordinator) -> any LoginViewModel & LoginViewModelPresentable
func makeOnboardingViewModel(coordinator: AuthCoordinator) -> any OnboardingViewModel & OnboardingViewModelPresentable
func makeCompleteOnboardingViewModel(coordinator: AuthCoordinator, data: UserOnboardingModel) -> any CompleteOnboardingViewModel & CompleteOnboardingViewModelPresentable
func makeAuthAdaptor(coordinator: AuthCoordinator) -> EntireAuthNaviation

func makeLoginViewController(coordinator: AuthCoordinator) -> LoginViewController

func makeCompleteOnbardingViewController(coordinator: AuthCoordinator) -> CompleteOnbardingViewControllerable
func makeOnboardingViewController(coordinator: AuthCoordinator) -> OnboardingViewControllerable
func makeLoginViewController(coordinator: AuthCoordinator) -> LoginViewControllerable
func makeCompleteOnboardingViewController(coordinator: AuthCoordinator, data: UserOnboardingModel) -> CompleteOnboardingViewControllerable
func makeOnboardingViewController(token: String?, coordinator: AuthCoordinator) -> OnboardingViewControllerable
}


Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import UIKit

protocol SplashFactory {
func makeSplashViewModel(coordinator: SplashCoordinator) -> any SplashViewModel & SplashViewModelPresentable
func makeSplashAdaptor(coordinator: SplashCoordinator) -> EntireSplashNavigation
func makeSplashViewController(coordinator: SplashCoordinator) -> SplashViewControllerable
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import UIKit
import SnapKit
import Combine

protocol LoginViewControllerable where Self: UIViewController {}

final class LoginViewController: UIViewController {
final class LoginViewController: UIViewController, LoginViewControllerable {

// MARK: - Properties

Expand Down
2 changes: 2 additions & 0 deletions LionHeart-iOS/LionHeart-iOS/Scenes/Login/LoginViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import Foundation
import Combine

protocol LoginViewModelPresentable {}

protocol LoginViewModel: ViewModel where Input == LoginViewModelInput, Output == LoginViewModelOutput {}

struct LoginViewModelInput {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// CompleteOnbardingNavigation.swift
// CompleteOnbordingNavigation.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol CompleteOnbardingNavigation: ExpireNavigation {
protocol CompleteOnboardingNavigation: ExpireNavigation {
func startButtonTapped()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,3 @@ enum OnbardingFlowType: Int {
case toFetalNickname
case toCompleteOnboarding
}

extension OnboardingPageType {

var progressValue: Float {
switch self {
case .getPregnancy:
return .half
case .getFetalNickname:
return .full
}
}

var forward: OnbardingFlowType {
switch self {
case .getPregnancy:
return .toFetalNickname
case .getFetalNickname:
return .toCompleteOnboarding
}
}
}
Loading