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 [#114] OnboardingFeature 리펙토링 #121

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PickerCoordinator: NSObject, UIPickerViewDelegate, UIPickerViewDataSource

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
selectedTime.wrappedValue = times[row]
viewModel.isCompleted = true
// viewModel.isCompleted = true
}

func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// LoginUseCase.swift
// LoginFeature
//
// Created by Seonwoo Kim on 11/8/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
//

import Foundation
import Combine

import Domain
import Core

public enum LoginResponseType {
case loginSuccess
case loginFailure
case onboardingNeeded
}

public protocol LoginUseCaseType {
func login(provider: OAuthProviderType) -> AnyPublisher<LoginResponseType, AuthError>
}

public final class LoginUseCase: LoginUseCaseType {

private let repository: AuthRepositoryType

public init(repository: AuthRepositoryType) {
self.repository = repository
}

public func login(provider: OAuthProviderType) -> AnyPublisher<LoginResponseType, Domain.AuthError> {
repository.authorize(provider)
.handleEvents(receiveOutput: { socialToken in
UserManager.shared.socialToken = socialToken
})
.flatMap { [weak self] _ -> AnyPublisher<LoginResponseType, AuthError> in
guard let self = self else {
return Fail(error: AuthError.appleAuthrizeError).eraseToAnyPublisher()
}

return self.repository.socialLogin(socialPlatform: provider.rawValue)
.map { _ in LoginResponseType.loginSuccess }
.catch { error -> AnyPublisher<LoginResponseType, AuthError> in
switch error {
case .unregisteredUser:
return Just(.onboardingNeeded)
.setFailureType(to: AuthError.self)
.eraseToAnyPublisher()
default:
return Just(.loginFailure)
.setFailureType(to: AuthError.self)
.eraseToAnyPublisher()
}
}
.eraseToAnyPublisher()
}
.eraseToAnyPublisher()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,36 @@
//

import Foundation
import DSKit

struct SurveyButtonInfo: Identifiable {
let id = UUID()
var buttonTitle: String
var isSelected: Bool
}

extension SurveyButtonInfo {
static func initializeSurveyButtonItems() -> [[SurveyButtonInfo]] {
return [
[
SurveyButtonInfo(buttonTitle: StringLiteral.TimeSurveySelect.firstSelect, isSelected: false),
SurveyButtonInfo(buttonTitle: StringLiteral.TimeSurveySelect.secondSelect, isSelected: false),
SurveyButtonInfo(buttonTitle: StringLiteral.TimeSurveySelect.thirdSelect, isSelected: false),
SurveyButtonInfo(buttonTitle: StringLiteral.TimeSurveySelect.fourthSelect, isSelected: false),
],
[
SurveyButtonInfo(buttonTitle: StringLiteral.ProblemSurveySelect.firstSelect, isSelected: false),
SurveyButtonInfo(buttonTitle: StringLiteral.ProblemSurveySelect.secondSelect, isSelected: false),
SurveyButtonInfo(buttonTitle: StringLiteral.ProblemSurveySelect.thirdSelect, isSelected: false),
SurveyButtonInfo(buttonTitle: StringLiteral.ProblemSurveySelect.fourthSelect, isSelected: false),
],
[
SurveyButtonInfo(buttonTitle: StringLiteral.PeriodSelect.firstSelect, isSelected: false),
SurveyButtonInfo(buttonTitle: StringLiteral.PeriodSelect.secondSelect, isSelected: false),
SurveyButtonInfo(buttonTitle: StringLiteral.PeriodSelect.thirdSelect, isSelected: false),
SurveyButtonInfo(buttonTitle: StringLiteral.PeriodSelect.fourthSelect, isSelected: false),
]
]
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// OnboardingState.swift
// OnboardingFeature
//
// Created by Seonwoo Kim on 11/23/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
//

import Foundation
import DSKit

enum OnboardingState: Int {
case timeSurveySelect = 0
case problemSurveySelect
case challangePeriodSelect
case goalTimeSelect
case permissionSelect
}

extension OnboardingState {
var mainTitle: String {
switch self {
case .timeSurveySelect:
return StringLiteral.OnboardigMain.timeSurveySelect
case .problemSurveySelect:
return StringLiteral.OnboardigMain.problemSurveySelect
case .challangePeriodSelect:
return StringLiteral.OnboardigMain.periodSelect
case .permissionSelect:
return StringLiteral.OnboardigMain.permissionSelect
case .goalTimeSelect:
return StringLiteral.OnboardigMain.appGoalTimeSelect
}
}

var subTitle: String {
switch self {
case .timeSurveySelect:
return ""
case .problemSurveySelect:
return StringLiteral.OnboardigSub.problemSurveySelect
case .challangePeriodSelect:
return StringLiteral.OnboardigSub.periodSelect
case .permissionSelect:
return StringLiteral.OnboardigSub.permissionSelect
case .goalTimeSelect:
return StringLiteral.OnboardigSub.appGoalTimeSelect
}
}

var nextButtonTitle: String {
switch self {
case .timeSurveySelect, .problemSurveySelect, .challangePeriodSelect, .goalTimeSelect:
return StringLiteral.OnboardingButton.next
case .permissionSelect:
return StringLiteral.OnboardingButton.permission
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// OnboardingUseCase.swift
// OnboardingFeatureInterface
//
// Created by Seonwoo Kim on 11/18/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
//

import Foundation
import Combine

import Domain
import Core

public protocol OnboardingUseCaseType {
func postSignUpData(
socialPlatform: String,
userName: String,
averageUseTime: String,
problems: [String],
period: Int,
goalTime: Int
) -> AnyPublisher<Void, Error>
func calculateGoalTime(hour: String, minute: String) -> Int
func removeLastCharacterAndConvertToInt(from string: String) -> Int?
}

public final class OnboardingUseCase: OnboardingUseCaseType {

private let repository: AuthRepositoryType

public init(repository: AuthRepositoryType) {
self.repository = repository
}

public func postSignUpData(
socialPlatform: String,
userName: String,
averageUseTime: String,
problems: [String],
period: Int,
goalTime: Int
) -> AnyPublisher<Void, Error> {
let challengeInfo = ChallengeInfo(period: period, goalTime: goalTime, apps: [])

return repository.signUp(
socialPlatform: socialPlatform,
name: userName,
averageUseTime: averageUseTime,
problem: problems,
challengeInfo: challengeInfo
)
.map { auth -> Void in
// UserManager.shared.accessToken = auth.accessToken
// UserManager.shared.refreshToken = auth.refreshToken
}
.mapError { error -> Error in

return error
}
.eraseToAnyPublisher()
}

public func calculateGoalTime(hour: String, minute: String) -> Int {
let hourInt = Int(hour) ?? 0
let minuteInt = Int(minute) ?? 0

let totalMinutes = hourInt * 60 + minuteInt
let totalMilliseconds = totalMinutes * 60 * 1000
return totalMilliseconds
}

public func removeLastCharacterAndConvertToInt(from string: String) -> Int? {
guard !string.isEmpty else {
return nil
}

let modifiedString = String(string.dropLast())

return Int(modifiedString)
}
}

Loading