From 1738a037d785079e64e691e53e698f04251ddabe Mon Sep 17 00:00:00 2001 From: Goban Date: Sat, 3 Dec 2022 12:40:59 +0900 Subject: [PATCH 01/12] =?UTF-8?q?Fix=F0=9F=90=9E:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=ED=95=98=EA=B3=A0=20=EC=9E=AC=EC=A0=91?= =?UTF-8?q?=EC=86=8D=20=ED=95=98=EB=A9=B4=20=EC=9D=B8=EC=A6=9D=20=EC=97=86?= =?UTF-8?q?=EC=9D=8C=EC=9C=BC=EB=A1=9C=20=EB=82=98=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=ED=98=84=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Application/SceneDelegate.swift | 6 +++- .../Sources/Domain/User/UserInfoManager.swift | 33 +++++++++++++++++++ .../View/PlaceListViewController.swift | 20 ++++++++--- .../ViewModel/ThirdPartyLoginViewModel.swift | 6 +++- 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/Projects/App/Sources/Application/SceneDelegate.swift b/Projects/App/Sources/Application/SceneDelegate.swift index 30d67bc9..88cd1525 100644 --- a/Projects/App/Sources/Application/SceneDelegate.swift +++ b/Projects/App/Sources/Application/SceneDelegate.swift @@ -25,9 +25,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let userAuthToken = KeyChainManager.read(key: .authToken) let userNickName = UserInfoManager.userInfo?.userNickname let organizationID = UserInfoManager.userInfo?.userOrganization + let isEmptyOrganization = UserInfoManager.userInfo?.userOrganization.isEmpty let navigationController = UINavigationController(rootViewController: ThirdPartyLoginViewController()) // 정상적으로 가입을 한경우 - if userAuthToken != nil && userNickName != nil && organizationID != nil { + if userAuthToken != nil && userNickName != nil && isEmptyOrganization == false { + if UserInfoManager.userInfo?.userOrgName == nil, let orgID = organizationID?.first { + UserInfoManager.shared.fetchOrganizationList(orgID: orgID) + } navigationController.pushViewController(PlaceListViewController(), animated: false) } window.rootViewController = navigationController diff --git a/Projects/App/Sources/Domain/User/UserInfoManager.swift b/Projects/App/Sources/Domain/User/UserInfoManager.swift index 0913fd3e..0949d259 100644 --- a/Projects/App/Sources/Domain/User/UserInfoManager.swift +++ b/Projects/App/Sources/Domain/User/UserInfoManager.swift @@ -7,9 +7,15 @@ // import Foundation +import Combine +import Network final class UserInfoManager { + public static let shared = UserInfoManager() + private var cancelBag = Set() + public var isNameFetched = PassthroughSubject() + private enum UserInfoKeys: String, CaseIterable { case userNickname case userID @@ -100,4 +106,31 @@ final class UserInfoManager { UserInfoManager.userInfo?.userOrganization = userOrganization UserInfoManager.userInfo?.userOrgName = userOrgName } + +} + +extension UserInfoManager: ErrorMapper { + + func fetchOrganizationList(orgID: Int) { + OrganizationAPI.fetchOrgList() + .map { orgList in + orgList.map { Organization(dto: $0) } + } + .eraseToAnyPublisher() + .sink { [weak self] error in + guard let self = self else { return } + + switch error { + case .failure(let error): + let errorMessage = self.errorMessage(for: error) + print(errorMessage) + case .finished: break + } + } receiveValue: { [weak self] orgList in + UserInfoManager.userInfo?.userOrgName = orgList.first(where: {$0.id == orgID})?.name ?? "(대학 찾을 수 없음)" + self?.isNameFetched.send(true) + } + .store(in: &cancelBag) + } + } diff --git a/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift b/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift index 9452de9e..dde1e0b3 100644 --- a/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift +++ b/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift @@ -3,7 +3,7 @@ // App // // Created by 김태호 on 2022/10/25. -// Updated by 리아 on 2022/11/01. +// Updated by 고반 on 2022/12/03. // Copyright (c) 2022 zesty. All rights reserved. // @@ -33,6 +33,8 @@ final class PlaceListViewController: UIViewController { private var emptyImageView = UIImageView() private var emptyLabel = UILabel() + private let placeTitle = UILabel() + // MARK: - LifeCycle init(viewModel: PlaceListViewModel = PlaceListViewModel()) { @@ -50,17 +52,28 @@ final class PlaceListViewController: UIViewController { configureDataSource() createLayout() configureUI() + bind() analytics() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - bind() + bindResult() } // MARK: - Function private func bind() { + UserInfoManager.shared.isNameFetched + .receive(on: DispatchQueue.main) + .sink { [weak self] _ in + guard let self = self else { return } + self.placeTitle.text = UserInfoManager.userInfo?.userOrgName + } + .store(in: &cancelBag) + } + + private func bindResult() { viewModel.$result .receive(on: DispatchQueue.main) .sink { [weak self] placeList in @@ -250,9 +263,8 @@ extension PlaceListViewController { let searchItem = UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(searchButtonTapped)) let personCropCircle = UIImage(systemName: "person.crop.circle") let userInfoItem = UIBarButtonItem(image: personCropCircle, style: .plain, target: self, action: #selector(userInfoButtonTapped)) - let placeTitle = UILabel() let tapGesture = UITapGestureRecognizer(target: self, action: #selector(orgDetailButtonTapped)) - + placeTitle.text = UserInfoManager.userInfo?.userOrgName ?? "(인증대학없음)" placeTitle.font = .systemFont(ofSize: 17, weight: .bold) placeTitle.isUserInteractionEnabled = true diff --git a/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift b/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift index 17de9cf8..fdb65422 100644 --- a/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift +++ b/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift @@ -83,10 +83,14 @@ final class ThirdPartyLoginViewModel { self.shouldSetNicknameSubject.send(true) return } - if UserInfoManager.userInfo?.userOrganization == nil { + let userOrganization = UserInfoManager.userInfo?.userOrganization + if userOrganization == nil { self.shouldSetOrganizationSubject.send(true) return } + if UserInfoManager.userInfo?.userOrgName == nil, let orgID = userOrganization?.first { + UserInfoManager.shared.fetchOrganizationList(orgID: orgID) + } self.shouldSetNicknameSubject.send(false) } else { self.shouldSetNicknameSubject.send(true) From db92240a50f4de5dfd5af1950ce5e88212c854a7 Mon Sep 17 00:00:00 2001 From: Goban Date: Sat, 3 Dec 2022 12:41:43 +0900 Subject: [PATCH 02/12] =?UTF-8?q?Fix=F0=9F=90=9E:=20=EC=A1=B0=EC=A7=81=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EC=95=88=20=ED=95=9C=20=EC=B1=84=EB=A1=9C?= =?UTF-8?q?=20=EC=95=B1=20=EA=BB=90=EC=BC=B0=ED=95=98=EB=A9=B4=20=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EA=B0=80=EC=A7=80=EC=A7=80=EB=A7=8C=20?= =?UTF-8?q?=EC=A1=B0=EC=A7=81=EC=9D=80=20=EC=97=86=EB=8A=94=20=EC=83=81?= =?UTF-8?q?=ED=83=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift b/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift index fdb65422..6c677c56 100644 --- a/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift +++ b/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift @@ -83,11 +83,12 @@ final class ThirdPartyLoginViewModel { self.shouldSetNicknameSubject.send(true) return } - let userOrganization = UserInfoManager.userInfo?.userOrganization - if userOrganization == nil { + let isEmptyOrganization = UserInfoManager.userInfo?.userOrganization.isEmpty + if isEmptyOrganization == true { self.shouldSetOrganizationSubject.send(true) return } + let userOrganization = UserInfoManager.userInfo?.userOrganization if UserInfoManager.userInfo?.userOrgName == nil, let orgID = userOrganization?.first { UserInfoManager.shared.fetchOrganizationList(orgID: orgID) } From a495b54ceab6bebfd05a47b162896cf3fe4b5ffa Mon Sep 17 00:00:00 2001 From: Goban Date: Sat, 3 Dec 2022 12:44:39 +0900 Subject: [PATCH 03/12] =?UTF-8?q?Chore=F0=9F=A7=B9:=20bind=20function=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/PlaceListViewController.swift | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift b/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift index dde1e0b3..a4cbfac9 100644 --- a/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift +++ b/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift @@ -63,6 +63,18 @@ final class PlaceListViewController: UIViewController { // MARK: - Function + private func analytics() { + FirebaseAnalytics.Analytics.logEvent("place_list_viewed", parameters: [ + AnalyticsParameterScreenName: "place_list" + ]) + } + +} + +// MARK: - Bind Function + +extension PlaceListViewController { + private func bind() { UserInfoManager.shared.isNameFetched .receive(on: DispatchQueue.main) @@ -84,12 +96,6 @@ final class PlaceListViewController: UIViewController { .store(in: &cancelBag) } - private func analytics() { - FirebaseAnalytics.Analytics.logEvent("place_list_viewed", parameters: [ - AnalyticsParameterScreenName: "place_list" - ]) - } - } extension PlaceListViewController: UICollectionViewDataSourcePrefetching, UICollectionViewDelegate { From 1520b544fcdee53a47cd9508158516b12360fdf6 Mon Sep 17 00:00:00 2001 From: Goban Date: Sat, 3 Dec 2022 21:33:55 +0900 Subject: [PATCH 04/12] =?UTF-8?q?Refactor=E2=99=BB=EF=B8=8F:=20orgName=20f?= =?UTF-8?q?etch=20=EC=8B=9C=EC=A0=90=20resonable=ED=95=98=EA=B2=8C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Projects/App/Sources/Application/SceneDelegate.swift | 4 ---- .../UI/Place/PlaceList/View/PlaceListViewController.swift | 6 ++++++ .../UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift | 4 ---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Projects/App/Sources/Application/SceneDelegate.swift b/Projects/App/Sources/Application/SceneDelegate.swift index 88cd1525..f475e819 100644 --- a/Projects/App/Sources/Application/SceneDelegate.swift +++ b/Projects/App/Sources/Application/SceneDelegate.swift @@ -24,14 +24,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let window = UIWindow(windowScene: windowScene) let userAuthToken = KeyChainManager.read(key: .authToken) let userNickName = UserInfoManager.userInfo?.userNickname - let organizationID = UserInfoManager.userInfo?.userOrganization let isEmptyOrganization = UserInfoManager.userInfo?.userOrganization.isEmpty let navigationController = UINavigationController(rootViewController: ThirdPartyLoginViewController()) // 정상적으로 가입을 한경우 if userAuthToken != nil && userNickName != nil && isEmptyOrganization == false { - if UserInfoManager.userInfo?.userOrgName == nil, let orgID = organizationID?.first { - UserInfoManager.shared.fetchOrganizationList(orgID: orgID) - } navigationController.pushViewController(PlaceListViewController(), animated: false) } window.rootViewController = navigationController diff --git a/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift b/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift index a4cbfac9..4739bb42 100644 --- a/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift +++ b/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift @@ -271,6 +271,12 @@ extension PlaceListViewController { let userInfoItem = UIBarButtonItem(image: personCropCircle, style: .plain, target: self, action: #selector(userInfoButtonTapped)) let tapGesture = UITapGestureRecognizer(target: self, action: #selector(orgDetailButtonTapped)) + // TODO: 여러 조직을 가입을 대비하여 확장성 있게 구조 개선 + if UserInfoManager.userInfo?.userOrgName != nil { + placeTitle.text = UserInfoManager.userInfo?.userOrgName + } else if let orgID = UserInfoManager.userInfo?.userOrganization.first { + UserInfoManager.shared.fetchOrganizationList(orgID: orgID) + } placeTitle.text = UserInfoManager.userInfo?.userOrgName ?? "(인증대학없음)" placeTitle.font = .systemFont(ofSize: 17, weight: .bold) placeTitle.isUserInteractionEnabled = true diff --git a/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift b/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift index 6c677c56..97fcb2ef 100644 --- a/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift +++ b/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift @@ -88,10 +88,6 @@ final class ThirdPartyLoginViewModel { self.shouldSetOrganizationSubject.send(true) return } - let userOrganization = UserInfoManager.userInfo?.userOrganization - if UserInfoManager.userInfo?.userOrgName == nil, let orgID = userOrganization?.first { - UserInfoManager.shared.fetchOrganizationList(orgID: orgID) - } self.shouldSetNicknameSubject.send(false) } else { self.shouldSetNicknameSubject.send(true) From 39a9afa046f5af8fae44abb6e637a1935b310280 Mon Sep 17 00:00:00 2001 From: Goban Date: Sat, 3 Dec 2022 21:34:45 +0900 Subject: [PATCH 05/12] =?UTF-8?q?Fix=F0=9F=90=9E:=20UIBarButtonItem=20?= =?UTF-8?q?=EC=9D=84=20=EB=8B=A4=EC=8B=9C=20initial=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=95=84=EC=9B=83=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/Place/PlaceList/View/PlaceListViewController.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift b/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift index 4739bb42..8d7d750e 100644 --- a/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift +++ b/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift @@ -61,6 +61,12 @@ final class PlaceListViewController: UIViewController { bindResult() } + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + // TODO: 계속 sink 가 쌓이면서 중복 실행되는 버그 해결을 위해 임시로 cancelBag 초기화 + cancelBag.removeAll() + } + // MARK: - Function private func analytics() { @@ -80,7 +86,9 @@ extension PlaceListViewController { .receive(on: DispatchQueue.main) .sink { [weak self] _ in guard let self = self else { return } + // TODO: 계속 sink 가 쌓이면서 중복 실행되는 버그가 있음. cancelBag에서 binding이 제대로 해제가 안되는 것 같음. self.placeTitle.text = UserInfoManager.userInfo?.userOrgName + self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: self.placeTitle) } .store(in: &cancelBag) } From 2b2c22704b91484bcc1e5c0677e7192fdcd955ef Mon Sep 17 00:00:00 2001 From: Goban Date: Sat, 3 Dec 2022 21:35:30 +0900 Subject: [PATCH 06/12] =?UTF-8?q?Chore=F0=9F=A7=B9:=20orgName=20=EB=8C=80?= =?UTF-8?q?=EC=B2=B4=20=ED=85=8D=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Projects/App/Sources/Domain/User/UserInfoManager.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Projects/App/Sources/Domain/User/UserInfoManager.swift b/Projects/App/Sources/Domain/User/UserInfoManager.swift index 0949d259..a52e526c 100644 --- a/Projects/App/Sources/Domain/User/UserInfoManager.swift +++ b/Projects/App/Sources/Domain/User/UserInfoManager.swift @@ -127,7 +127,7 @@ extension UserInfoManager: ErrorMapper { case .finished: break } } receiveValue: { [weak self] orgList in - UserInfoManager.userInfo?.userOrgName = orgList.first(where: {$0.id == orgID})?.name ?? "(대학 찾을 수 없음)" + UserInfoManager.userInfo?.userOrgName = orgList.first(where: {$0.id == orgID})?.name ?? "(인증대학없음)" self?.isNameFetched.send(true) } .store(in: &cancelBag) From b322382d90ba90a2d3ef98bb1a410f2cc5d76725 Mon Sep 17 00:00:00 2001 From: Goban Date: Sun, 4 Dec 2022 10:37:06 +0900 Subject: [PATCH 07/12] =?UTF-8?q?Chore=F0=9F=A7=B9:=20=20fetchOrganization?= =?UTF-8?q?List=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EB=B6=84=EB=A6=AC=20TODO?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Projects/App/Sources/Domain/User/UserInfoManager.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Projects/App/Sources/Domain/User/UserInfoManager.swift b/Projects/App/Sources/Domain/User/UserInfoManager.swift index a52e526c..d0eae841 100644 --- a/Projects/App/Sources/Domain/User/UserInfoManager.swift +++ b/Projects/App/Sources/Domain/User/UserInfoManager.swift @@ -111,6 +111,7 @@ final class UserInfoManager { extension UserInfoManager: ErrorMapper { + // TODO: fetchOrganizationList 와 userOrgName 업데이트 분리 func fetchOrganizationList(orgID: Int) { OrganizationAPI.fetchOrgList() .map { orgList in From 1141f9279db00881628c1714a49f64d620dae4eb Mon Sep 17 00:00:00 2001 From: Goban Date: Sun, 4 Dec 2022 11:49:16 +0900 Subject: [PATCH 08/12] =?UTF-8?q?Chore=F0=9F=A7=B9:=20isEmptyOrganization?= =?UTF-8?q?=20unwrapping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift b/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift index 97fcb2ef..adf2aa93 100644 --- a/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift +++ b/Projects/App/Sources/UI/User/Login/ViewModel/ThirdPartyLoginViewModel.swift @@ -83,8 +83,8 @@ final class ThirdPartyLoginViewModel { self.shouldSetNicknameSubject.send(true) return } - let isEmptyOrganization = UserInfoManager.userInfo?.userOrganization.isEmpty - if isEmptyOrganization == true { + let isEmptyOrganization = UserInfoManager.userInfo?.userOrganization.isEmpty ?? true + if isEmptyOrganization { self.shouldSetOrganizationSubject.send(true) return } From 4cba35200629b50faf915c21e692baac8c03c8dd Mon Sep 17 00:00:00 2001 From: Goban Date: Sun, 4 Dec 2022 11:51:37 +0900 Subject: [PATCH 09/12] =?UTF-8?q?Chore=F0=9F=A7=B9:=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20=EC=A3=BC=EC=84=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/Place/PlaceList/View/PlaceListViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift b/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift index 8d7d750e..4f817f0c 100644 --- a/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift +++ b/Projects/App/Sources/UI/Place/PlaceList/View/PlaceListViewController.swift @@ -3,7 +3,8 @@ // App // // Created by 김태호 on 2022/10/25. -// Updated by 고반 on 2022/12/03. +// Updated by 리아 on 2022/11/01. +// Updated userOrg by 고반 on 2022/12/03. // Copyright (c) 2022 zesty. All rights reserved. // From f41cdafeb0f8e4fe1391836a2416bb0a93e5b23a Mon Sep 17 00:00:00 2001 From: Goban Date: Sun, 4 Dec 2022 13:50:44 +0900 Subject: [PATCH 10/12] =?UTF-8?q?Chore=F0=9F=A7=B9:=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=EC=A0=91=EA=B7=BC=20=EC=A0=9C=EC=96=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Projects/App/Sources/Domain/User/UserInfoManager.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Projects/App/Sources/Domain/User/UserInfoManager.swift b/Projects/App/Sources/Domain/User/UserInfoManager.swift index d0eae841..67bc4bd4 100644 --- a/Projects/App/Sources/Domain/User/UserInfoManager.swift +++ b/Projects/App/Sources/Domain/User/UserInfoManager.swift @@ -8,13 +8,18 @@ import Foundation import Combine -import Network final class UserInfoManager { public static let shared = UserInfoManager() private var cancelBag = Set() public var isNameFetched = PassthroughSubject() + + private init(cancelBag: Set = Set(), useCase: UserInfoManagerUseCase = UserInfoManagerUseCase(), isNameFetched: PassthroughSubject = PassthroughSubject()) { + self.cancelBag = cancelBag + self.useCase = useCase + self.isNameFetched = isNameFetched + } private enum UserInfoKeys: String, CaseIterable { case userNickname From 94b8d920ed25fcd1c4a0c9c04523185a6f08661a Mon Sep 17 00:00:00 2001 From: Goban Date: Sun, 4 Dec 2022 13:51:50 +0900 Subject: [PATCH 11/12] =?UTF-8?q?Refactor=E2=99=BB=EF=B8=8F:=20UserInfoMan?= =?UTF-8?q?ager=20useCase=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Domain/User/UserInfoManager.swift | 9 +++----- .../Domain/User/UserInfoManagerUseCase.swift | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 Projects/App/Sources/Domain/User/UserInfoManagerUseCase.swift diff --git a/Projects/App/Sources/Domain/User/UserInfoManager.swift b/Projects/App/Sources/Domain/User/UserInfoManager.swift index 67bc4bd4..35d52406 100644 --- a/Projects/App/Sources/Domain/User/UserInfoManager.swift +++ b/Projects/App/Sources/Domain/User/UserInfoManager.swift @@ -12,6 +12,8 @@ import Combine final class UserInfoManager { public static let shared = UserInfoManager() + + private var useCase = UserInfoManagerUseCase() private var cancelBag = Set() public var isNameFetched = PassthroughSubject() @@ -118,14 +120,9 @@ extension UserInfoManager: ErrorMapper { // TODO: fetchOrganizationList 와 userOrgName 업데이트 분리 func fetchOrganizationList(orgID: Int) { - OrganizationAPI.fetchOrgList() - .map { orgList in - orgList.map { Organization(dto: $0) } - } - .eraseToAnyPublisher() + useCase.fetchOrganizationList() .sink { [weak self] error in guard let self = self else { return } - switch error { case .failure(let error): let errorMessage = self.errorMessage(for: error) diff --git a/Projects/App/Sources/Domain/User/UserInfoManagerUseCase.swift b/Projects/App/Sources/Domain/User/UserInfoManagerUseCase.swift new file mode 100644 index 00000000..3bce44dc --- /dev/null +++ b/Projects/App/Sources/Domain/User/UserInfoManagerUseCase.swift @@ -0,0 +1,23 @@ +// +// UserInfoManagerUseCase.swift +// App +// +// Created by Lee Myeonghwan on 2022/12/04. +// Copyright © 2022 com.zesty. All rights reserved. +// + +import Combine +import Foundation +import Network + +final class UserInfoManagerUseCase { + + func fetchOrganizationList() -> AnyPublisher<[Organization], NetworkError> { + return OrganizationAPI.fetchOrgList() + .map { orgList in + orgList.map { Organization(dto: $0) } + } + .eraseToAnyPublisher() + } + +} From d9a60f3ea919faaffb3f6037532ca1b3305b1090 Mon Sep 17 00:00:00 2001 From: Goban Date: Sun, 4 Dec 2022 20:17:17 +0900 Subject: [PATCH 12/12] =?UTF-8?q?Chore=F0=9F=A7=B9:=20UserInfoManager=20pa?= =?UTF-8?q?ramater=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Projects/App/Sources/Domain/User/UserInfoManager.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Projects/App/Sources/Domain/User/UserInfoManager.swift b/Projects/App/Sources/Domain/User/UserInfoManager.swift index 35d52406..87c8c8d6 100644 --- a/Projects/App/Sources/Domain/User/UserInfoManager.swift +++ b/Projects/App/Sources/Domain/User/UserInfoManager.swift @@ -17,11 +17,7 @@ final class UserInfoManager { private var cancelBag = Set() public var isNameFetched = PassthroughSubject() - private init(cancelBag: Set = Set(), useCase: UserInfoManagerUseCase = UserInfoManagerUseCase(), isNameFetched: PassthroughSubject = PassthroughSubject()) { - self.cancelBag = cancelBag - self.useCase = useCase - self.isNameFetched = isNameFetched - } + private init() {} private enum UserInfoKeys: String, CaseIterable { case userNickname