Skip to content

Commit

Permalink
#127 #128 refactor: SettingsUseCase의 닉네임 변경 로직을 ChangeUserNameUseCase…
Browse files Browse the repository at this point in the history
…로 이동
  • Loading branch information
LEEYOONJONG committed Nov 30, 2022
1 parent af236d8 commit 9908d4b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 19 deletions.
8 changes: 8 additions & 0 deletions Segno/Segno.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
7940FB2F292E063100276EFC /* DiaryDetailDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7940FB2E292E063100276EFC /* DiaryDetailDTO.swift */; };
7940FB31292E065100276EFC /* DiaryDetailEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7940FB30292E065100276EFC /* DiaryDetailEndpoint.swift */; };
7940FB33292E065F00276EFC /* DiaryDetailUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7940FB32292E065F00276EFC /* DiaryDetailUseCase.swift */; };
9825F41B29377875005F2163 /* ChangeUserNameUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9825F41A29377875005F2163 /* ChangeUserNameUseCase.swift */; };
9825F41D29377ACF005F2163 /* SettingsRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9825F41C29377ACF005F2163 /* SettingsRepository.swift */; };
982A2A472924AE74006F6ACD /* UserDefaultsKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 982A2A462924AE74006F6ACD /* UserDefaultsKey.swift */; };
982A3699292C905300FDC6CF /* DiaryDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 982A3698292C905300FDC6CF /* DiaryDetailViewController.swift */; };
982B3B7F292E68FB0077A44B /* DiaryDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 982B3B7E292E68FB0077A44B /* DiaryDetailViewModel.swift */; };
Expand Down Expand Up @@ -130,6 +132,8 @@
7940FB2E292E063100276EFC /* DiaryDetailDTO.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiaryDetailDTO.swift; sourceTree = "<group>"; };
7940FB30292E065100276EFC /* DiaryDetailEndpoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiaryDetailEndpoint.swift; sourceTree = "<group>"; };
7940FB32292E065F00276EFC /* DiaryDetailUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiaryDetailUseCase.swift; sourceTree = "<group>"; };
9825F41A29377875005F2163 /* ChangeUserNameUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeUserNameUseCase.swift; sourceTree = "<group>"; };
9825F41C29377ACF005F2163 /* SettingsRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsRepository.swift; sourceTree = "<group>"; };
982A2A462924AE74006F6ACD /* UserDefaultsKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsKey.swift; sourceTree = "<group>"; };
982A3698292C905300FDC6CF /* DiaryDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiaryDetailViewController.swift; sourceTree = "<group>"; };
982B3B7E292E68FB0077A44B /* DiaryDetailViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiaryDetailViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -287,6 +291,7 @@
7940FB32292E065F00276EFC /* DiaryDetailUseCase.swift */,
988414DA2923606B007C9132 /* DiaryListUseCase.swift */,
9894EAF429373385005F2B15 /* SettingsUseCase.swift */,
9825F41A29377875005F2163 /* ChangeUserNameUseCase.swift */,
);
path = UseCase;
sourceTree = "<group>";
Expand Down Expand Up @@ -364,6 +369,7 @@
4FA32427292363AA00DB04D5 /* DiaryRepository.swift */,
982A2A462924AE74006F6ACD /* UserDefaultsKey.swift */,
4F4E0D3D2924B925005ABA8F /* LoginRepository.swift */,
9825F41C29377ACF005F2163 /* SettingsRepository.swift */,
);
path = Repository;
sourceTree = "<group>";
Expand Down Expand Up @@ -523,6 +529,7 @@
4F4E0D3E2924B925005ABA8F /* LoginRepository.swift in Sources */,
4F9A00212922338E007D9057 /* AppDelegate.swift in Sources */,
983AE9D82935CEE2006547BD /* SettingsViewModel.swift in Sources */,
9825F41D29377ACF005F2163 /* SettingsRepository.swift in Sources */,
66F0D7EE2925FF8B0074872E /* DiaryCell.swift in Sources */,
4F9A00202922337F007D9057 /* LoginViewController.swift in Sources */,
982A2A472924AE74006F6ACD /* UserDefaultsKey.swift in Sources */,
Expand Down Expand Up @@ -552,6 +559,7 @@
4FCAC5C2292B5C9000BF9CDD /* LoginSession.swift in Sources */,
666E6F7D291CF45600CECD4B /* Coordinator.swift in Sources */,
982A3699292C905300FDC6CF /* DiaryDetailViewController.swift in Sources */,
9825F41B29377875005F2163 /* ChangeUserNameUseCase.swift in Sources */,
666E6F8C291CFAC200CECD4B /* DiaryCollectionViewController.swift in Sources */,
666E6F8A291CF82700CECD4B /* TabBarPageCase.swift in Sources */,
79183800292225DC00BC6992 /* UIFont+.swift in Sources */,
Expand Down
16 changes: 16 additions & 0 deletions Segno/Segno/Data/Repository/SettingsRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// SettingsRepository.swift
// Segno
//
// Created by YOONJONG on 2022/11/30.
//

import RxSwift

protocol SettingsRepository {

}

final class SettingsRepositoryImpl: SettingsRepository {

}
27 changes: 27 additions & 0 deletions Segno/Segno/Domain/UseCase/ChangeUserNameUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ChangeUserNameUseCase.swift
// Segno
//
// Created by YOONJONG on 2022/11/30.
//

import RxSwift

protocol ChangeUserNameUseCase {
func requestChangeNickname(to nickname: String) -> Bool
}

final class ChangeUserNameUseCaseImpl: ChangeUserNameUseCase {
let repository: SettingsRepository
private let disposeBag = DisposeBag()

init(repository: SettingsRepository = SettingsRepositoryImpl()) {
self.repository = repository
}

func requestChangeNickname(to nickname: String) -> Bool {
// 임시 처리입니다.
debugPrint("SettingsUseCase - requestChangeNickname : \(nickname)으로 변경")
return true
}
}
7 changes: 0 additions & 7 deletions Segno/Segno/Domain/UseCase/SettingsUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import RxSwift

protocol SettingsUseCase {
func requestChangeNickname(to nickname: String) -> Bool
func getAutoPlayMode() -> Bool
func changeAutoPlayMode(to mode: Bool)
func getDarkMode() -> Int
Expand All @@ -23,12 +22,6 @@ final class SettingsUseCaseImpl: SettingsUseCase {
self.repository = repository
}

func requestChangeNickname(to nickname: String) -> Bool {
// 임시 처리입니다.
debugPrint("SettingsUseCase - requestChangeNickname : \(nickname)으로 변경")
return true
}

func getAutoPlayMode() -> Bool {
if let isEnabled = repository.getUserDefaultsObject(forKey: .isAutoPlayEnabled) as? Bool {
debugPrint("SettingsUseCase - getAutoPlayMode : 키가 있습니다 - \(isEnabled)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ final class SettingsViewController: UIViewController {
guard let newNickname = cell.nicknameTextField.text else {
return Observable<Bool>.empty()
}
debugPrint("입력된 아이디 : ", newNickname)
return self.viewModel.changeNickname(to: newNickname)
}
.subscribe(onNext: { result in
debugPrint("viewModel 메서드 실행 결과 : ", result)
debugPrint("여기에서 \(result)에 대한 피드백 Alert 띄웁니다.")
})
.disposed(by: self.disposeBag)

Expand Down
24 changes: 14 additions & 10 deletions Segno/Segno/Presentation/ViewModel/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,41 @@ import RxSwift
final class SettingsViewModel {
lazy var dataSource = Observable<[SettingsCellModel]>.just([
.nickname,
.settingsSwitch(title: "음악 자동 재생", isOn: useCase.getAutoPlayMode()),
.settingsActionSheet(title: "다크 모드", mode: useCase.getDarkMode())
.settingsSwitch(title: "음악 자동 재생", isOn: settingsUseCase.getAutoPlayMode()),
.settingsActionSheet(title: "다크 모드", mode: settingsUseCase.getDarkMode())
])

private let useCase: SettingsUseCase
private let settingsUseCase: SettingsUseCase
private let changeUserNameUseCase: ChangeUserNameUseCase

init(useCase: SettingsUseCase = SettingsUseCaseImpl()) {
self.useCase = useCase
init(settingsUseCase: SettingsUseCase = SettingsUseCaseImpl(),
changeUserNameUseCase: ChangeUserNameUseCase = ChangeUserNameUseCaseImpl()
) {
self.settingsUseCase = settingsUseCase
self.changeUserNameUseCase = changeUserNameUseCase
}

func changeNickname(to nickname: String) -> Observable<Bool> {
return Observable.create { emitter in
let result = self.useCase.requestChangeNickname(to: nickname)
let result = self.changeUserNameUseCase.requestChangeNickname(to: nickname)
emitter.onNext(result)
return Disposables.create()
}
}

func getAutoPlayMode() -> Bool {
return useCase.getAutoPlayMode()
return settingsUseCase.getAutoPlayMode()
}

func changeAutoPlayMode(to mode: Bool) {
useCase.changeAutoPlayMode(to: mode)
settingsUseCase.changeAutoPlayMode(to: mode)
}

func getDarkMode() -> Int {
return useCase.getDarkMode()
return settingsUseCase.getDarkMode()
}

func changeDarkMode(to mode: Int) {
useCase.changeDarkMode(to: mode)
settingsUseCase.changeDarkMode(to: mode)
}
}

0 comments on commit 9908d4b

Please sign in to comment.