From d2e94f4d79ce6f93f409608d02fc016160a690ce Mon Sep 17 00:00:00 2001 From: Dayeon Lee Date: Tue, 13 Dec 2022 12:46:37 +0900 Subject: [PATCH 01/11] [feat] Delete CameraIconView.swift --- .../DailyQuest.xcodeproj/project.pbxproj | 4 - .../xcshareddata/swiftpm/Package.resolved | 2 +- .../Home/View/CameraIconView.swift | 77 ------------------- 3 files changed, 1 insertion(+), 82 deletions(-) delete mode 100644 DailyQuest/DailyQuest/Presentation/Home/View/CameraIconView.swift diff --git a/DailyQuest/DailyQuest.xcodeproj/project.pbxproj b/DailyQuest/DailyQuest.xcodeproj/project.pbxproj index b777752..d6fd40d 100644 --- a/DailyQuest/DailyQuest.xcodeproj/project.pbxproj +++ b/DailyQuest/DailyQuest.xcodeproj/project.pbxproj @@ -140,7 +140,6 @@ 9BED4DE8293FA01400C60631 /* ProfileViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BED4DE7293FA01400C60631 /* ProfileViewModel.swift */; }; 9BED4DEA293FA92900C60631 /* UIImageView+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BED4DE9293FA92900C60631 /* UIImageView+.swift */; }; 9BED4DEC2940EA8900C60631 /* UserImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BED4DEB2940EA8900C60631 /* UserImageView.swift */; }; - 9BED4DEE2941932200C60631 /* CameraIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BED4DED2941932200C60631 /* CameraIconView.swift */; }; 9BED4DF12941C47D00C60631 /* RxGesture in Frameworks */ = {isa = PBXBuildFile; productRef = 9BED4DF02941C47D00C60631 /* RxGesture */; }; 9BED4DF629470D8C00C60631 /* LaunchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BED4DF529470D8C00C60631 /* LaunchViewController.swift */; }; 9BED4DFF2947109D00C60631 /* max.lottie.json in Resources */ = {isa = PBXBuildFile; fileRef = 9BED4DFE2947109C00C60631 /* max.lottie.json */; }; @@ -383,7 +382,6 @@ 9BED4DE7293FA01400C60631 /* ProfileViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewModel.swift; sourceTree = ""; }; 9BED4DE9293FA92900C60631 /* UIImageView+.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImageView+.swift"; sourceTree = ""; }; 9BED4DEB2940EA8900C60631 /* UserImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserImageView.swift; sourceTree = ""; }; - 9BED4DED2941932200C60631 /* CameraIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraIconView.swift; sourceTree = ""; }; 9BED4DF529470D8C00C60631 /* LaunchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchViewController.swift; sourceTree = ""; }; 9BED4DFE2947109C00C60631 /* max.lottie.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = max.lottie.json; sourceTree = ""; }; A5003AB3293F5FEC00082A9C /* SignUpViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpViewModel.swift; sourceTree = ""; }; @@ -1084,7 +1082,6 @@ 345687F729374D2500CA51E3 /* DayNamePickerView.swift */, 345687F92937815900CA51E3 /* QuantityView.swift */, 9BED4DEB2940EA8900C60631 /* UserImageView.swift */, - 9BED4DED2941932200C60631 /* CameraIconView.swift */, ); path = View; sourceTree = ""; @@ -1577,7 +1574,6 @@ 349955122923220E007AB99E /* SwiftUIPreview.swift in Sources */, 9BD8CD022938418500E6EA2F /* LastFollowingCell.swift in Sources */, 3449AD6029222B3900B87619 /* UserInfoCell.swift in Sources */, - 9BED4DEE2941932200C60631 /* CameraIconView.swift in Sources */, 34ACC32F291DE9C000741371 /* SceneDelegate.swift in Sources */, 34A529D829247A87001BAD34 /* HomeCoordinator.swift in Sources */, 3472E8F7294213BE00BB304F /* DefaultFriendQuestUseCase.swift in Sources */, diff --git a/DailyQuest/DailyQuest.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DailyQuest/DailyQuest.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index f105edd..938e625 100644 --- a/DailyQuest/DailyQuest.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DailyQuest/DailyQuest.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -93,7 +93,7 @@ { "identity" : "lottie-ios", "kind" : "remoteSourceControl", - "location" : "https://github.com/airbnb/lottie-ios", + "location" : "https://github.com/airbnb/lottie-ios.git", "state" : { "revision" : "b4bd0604ded9574807f41b4004b57dd1226a30a4", "version" : "3.5.0" diff --git a/DailyQuest/DailyQuest/Presentation/Home/View/CameraIconView.swift b/DailyQuest/DailyQuest/Presentation/Home/View/CameraIconView.swift deleted file mode 100644 index d189994..0000000 --- a/DailyQuest/DailyQuest/Presentation/Home/View/CameraIconView.swift +++ /dev/null @@ -1,77 +0,0 @@ -// -// CameraIconView.swift -// DailyQuest -// -// Created by 이다연 on 2022/12/08. -// - -import UIKit -import SnapKit - -final class CameraIconView: UIView { - - override func draw(_ rect: CGRect) { - super.draw(rect) - } - - private lazy var backgroundView: UIView = { - let backgroundView = UIView() - backgroundView.backgroundColor = .white - backgroundView.layer.cornerRadius = 30.0 / 2 - backgroundView.layer.shadowColor = UIColor.black.cgColor - backgroundView.layer.masksToBounds = false - backgroundView.layer.shadowOffset = CGSize(width: 3, height: 3) - backgroundView.layer.shadowRadius = 3 - backgroundView.layer.shadowOpacity = 0.3 - return backgroundView - }() - - - private lazy var camaraImageView: UIImageView = { - let camaraImageView = UIImageView() - camaraImageView.image = UIImage(systemName: "camera.fill") - camaraImageView.contentMode = .scaleAspectFit - camaraImageView.tintColor = .gray - return camaraImageView - }() - - override init(frame: CGRect = .zero) { - super.init(frame: frame) - addSubviews() - setupConstraints() - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - private func addSubviews() { - addSubview(backgroundView) - backgroundView.addSubview(camaraImageView) - } - - private func setupConstraints() { - camaraImageView.snp.makeConstraints { make in - make.centerX.centerY.equalToSuperview() - make.width.height.equalTo(20) - } - - backgroundView.snp.makeConstraints { make in - make.edges.equalToSuperview() - make.width.height.equalTo(30) - } - } -} - -#if canImport(SwiftUI) && DEBUG -import SwiftUI - -struct CameraIconViewPreview: PreviewProvider{ - static var previews: some View { - UIViewPreview { - let view = CameraIconView(frame: .zero) - return view - }.previewLayout(.fixed(width: 30, height: 30)) - } -} -#endif From 22132269d495f22e5a2ce99054b8450f397b56d5 Mon Sep 17 00:00:00 2001 From: Dayeon Lee Date: Tue, 13 Dec 2022 12:52:40 +0900 Subject: [PATCH 02/11] [feat] Delete CameraIconView in UserImageView --- .../Presentation/Home/View/UserImageView.swift | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/DailyQuest/DailyQuest/Presentation/Home/View/UserImageView.swift b/DailyQuest/DailyQuest/Presentation/Home/View/UserImageView.swift index 825425a..131fc33 100644 --- a/DailyQuest/DailyQuest/Presentation/Home/View/UserImageView.swift +++ b/DailyQuest/DailyQuest/Presentation/Home/View/UserImageView.swift @@ -19,10 +19,6 @@ final class UserImageView: UIView { return userImage }() - private lazy var cameraIcon: CameraIconView = { - return CameraIconView() - }() - override init(frame: CGRect) { super.init(frame: frame) @@ -36,7 +32,6 @@ final class UserImageView: UIView { private func addSubviews() { addSubview(userImage) - addSubview(cameraIcon) } private func setupConstraints() { @@ -44,12 +39,5 @@ final class UserImageView: UIView { make.centerX.centerY.equalToSuperview() make.width.height.equalTo(100) } - cameraIcon.snp.makeConstraints { make in - make.left.equalTo(75) - make.top.equalTo(75) - } - self.snp.makeConstraints { make in - make.width.height.equalTo(110) - } } } From 62e619270b4217af38d83fff308079888dc69398 Mon Sep 17 00:00:00 2001 From: Dayeon Lee Date: Tue, 13 Dec 2022 16:45:33 +0900 Subject: [PATCH 03/11] [feat] Add setIntroduce in User Entity --- DailyQuest/DailyQuest/Domain/Entities/User.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/DailyQuest/DailyQuest/Domain/Entities/User.swift b/DailyQuest/DailyQuest/Domain/Entities/User.swift index e61c60b..ba96856 100644 --- a/DailyQuest/DailyQuest/Domain/Entities/User.swift +++ b/DailyQuest/DailyQuest/Domain/Entities/User.swift @@ -70,4 +70,13 @@ extension User { introduce: self.introduce, allow: self.allow) } + + func setIntroduce(introduce: String) -> User { + return User(uuid: self.uuid, + nickName: self.nickName, + profileURL: self.profileURL, + backgroundImageURL: self.backgroundImageURL, + introduce: introduce, + allow: self.allow) + } } From 7bf144674c0574e0a4c3b1c1de3ec721792d562c Mon Sep 17 00:00:00 2001 From: Dayeon Lee Date: Tue, 13 Dec 2022 16:45:59 +0900 Subject: [PATCH 04/11] [feat] Create updateIntroduce function in DefaultUserUseCase --- .../Domain/UseCases/Home/DefaultUserUseCase.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/DailyQuest/DailyQuest/Domain/UseCases/Home/DefaultUserUseCase.swift b/DailyQuest/DailyQuest/Domain/UseCases/Home/DefaultUserUseCase.swift index 886375f..752f31f 100644 --- a/DailyQuest/DailyQuest/Domain/UseCases/Home/DefaultUserUseCase.swift +++ b/DailyQuest/DailyQuest/Domain/UseCases/Home/DefaultUserUseCase.swift @@ -53,5 +53,12 @@ extension DefaultUserUseCase: UserUseCase { return userRepository.deleteUser() .catchAndReturn(false) } + + func updateIntroduce(introduce: String) -> Single { + userRepository.readUser() + .map { $0.setIntroduce(introduce: introduce) } + .flatMap(userRepository.updateUser(by:)) + .map { _ in true } + .catchAndReturn(false) + } } - From c2298471b888842973717880571dde381dd79a97 Mon Sep 17 00:00:00 2001 From: Dayeon Lee Date: Tue, 13 Dec 2022 16:46:24 +0900 Subject: [PATCH 05/11] [feat] Create updateIntroduce in UserUseCase --- .../DailyQuest/Domain/UseCases/Home/Protocols/UserUseCase.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DailyQuest/DailyQuest/Domain/UseCases/Home/Protocols/UserUseCase.swift b/DailyQuest/DailyQuest/Domain/UseCases/Home/Protocols/UserUseCase.swift index ab9007d..77e8622 100644 --- a/DailyQuest/DailyQuest/Domain/UseCases/Home/Protocols/UserUseCase.swift +++ b/DailyQuest/DailyQuest/Domain/UseCases/Home/Protocols/UserUseCase.swift @@ -17,4 +17,6 @@ protocol UserUseCase { func saveBackgroundImage(data: Data) -> Single func delete() -> Single + + func updateIntroduce(introduce: String) -> Single } From 98d81ff58d8be7af8a286546496517d7a205bd8b Mon Sep 17 00:00:00 2001 From: Dayeon Lee Date: Tue, 13 Dec 2022 16:46:40 +0900 Subject: [PATCH 06/11] [feat] Update ProfileViewController --- .../ProfileViewController.swift | 103 +++++++++++++----- 1 file changed, 77 insertions(+), 26 deletions(-) diff --git a/DailyQuest/DailyQuest/Presentation/Home/ViewController/ProfileViewController.swift b/DailyQuest/DailyQuest/Presentation/Home/ViewController/ProfileViewController.swift index e26a075..68881b7 100644 --- a/DailyQuest/DailyQuest/Presentation/Home/ViewController/ProfileViewController.swift +++ b/DailyQuest/DailyQuest/Presentation/Home/ViewController/ProfileViewController.swift @@ -18,6 +18,7 @@ final class ProfileViewController: UIViewController { private var disposableBag = DisposeBag() private let changeProfileImage = PublishSubject() + private let changeIntroduceLabel = PublishSubject() private lazy var imagePicker: PHPickerViewController = { var configuration = PHPickerConfiguration() @@ -48,14 +49,27 @@ final class ProfileViewController: UIViewController { return introduceLabel }() - private lazy var editIntroduceButton: UIButton = { - let editIntroduceButton = UIButton() - editIntroduceButton.setImage(UIImage(systemName: "pencil"), for: .normal) - editIntroduceButton.tintColor = .gray - return editIntroduceButton + private lazy var editProfileImageButton: UIButton = { + let editProfileImageButton = UIButton() + editProfileImageButton.setTitle("프로필 이미지 변경", for: .normal) + editProfileImageButton.setTitleColor(.maxViolet, for: .normal) + editProfileImageButton.backgroundColor = .maxYellow + editProfileImageButton.layer.cornerRadius = 10 + return editProfileImageButton }() + private lazy var editIntroduceLabel: UIButton = { + let editIntroduceLabel = UIButton() + editIntroduceLabel.setTitle("한 줄 소개 변경", for: .normal) + editIntroduceLabel.setTitleColor(.maxViolet, for: .normal) + editIntroduceLabel.backgroundColor = .maxYellow + editIntroduceLabel.layer.cornerRadius = 10 + return editIntroduceLabel + }() + + + // MARK: - Life Cycle static func create(with viewModel: ProfileViewModel) -> ProfileViewController { let vc = ProfileViewController() @@ -75,16 +89,17 @@ final class ProfileViewController: UIViewController { view.addSubview(userImageView) view.addSubview(nameLabel) view.addSubview(introduceLabel) - view.addSubview(editIntroduceButton) + view.addSubview(editProfileImageButton) + view.addSubview(editIntroduceLabel) userImageView.snp.makeConstraints { make in make.centerX.equalToSuperview() - make.top.equalToSuperview().offset(50) + make.top.equalToSuperview().offset(100) } nameLabel.snp.makeConstraints { make in make.centerX.equalToSuperview() - make.top.equalTo(userImageView.snp.bottom).offset(5) + make.top.equalTo(userImageView.snp.bottom).offset(60) } introduceLabel.snp.makeConstraints { make in @@ -92,40 +107,38 @@ final class ProfileViewController: UIViewController { make.top.equalTo(nameLabel.snp.bottom).offset(5) } - editIntroduceButton.snp.makeConstraints { make in - make.width.height.equalTo(20) - make.top.equalTo(nameLabel.snp.bottom).offset(5) - make.left.equalTo(introduceLabel.snp.right).offset(5) + editProfileImageButton.snp.makeConstraints { make in + make.centerX.equalToSuperview() + make.top.equalTo(introduceLabel.snp.bottom).offset(10) + make.height.equalTo(50) + make.width.equalTo(300) } + editIntroduceLabel.snp.makeConstraints { make in + make.centerX.equalToSuperview() + make.top.equalTo(editProfileImageButton.snp.bottom).offset(10) + make.height.equalTo(50) + make.width.equalTo(300) + } } func bind() { - userImageView.rx.tapGesture() - .when(.recognized) + + editProfileImageButton.rx.tap .subscribe(onNext: { [weak self] _ in guard let self = self else { return } self.present(self.imagePicker, animated: true) }).disposed(by: disposableBag) - editIntroduceButton.rx.tapGesture() - .when(.recognized) + editIntroduceLabel.rx.tap .subscribe(onNext: { [weak self] _ in - let message = "한줄소개를 작성해주세요." - let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert) - let okAction = UIAlertAction(title: "OK", style: .cancel) { (action) in - - - } - alert.addAction(okAction) - alert.addTextField () - self?.present(alert, animated: true, completion: nil) + self?.showIntroduceAlert() }) .disposed(by: disposableBag) - let input = ProfileViewModel.Input(viewDidLoad: .just(()).asObservable(),changeProfileImage: changeProfileImage) + let input = ProfileViewModel.Input(viewDidLoad: .just(()).asObservable(),changeProfileImage: changeProfileImage, changeIntroduceLabel: changeIntroduceLabel) let output = viewModel.transform(input: input) output @@ -134,6 +147,9 @@ final class ProfileViewController: UIViewController { self.userImageView.userImage.setImage(with: user.profileURL) self.nameLabel.text = user.nickName self.introduceLabel.text = user.introduce + if self.introduceLabel.text == "" { + self.setDefaultIntroduce() + } }) .disposed(by: disposableBag) @@ -147,6 +163,41 @@ final class ProfileViewController: UIViewController { } }) .disposed(by: disposableBag) + + output + .changeIntroduceLabelResult + .drive(onNext: { user in + self.introduceLabel.text = user.introduce + if self.introduceLabel.text == "" { + self.setDefaultIntroduce() + } else { + self.introduceLabel.textColor = .maxViolet + } + }) + .disposed(by: disposableBag) + } + + private func setDefaultIntroduce() { + self.introduceLabel.text = "한 줄 소개를 작성해주세요." + self.introduceLabel.textColor = .maxLightGrey + } + + private func showIntroduceAlert(preferredStyle: UIAlertController.Style = .alert, + completion: (() -> Void)? = nil) { + let message = "한줄소개를 작성해주세요." + let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert) + let okAction = UIAlertAction(title: "OK", style: .default) { [weak self] _ in + let text = alert.textFields?[0].text + self?.changeIntroduceLabel.onNext(text ?? "") + } + + let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) + + alert.addAction(okAction) + alert.addAction(cancelAction) + + alert.addTextField () + self.present(alert, animated: true, completion: nil) } } From 8b6df2fd585032cf136e28025862ceecf5812e66 Mon Sep 17 00:00:00 2001 From: Dayeon Lee Date: Tue, 13 Dec 2022 16:47:06 +0900 Subject: [PATCH 07/11] [feat] Add changeIntroduceLabelResult output in ProfileViewModel --- .../Home/ViewModel/ProfileViewModel.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/DailyQuest/DailyQuest/Presentation/Home/ViewModel/ProfileViewModel.swift b/DailyQuest/DailyQuest/Presentation/Home/ViewModel/ProfileViewModel.swift index e9f8e96..55e6284 100644 --- a/DailyQuest/DailyQuest/Presentation/Home/ViewModel/ProfileViewModel.swift +++ b/DailyQuest/DailyQuest/Presentation/Home/ViewModel/ProfileViewModel.swift @@ -22,11 +22,13 @@ final class ProfileViewModel { struct Input { let viewDidLoad: Observable let changeProfileImage: Observable + let changeIntroduceLabel : Observable } struct Output { let data: Driver let changeProfileImageResult: Driver + let changeIntroduceLabelResult: Driver } func transform(input: Input) -> Output { @@ -55,6 +57,16 @@ final class ProfileViewModel { }.flatMap(userUseCase.fetch) .asDriver(onErrorJustReturn: User()) - return Output(data: data, changeProfileImageResult: changeProfileImageResult) + let changeIntroduceLabelResult = input.changeIntroduceLabel.flatMap { introduce in + return self.userUseCase.updateIntroduce(introduce: introduce) + .map{ _ in introduce } + .catchAndReturn(nil) + .asObservable() + }.map{ _ in + Void() + }.flatMap(userUseCase.fetch) + .asDriver(onErrorJustReturn: User()) + + return Output(data: data, changeProfileImageResult: changeProfileImageResult, changeIntroduceLabelResult: changeIntroduceLabelResult) } } From 7e4f0ae752057254fb724ff0133d5f6490b20b2b Mon Sep 17 00:00:00 2001 From: Jeonhui Date: Tue, 13 Dec 2022 19:37:00 +0900 Subject: [PATCH 08/11] [style] change color --- .../DailyQuest/Presentation/Common/View/FriendStatusView.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DailyQuest/DailyQuest/Presentation/Common/View/FriendStatusView.swift b/DailyQuest/DailyQuest/Presentation/Common/View/FriendStatusView.swift index ca13cb4..af5e4cc 100644 --- a/DailyQuest/DailyQuest/Presentation/Common/View/FriendStatusView.swift +++ b/DailyQuest/DailyQuest/Presentation/Common/View/FriendStatusView.swift @@ -31,6 +31,7 @@ final class FriendStatusView: UIView { private(set) lazy var userNameLabel: UILabel = { let userNameLabel = UILabel() userNameLabel.text = "User name label님의 Quest" + userNameLabel.font = .systemFont(ofSize: 22,weight: .bold) return userNameLabel }() @@ -38,7 +39,7 @@ final class FriendStatusView: UIView { private(set) lazy var introduceLabel: UILabel = { let introduceLabel = UILabel() introduceLabel.text = "introduceLabel" - introduceLabel.textColor = .maxLightGrey + introduceLabel.textColor = .darkGray return introduceLabel }() From d680247f92f53b5c7d371f70a7e28ab9771ffaf2 Mon Sep 17 00:00:00 2001 From: Jeonhui Date: Tue, 13 Dec 2022 19:40:52 +0900 Subject: [PATCH 09/11] [fix] getAllowUser --- .../Data/Repositories/DefaultBrowseRepository.swift | 3 +-- .../Infrastructure/FirebaseService/FirebaseService.swift | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/DailyQuest/DailyQuest/Data/Repositories/DefaultBrowseRepository.swift b/DailyQuest/DailyQuest/Data/Repositories/DefaultBrowseRepository.swift index 22b5107..751ea63 100644 --- a/DailyQuest/DailyQuest/Data/Repositories/DefaultBrowseRepository.swift +++ b/DailyQuest/DailyQuest/Data/Repositories/DefaultBrowseRepository.swift @@ -27,11 +27,10 @@ extension DefaultBrowseRepository: BrowseRepository { /// Firebase 우선, 실패시 persistentStorage, persistentStorage도 실패시 Error반환 /// - Returns: Observable<[BrowseQuest]> func fetch() -> Single<[BrowseQuest]> { - let uid = networkService.uid.value return networkService.getAllowUsers(limit: 10) .map { $0.toDomain() } .flatMap(fetchBrowseQuestNetworkService(user:)) - .filter { !$0.quests.isEmpty && uid != $0.user.uuid } + .filter { !$0.quests.isEmpty } .toArray() .do(afterSuccess: { [weak self] browseQuests in guard let self = self else { return } diff --git a/DailyQuest/DailyQuest/Infrastructure/FirebaseService/FirebaseService.swift b/DailyQuest/DailyQuest/Infrastructure/FirebaseService/FirebaseService.swift index a61c592..6745540 100644 --- a/DailyQuest/DailyQuest/Infrastructure/FirebaseService/FirebaseService.swift +++ b/DailyQuest/DailyQuest/Infrastructure/FirebaseService/FirebaseService.swift @@ -437,8 +437,10 @@ extension FirebaseService { do { guard let querySnapshot = querySnapshot else { throw NetworkServiceError.noDataError } for document in querySnapshot.documents { - let quest = try document.data(as: UserDTO.self) - observer.onNext(quest) + let user = try document.data(as: UserDTO.self) + if user.uuid != self.uid.value { + observer.onNext(user) + } } } catch let error { observer.onError(error) From d61656c05f48ef910346827ca1fe3837cfe8d188 Mon Sep 17 00:00:00 2001 From: Jeonhui Date: Tue, 13 Dec 2022 20:29:09 +0900 Subject: [PATCH 10/11] [fix] change func name --- DailyQuest/DailyQuest/Application/SyncManager.swift | 2 +- .../RealmStorage/RealmBrowseQuestsStorage.swift | 4 ++-- .../RealmStorage/RealmQuestsStorage.swift | 12 ++++++------ .../RealmStorage/RealmStorage.swift | 4 ++-- .../RealmStorage/RealmUserInfoStorage.swift | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/DailyQuest/DailyQuest/Application/SyncManager.swift b/DailyQuest/DailyQuest/Application/SyncManager.swift index daf38d6..3ee9ebe 100644 --- a/DailyQuest/DailyQuest/Application/SyncManager.swift +++ b/DailyQuest/DailyQuest/Application/SyncManager.swift @@ -69,7 +69,7 @@ final class SyncManager { do { let quests = try persistentStorage - .fetchEntities(type: QuestEntity.self, filter: nil) + .readEntities(type: QuestEntity.self, filter: nil) .compactMap { $0.toDomain() } single(.success(quests)) } catch let error { diff --git a/DailyQuest/DailyQuest/Data/PersistentStorages/BrowseQuestsStorage/RealmStorage/RealmBrowseQuestsStorage.swift b/DailyQuest/DailyQuest/Data/PersistentStorages/BrowseQuestsStorage/RealmStorage/RealmBrowseQuestsStorage.swift index e5b8e51..2bd208f 100644 --- a/DailyQuest/DailyQuest/Data/PersistentStorages/BrowseQuestsStorage/RealmStorage/RealmBrowseQuestsStorage.swift +++ b/DailyQuest/DailyQuest/Data/PersistentStorages/BrowseQuestsStorage/RealmStorage/RealmBrowseQuestsStorage.swift @@ -24,7 +24,7 @@ extension RealmBrowseQuestsStorage: BrowseQuestsStorage { } do { - let browseQuests = try realmStorage.fetchEntities(type: BrowseQuestEntity.self) + let browseQuests = try realmStorage.readEntities(type: BrowseQuestEntity.self) .compactMap { $0.toDomain() } single(.success(browseQuests)) } catch let error { @@ -44,7 +44,7 @@ extension RealmBrowseQuestsStorage: BrowseQuestsStorage { let browseQuestEntity = BrowseQuestEntity(browseQuest: browseQuest) do { - try realmStorage.saveEntity(entity: browseQuestEntity) + try realmStorage.createEntity(entity: browseQuestEntity) single(.success(browseQuest)) } catch let error { single(.failure(RealmStorageError.saveError(error))) diff --git a/DailyQuest/DailyQuest/Data/PersistentStorages/QuestsStorage/RealmStorage/RealmQuestsStorage.swift b/DailyQuest/DailyQuest/Data/PersistentStorages/QuestsStorage/RealmStorage/RealmQuestsStorage.swift index 7ad833f..74f7773 100644 --- a/DailyQuest/DailyQuest/Data/PersistentStorages/QuestsStorage/RealmStorage/RealmQuestsStorage.swift +++ b/DailyQuest/DailyQuest/Data/PersistentStorages/QuestsStorage/RealmStorage/RealmQuestsStorage.swift @@ -26,7 +26,7 @@ extension RealmQuestsStorage: QuestsStorage { do { for quest in quests { let questEntity = QuestEntity(quest: quest) - try realmStorage.saveEntity(entity: questEntity) + try realmStorage.createEntity(entity: questEntity) } single(.success(quests)) } catch let error { @@ -43,7 +43,7 @@ extension RealmQuestsStorage: QuestsStorage { } do { let quests = try realmStorage - .fetchEntities(type: QuestEntity.self, filter: NSPredicate(format: "date == %@", date.toString)) + .readEntities(type: QuestEntity.self, filter: NSPredicate(format: "date == %@", date.toString)) .compactMap { $0.toDomain() } single(.success(quests)) } catch let error { @@ -75,7 +75,7 @@ extension RealmQuestsStorage: QuestsStorage { return Disposables.create() } do { - guard let entity = try realmStorage.findEntities(type: QuestEntity.self, filter: NSPredicate(format: "uuid == %@", questId as CVarArg)).first else { + guard let entity = try realmStorage.readEntities(type: QuestEntity.self, filter: NSPredicate(format: "uuid == %@", questId as CVarArg)).first else { throw RealmStorageError.noDataError } let quest = entity.toDomain() @@ -96,7 +96,7 @@ extension RealmQuestsStorage: QuestsStorage { } do { - let entities = try realmStorage.findEntities(type: QuestEntity.self, filter: NSPredicate(format: "groupId == %@", groupId as CVarArg)) + let entities = try realmStorage.readEntities(type: QuestEntity.self, filter: NSPredicate(format: "groupId == %@", groupId as CVarArg)) let quests = entities.compactMap { $0.toDomain() } for entity in entities { try realmStorage.deleteEntity(entity: entity) @@ -115,7 +115,7 @@ extension RealmQuestsStorage: QuestsStorage { return Disposables.create() } do { - let entities = try realmStorage.fetchEntities(type: QuestEntity.self) + let entities = try realmStorage.readEntities(type: QuestEntity.self) let quests = entities.compactMap { $0.toDomain() } for entity in entities { try realmStorage.deleteEntity(entity: entity) @@ -137,7 +137,7 @@ extension RealmQuestsStorage: QuestsStorage { do { let quests = try realmStorage - .fetchEntities(type: QuestEntity.self, filter: nil) + .readEntities(type: QuestEntity.self, filter: nil) .compactMap { $0.toDomain() } single(.success(quests)) } catch let error { diff --git a/DailyQuest/DailyQuest/Data/PersistentStorages/RealmStorage/RealmStorage.swift b/DailyQuest/DailyQuest/Data/PersistentStorages/RealmStorage/RealmStorage.swift index 9a7ca64..8011bc3 100644 --- a/DailyQuest/DailyQuest/Data/PersistentStorages/RealmStorage/RealmStorage.swift +++ b/DailyQuest/DailyQuest/Data/PersistentStorages/RealmStorage/RealmStorage.swift @@ -30,7 +30,7 @@ final class RealmStorage { private let persistentContainer = try? Realm() @discardableResult - func saveEntity(entity: O) throws -> O { + func createEntity(entity: O) throws -> O { guard let persistentContainer = persistentContainer else { throw RealmStorageError.realmObjectError } @@ -40,7 +40,7 @@ final class RealmStorage { return entity } - func fetchEntities(type: O.Type, filter: NSPredicate? = nil) throws -> [O] { + func readEntities(type: O.Type, filter: NSPredicate? = nil) throws -> [O] { guard let persistentContainer = persistentContainer else { throw RealmStorageError.realmObjectError } diff --git a/DailyQuest/DailyQuest/Data/PersistentStorages/UserInfoStorage/RealmStorage/RealmUserInfoStorage.swift b/DailyQuest/DailyQuest/Data/PersistentStorages/UserInfoStorage/RealmStorage/RealmUserInfoStorage.swift index 090fab5..adf92c3 100644 --- a/DailyQuest/DailyQuest/Data/PersistentStorages/UserInfoStorage/RealmStorage/RealmUserInfoStorage.swift +++ b/DailyQuest/DailyQuest/Data/PersistentStorages/UserInfoStorage/RealmStorage/RealmUserInfoStorage.swift @@ -21,7 +21,7 @@ extension RealmUserInfoStorage: UserInfoStorage { return Single.create { [weak self] single in do { guard let realmStorage = self?.realmStorage else { throw RealmStorageError.realmObjectError } - guard let userInfoEntity = try realmStorage.fetchEntities(type: UserInfoEntity.self) + guard let userInfoEntity = try realmStorage.readEntities(type: UserInfoEntity.self) .first else { throw RealmStorageError.noDataError } From ee2897c3f580b48da0c24e4bf0bad4844bd698d9 Mon Sep 17 00:00:00 2001 From: Jeonhui Date: Tue, 13 Dec 2022 20:33:13 +0900 Subject: [PATCH 11/11] [refactor] RealmStorageCode --- .../RealmStorage/RealmStorage.swift | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/DailyQuest/DailyQuest/Data/PersistentStorages/RealmStorage/RealmStorage.swift b/DailyQuest/DailyQuest/Data/PersistentStorages/RealmStorage/RealmStorage.swift index 8011bc3..7566d32 100644 --- a/DailyQuest/DailyQuest/Data/PersistentStorages/RealmStorage/RealmStorage.swift +++ b/DailyQuest/DailyQuest/Data/PersistentStorages/RealmStorage/RealmStorage.swift @@ -19,16 +19,17 @@ enum RealmStorageError: Error { final class RealmStorage { static let shared = RealmStorage() - + private let persistentContainer = try? Realm() + private init() { // Realm file path #if DEBUG - print(Realm.Configuration.defaultConfiguration.fileURL!) + print(Realm.Configuration.defaultConfiguration.fileURL!) #endif } +} - private let persistentContainer = try? Realm() - +extension RealmStorage { @discardableResult func createEntity(entity: O) throws -> O { guard let persistentContainer = persistentContainer else { @@ -39,7 +40,7 @@ final class RealmStorage { } return entity } - + func readEntities(type: O.Type, filter: NSPredicate? = nil) throws -> [O] { guard let persistentContainer = persistentContainer else { throw RealmStorageError.realmObjectError @@ -50,7 +51,7 @@ final class RealmStorage { return Array(persistentContainer.objects(type)) } } - + @discardableResult func updateEntity(entity: O) throws -> O { guard let persistentContainer = persistentContainer else { @@ -61,7 +62,7 @@ final class RealmStorage { } return entity } - + @discardableResult func deleteEntity(entity: O) throws -> O { guard let persistentContainer = persistentContainer else { @@ -70,10 +71,10 @@ final class RealmStorage { try persistentContainer.write { persistentContainer.delete(entity) } - + return entity } - + @discardableResult func deleteAllEntity(type: O.Type) throws -> [O] { guard let persistentContainer = persistentContainer else { @@ -86,12 +87,4 @@ final class RealmStorage { } return Array(persistentContainer.objects(type)) } - - func findEntities(type: O.Type, filter: NSPredicate) throws -> [O] { - guard let persistentContainer = persistentContainer else { - throw RealmStorageError.realmObjectError - } - return Array(persistentContainer.objects(type).filter(filter)) - } - }