-
Notifications
You must be signed in to change notification settings - Fork 0
[#132] UserDefautls를 관리하는 객체를 Persistence 디렉토리 내에 구현한다 #133
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8c72276
feat: 프로젝트에서 사용하는 UserDefaults를 관리하기 위한 객체
opficdev de6c0de
feat: 로그아웃 하지 않고 앱을 삭제했을 경우, 앱을 재설치 했을 때 로그인 세션이 남아있는 현상을 관리하는 리포지토리 구현
opficdev 554917f
feat: PushNotificationView의 정렬/필터링 조건을 불러오거 저장하는 유즈케이스 구현
opficdev f1b4da1
feat: SearchView에서 최근 검색 기록을 불러오고 저장하는 유즈케이스 구현
opficdev 494e44a
feat: SettingView에서 앱 테마 설정을 불러오고 저장하는 유즈케이스 구현
opficdev 51161ee
feat: UserDefaults로 저장되는 키들을 관리하는 리포지토리 구현
opficdev e23bdd1
feat: 앱 테마 값을 방출하는 역할을 담당하는 객체 구현
opficdev 8619528
style: 인덴트 수정
opficdev 88737da
style: preferredColorScheme 위치 이동
opficdev d91bb89
feat: 개선된 각 레이어 객체 등록
opficdev ae4529e
feat: AppStorage 제거 및 등록된 유즈케이스를 사용하여 상태 변경
opficdev a2c4d92
refactor: 로그아웃에 실패해도 로컬 세션은 로그아웃 되도록 개선
opficdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // | ||
| // UserPreferencesRepository.swift | ||
| // DevLog | ||
| // | ||
| // Created by 최윤진 on 2/25/26. | ||
| // | ||
|
|
||
| import Foundation | ||
| import Combine | ||
|
|
||
| protocol UserPreferencesRepository { | ||
| var systemThemePublisher: AnyPublisher<SystemTheme, Never> { get } | ||
| func systemTheme() -> SystemTheme | ||
| func setSystemTheme(_ theme: SystemTheme) | ||
|
|
||
| func isFirstLaunch() -> Bool | ||
| func setFirstLaunch(_ value: Bool) | ||
|
|
||
| func recentSearchQueries() -> [String] | ||
| func setRecentSearchQueries(_ queries: [String]) | ||
|
|
||
| func pushNotificationSortOrder() -> PushNotificationQuery.SortOrder | ||
| func setPushNotificationSortOrder(_ order: PushNotificationQuery.SortOrder) | ||
|
|
||
| func pushNotificationTimeFilter() -> PushNotificationQuery.TimeFilter | ||
| func setPushNotificationTimeFilter(_ filter: PushNotificationQuery.TimeFilter) | ||
|
|
||
| func pushNotificationUnreadOnly() -> Bool | ||
| func setPushNotificationUnreadOnly(_ value: Bool) | ||
| } |
95 changes: 95 additions & 0 deletions
95
DevLog/Data/Repository/UserPreferencesRepositoryImpl.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // | ||
| // UserPreferencesRepositoryImpl.swift | ||
| // DevLog | ||
| // | ||
| // Created by 최윤진 on 2/25/26. | ||
| // | ||
|
|
||
| import Foundation | ||
| import Combine | ||
|
|
||
| final class UserPreferencesRepositoryImpl: UserPreferencesRepository { | ||
| private enum Key { | ||
| static let theme = "theme" | ||
| static let firstLaunch = "isFirstLaunch" | ||
| static let recentQueries = "Search.recentQueries" | ||
| static let pushSortOrder = "PushNotification.sortOption" | ||
| static let pushTimeFilter = "PushNotification.timeFilter" | ||
| static let pushUnreadOnly = "PushNotification.showUnreadOnly" | ||
| } | ||
|
|
||
| private let store: UserDefaultsStore | ||
| private let themeStore: ThemeStore | ||
|
|
||
| init( | ||
| store: UserDefaultsStore, | ||
| themeStore: ThemeStore | ||
| ) { | ||
| self.store = store | ||
| self.themeStore = themeStore | ||
| themeStore.send(systemTheme()) | ||
| } | ||
|
|
||
| var systemThemePublisher: AnyPublisher<SystemTheme, Never> { | ||
| themeStore.themePublisher | ||
| } | ||
|
|
||
| func systemTheme() -> SystemTheme { | ||
| guard let rawValue = store.string(forKey: Key.theme), | ||
| let theme = SystemTheme(rawValue: rawValue) else { | ||
| return .automatic | ||
| } | ||
| return theme | ||
| } | ||
|
|
||
| func setSystemTheme(_ theme: SystemTheme) { | ||
| store.setString(theme.rawValue, forKey: Key.theme) | ||
| themeStore.send(theme) | ||
| } | ||
|
|
||
| func isFirstLaunch() -> Bool { | ||
| if store.string(forKey: Key.firstLaunch) == nil { | ||
| return true | ||
| } | ||
| return store.bool(forKey: Key.firstLaunch) | ||
| } | ||
|
|
||
| func setFirstLaunch(_ value: Bool) { | ||
| store.setBool(value, forKey: Key.firstLaunch) | ||
| } | ||
|
|
||
| func recentSearchQueries() -> [String] { | ||
| store.stringArray(forKey: Key.recentQueries) | ||
| } | ||
|
|
||
| func setRecentSearchQueries(_ queries: [String]) { | ||
| store.setStringArray(queries, forKey: Key.recentQueries) | ||
| } | ||
|
|
||
| func pushNotificationSortOrder() -> PushNotificationQuery.SortOrder { | ||
| guard let rawValue = store.string(forKey: Key.pushSortOrder) else { return .latest } | ||
| return rawValue == "oldest" ? .oldest : .latest | ||
| } | ||
|
|
||
| func setPushNotificationSortOrder(_ order: PushNotificationQuery.SortOrder) { | ||
| let value = order == .oldest ? "oldest" : "latest" | ||
| store.setString(value, forKey: Key.pushSortOrder) | ||
| } | ||
|
|
||
| func pushNotificationTimeFilter() -> PushNotificationQuery.TimeFilter { | ||
| let id = store.string(forKey: Key.pushTimeFilter) ?? "none" | ||
| return PushNotificationQuery.TimeFilter(id: id) | ||
| } | ||
|
|
||
| func setPushNotificationTimeFilter(_ filter: PushNotificationQuery.TimeFilter) { | ||
| store.setString(filter.id, forKey: Key.pushTimeFilter) | ||
| } | ||
|
|
||
| func pushNotificationUnreadOnly() -> Bool { | ||
| store.bool(forKey: Key.pushUnreadOnly) | ||
| } | ||
|
|
||
| func setPushNotificationUnreadOnly(_ value: Bool) { | ||
| store.setBool(value, forKey: Key.pushUnreadOnly) | ||
| } | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
DevLog/Domain/UseCase/UserPreferences/Launch/FetchFirstLaunchUseCase.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // | ||
| // FetchFirstLaunchUseCase.swift | ||
| // DevLog | ||
| // | ||
| // Created by 최윤진 on 2/25/26. | ||
| // | ||
|
|
||
| protocol FetchFirstLaunchUseCase { | ||
| func execute() -> Bool | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
isFirstLaunch()method incorrectly usesstore.string(forKey:)to check for the existence of a Boolean value inUserDefaults. This will always evaluate totrue, causing a perpetual "first launch" state and a denial of service.