Skip to content

Commit

Permalink
refactor: 마이페이지 저장값 앱서비스로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
devMinseok committed Aug 21, 2024
1 parent d25406e commit 5c294a3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
33 changes: 33 additions & 0 deletions Projects/Domain/AppService/Sources/AppService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Logger
import DatabaseClientInterface
import UserDefaultsClientInterface

import RealmSwift

Expand All @@ -32,3 +33,35 @@ public func initilizeDatabaseSystem(

try await databaseClient.initialize(configuration)
}


let isDisturbAlarmOnKey = "mohanyang_userdefaults_isDisturmAlarmOnKey"

public func setDisturbAlarm(
userDefaultsClient: UserDefaultsClient,
isEnabled: Bool
) async -> Void {
await userDefaultsClient.setBool(isEnabled, isDisturbAlarmOnKey)
}

public func getDisturbAlarm(
userDefaultsClient: UserDefaultsClient
) -> Bool {
return userDefaultsClient.boolForKey(isDisturbAlarmOnKey)
}


let isTimerAlarmOnKey = "mohanyang_userdefaults_isTimerAlarmOnKey"

public func setTimerAlarm(
userDefaultsClient: UserDefaultsClient,
isEnabled: Bool
) async -> Void {
await userDefaultsClient.setBool(isEnabled, isTimerAlarmOnKey)
}

public func getTimerAlarm(
userDefaultsClient: UserDefaultsClient
) -> Bool {
return userDefaultsClient.boolForKey(isTimerAlarmOnKey)
}
18 changes: 11 additions & 7 deletions Projects/Feature/MyPageFeature/Sources/MyPage/MyPageCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import UserServiceInterface
import CatServiceInterface
import UserDefaultsClientInterface
import NetworkTrackingInterface
import AppService

import ComposableArchitecture

Expand Down Expand Up @@ -41,9 +42,6 @@ public struct MyPageCore {
@Dependency(APIClient.self) var apiClient
@Dependency(UserService.self) var userService
@Dependency(UserDefaultsClient.self) var userDefaultsClient
@Dependency(NetworkTracking.self) var networkTracking
let isTimerAlarmOnKey = "mohanyang_userdefaults_isTimerAlarmOnKey"
let isDisturbAlarmOnKey = "mohanyang_userdefaults_isDisturmAlarmOnKey"

public init() {}

Expand All @@ -58,8 +56,8 @@ public struct MyPageCore {
private func core(state: inout State, action: Action) -> EffectOf<Self> {
switch action {
case .onAppear:
state.isTimerAlarmOn = userDefaultsClient.boolForKey(isTimerAlarmOnKey)
state.isDisturbAlarmOn = userDefaultsClient.boolForKey(isDisturbAlarmOnKey)
state.isTimerAlarmOn = getTimerAlarm(userDefaultsClient: self.userDefaultsClient)
state.isDisturbAlarmOn = getDisturbAlarm(userDefaultsClient: self.userDefaultsClient)
return .run { send in
let data = try await userService.getUserInfo(apiClient: apiClient)
await send(._responseUserInfo(data))
Expand Down Expand Up @@ -94,12 +92,18 @@ public struct MyPageCore {

case .binding(\.isTimerAlarmOn):
return .run { [isTimerAlarmOn = state.isTimerAlarmOn] _ in
await userDefaultsClient.setBool(isTimerAlarmOn, isTimerAlarmOnKey)
await setTimerAlarm(
userDefaultsClient: self.userDefaultsClient,
isEnabled: isTimerAlarmOn
)
}

case .binding(\.isDisturbAlarmOn):
return .run { [isDisturbAlarmOn = state.isDisturbAlarmOn] _ in
await userDefaultsClient.setBool(isDisturbAlarmOn, isDisturbAlarmOnKey)
await setDisturbAlarm(
userDefaultsClient: self.userDefaultsClient,
isEnabled: isDisturbAlarmOn
)
}

case .binding:
Expand Down

0 comments on commit 5c294a3

Please sign in to comment.