From bc09e72b2c5f4b71315ecc9f7ddcfc029a8d2585 Mon Sep 17 00:00:00 2001 From: Woogie <100309352+yw22@users.noreply.github.com> Date: Wed, 16 Nov 2022 15:15:29 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[chore]=20=EA=B7=B8=EB=9D=BC=EC=9A=B4?= =?UTF-8?q?=EB=93=9C=EB=A3=B0=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FriendsList/View/FriendsListCell.swift | 12 ++++++------ .../FriendsList/View/FriendsViewController.swift | 6 +++--- .../FriendsList/ViewModel/FriendsListViewModel.swift | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsListCell.swift b/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsListCell.swift index 7a0bb126..bb441e09 100644 --- a/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsListCell.swift +++ b/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsListCell.swift @@ -54,10 +54,10 @@ final class FriendsListCell: UITableViewCell { } private func configureConstraints() { - configureImg() - configureName() - configureuserDescription() - configurContentView() + self.configureImg() + self.configureName() + self.configureUserDescription() + self.configureContentView() } private func configureImg() { @@ -78,7 +78,7 @@ final class FriendsListCell: UITableViewCell { } } - private func configureuserDescription() { + private func configureUserDescription() { self.userDescription.snp.makeConstraints { make in make.leading.equalTo(self.img.snp.trailing).offset(16) make.trailing.equalTo(self.contentView).offset(-16) @@ -87,7 +87,7 @@ final class FriendsListCell: UITableViewCell { } } - private func configurContentView() { + private func configureContentView() { self.contentView.layer.borderColor = UIColor.gray.cgColor self.contentView.layer.borderWidth = 0.5 } diff --git a/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsViewController.swift b/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsViewController.swift index 9e07a47d..2d68e3d1 100644 --- a/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsViewController.swift +++ b/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsViewController.swift @@ -25,8 +25,8 @@ final class FriendsListViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - addSubviews() - configureConstraints() + self.addSubviews() + self.configureConstraints() } // MARK: - Helper @@ -46,7 +46,7 @@ final class FriendsListViewController: UIViewController { } private func configureTableView() { - tableView.snp.makeConstraints { make in + self.tableView.snp.makeConstraints { make in make.top.equalTo(self.view.safeAreaLayoutGuide) make.bottom.trailing.leading.equalTo(view) } diff --git a/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift b/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift index 27226002..a83ba29f 100644 --- a/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift +++ b/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift @@ -11,7 +11,7 @@ final class FriendsListViewModel { var friendsListDummyData: [FriendsListModel] = [] init() { - createDummyData() + self.createDummyData() } private func createDummyData() { From 46649efe79ae6a6f496d732ea90909473f7d5287 Mon Sep 17 00:00:00 2001 From: Woogie <100309352+yw22@users.noreply.github.com> Date: Mon, 21 Nov 2022 15:45:24 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[Feat]=20ViewModel,=20UseCase=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NearTalk/NearTalk.xcodeproj/project.pbxproj | 20 +++--- .../DIContainer/FriendListDIContainer.swift | 65 +++++++++++++++++++ .../NearTalk/Domain/Entities/Friend.swift | 16 +++++ .../UseCases/FetchFriendListUseCase.swift | 39 +++++++++++ .../Coordinator/FriendsListCoordinator.swift | 31 +++++++++ .../ViewModel/FriendsListModel.swift | 14 ---- .../ViewModel/FriendsListViewModel.swift | 62 +++++++++++++----- 7 files changed, 210 insertions(+), 37 deletions(-) create mode 100644 NearTalk/NearTalk/Application/DIContainer/FriendListDIContainer.swift create mode 100644 NearTalk/NearTalk/Domain/Entities/Friend.swift create mode 100644 NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift delete mode 100644 NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListModel.swift diff --git a/NearTalk/NearTalk.xcodeproj/project.pbxproj b/NearTalk/NearTalk.xcodeproj/project.pbxproj index 94c07475..61af2337 100644 --- a/NearTalk/NearTalk.xcodeproj/project.pbxproj +++ b/NearTalk/NearTalk.xcodeproj/project.pbxproj @@ -34,10 +34,12 @@ 1660D24E291DDB3A005F7B24 /* NearTalkUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1660D24D291DDB3A005F7B24 /* NearTalkUITestsLaunchTests.swift */; }; 1660D266291DE092005F7B24 /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1660D265291DE092005F7B24 /* AppCoordinator.swift */; }; 1660D27A291E09CE005F7B24 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 1660D279291E09CE005F7B24 /* .swiftlint.yml */; }; + 5506CDDB292B4D270002F328 /* FriendListDIContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5506CDDA292B4D270002F328 /* FriendListDIContainer.swift */; }; + 5506CDDD292B4F810002F328 /* FetchFriendListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5506CDDC292B4F810002F328 /* FetchFriendListUseCase.swift */; }; + 5506CDDF292B50D10002F328 /* Friend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5506CDDE292B50D10002F328 /* Friend.swift */; }; 555A6B2B29236D51001336ED /* FriendsListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B2A29236D51001336ED /* FriendsListCell.swift */; }; 555A6B2D29236D61001336ED /* FriendsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B2C29236D61001336ED /* FriendsViewController.swift */; }; 555A6B2F29236D73001336ED /* FriendsListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B2E29236D73001336ED /* FriendsListViewModel.swift */; }; - 555A6B3129236D86001336ED /* FriendsListModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3029236D86001336ED /* FriendsListModel.swift */; }; 555A6B3329236D98001336ED /* FriendsListCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3229236D98001336ED /* FriendsListCoordinator.swift */; }; 555A6B3529238C13001336ED /* ChatRoomListDIContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3429238C13001336ED /* ChatRoomListDIContainer.swift */; }; 555A6B3829238C69001336ED /* ChatRoomList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3729238C69001336ED /* ChatRoomList.swift */; }; @@ -61,7 +63,6 @@ 603EDDB12926C87700BEE65C /* RootTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 603EDDB02926C87700BEE65C /* RootTabBarController.swift */; }; 603EDDB32926C89000BEE65C /* RootTabBarViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 603EDDB22926C89000BEE65C /* RootTabBarViewModel.swift */; }; 603EDDB62926C89C00BEE65C /* RootTabBarCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 603EDDB52926C89C00BEE65C /* RootTabBarCoordinator.swift */; }; - 603FD0BD2928C23600687ED4 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 603FD0BC2928C23600687ED4 /* README.md */; }; 603FD3622928D40300687ED4 /* .FirebaseDatabaseBinary.version in Resources */ = {isa = PBXBuildFile; fileRef = 603FD33D2928D40300687ED4 /* .FirebaseDatabaseBinary.version */; }; 603FD3632928D40300687ED4 /* nanopb.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 603FD33E2928D40300687ED4 /* nanopb.xcframework */; }; 603FD3642928D40300687ED4 /* FirebaseDynamicLinks.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 603FD33F2928D40300687ED4 /* FirebaseDynamicLinks.xcframework */; }; @@ -216,10 +217,12 @@ 3AC46AE5352F041440185296 /* Pods_NearTalkTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NearTalkTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3BDD85385ADBE469FA3E4B6B /* Pods-NearTalkTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NearTalkTests.release.xcconfig"; path = "Target Support Files/Pods-NearTalkTests/Pods-NearTalkTests.release.xcconfig"; sourceTree = ""; }; 4585BFB6386FB019591AD279 /* Pods_NearTalk_NearTalkUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NearTalk_NearTalkUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 5506CDDA292B4D270002F328 /* FriendListDIContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendListDIContainer.swift; sourceTree = ""; }; + 5506CDDC292B4F810002F328 /* FetchFriendListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchFriendListUseCase.swift; sourceTree = ""; }; + 5506CDDE292B50D10002F328 /* Friend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Friend.swift; sourceTree = ""; }; 555A6B2A29236D51001336ED /* FriendsListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsListCell.swift; sourceTree = ""; }; 555A6B2C29236D61001336ED /* FriendsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsViewController.swift; sourceTree = ""; }; 555A6B2E29236D73001336ED /* FriendsListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsListViewModel.swift; sourceTree = ""; }; - 555A6B3029236D86001336ED /* FriendsListModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsListModel.swift; sourceTree = ""; }; 555A6B3229236D98001336ED /* FriendsListCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsListCoordinator.swift; sourceTree = ""; }; 555A6B3429238C13001336ED /* ChatRoomListDIContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomListDIContainer.swift; sourceTree = ""; }; 555A6B3729238C69001336ED /* ChatRoomList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomList.swift; sourceTree = ""; }; @@ -243,7 +246,6 @@ 603EDDB02926C87700BEE65C /* RootTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootTabBarController.swift; sourceTree = ""; }; 603EDDB22926C89000BEE65C /* RootTabBarViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootTabBarViewModel.swift; sourceTree = ""; }; 603EDDB52926C89C00BEE65C /* RootTabBarCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootTabBarCoordinator.swift; sourceTree = ""; }; - 603FD0BC2928C23600687ED4 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 603FD33D2928D40300687ED4 /* .FirebaseDatabaseBinary.version */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .FirebaseDatabaseBinary.version; sourceTree = ""; }; 603FD33E2928D40300687ED4 /* nanopb.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = nanopb.xcframework; sourceTree = ""; }; 603FD33F2928D40300687ED4 /* FirebaseDynamicLinks.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = FirebaseDynamicLinks.xcframework; sourceTree = ""; }; @@ -506,7 +508,6 @@ 1660D21B291DDB37005F7B24 = { isa = PBXGroup; children = ( - 603FD0BC2928C23600687ED4 /* README.md */, 1660D279291E09CE005F7B24 /* .swiftlint.yml */, 60DCAAF32928B9610087A63D /* Cartfile */, 603FD33C2928D40300687ED4 /* Build */, @@ -676,6 +677,7 @@ 555A6B472924BE65001336ED /* UserProfile.swift */, 6008FC9C2925DBCF0044F017 /* NCLocation.swift */, 603EDDA22926C01D00BEE65C /* UserChatModel.swift */, + 5506CDDE292B50D10002F328 /* Friend.swift */, ); path = Entities; sourceTree = ""; @@ -690,6 +692,7 @@ 7CE8063A2925312100D828FF /* ProfileDetailUseCase.swift */, 83D3543E29253A5C00B9236A /* MyProfileLoadUseCase.swift */, 603EDDA62926C4B300BEE65C /* TabBarUseCase.swift */, + 5506CDDC292B4F810002F328 /* FetchFriendListUseCase.swift */, ); path = UseCases; sourceTree = ""; @@ -737,7 +740,6 @@ isa = PBXGroup; children = ( 555A6B2E29236D73001336ED /* FriendsListViewModel.swift */, - 555A6B3029236D86001336ED /* FriendsListModel.swift */, ); path = ViewModel; sourceTree = ""; @@ -885,6 +887,7 @@ 555A6B3429238C13001336ED /* ChatRoomListDIContainer.swift */, 83D3543929252F1A00B9236A /* MyProfileDIContainer.swift */, 603EDDA42926C43500BEE65C /* RootTabBarDIContainer.swift */, + 5506CDDA292B4D270002F328 /* FriendListDIContainer.swift */, ); path = DIContainer; sourceTree = ""; @@ -1409,6 +1412,7 @@ 1648BABC2925CDDE0076AC35 /* BottomSheetViewController.swift in Sources */, 603EDDB12926C87700BEE65C /* RootTabBarController.swift in Sources */, 603EDDA32926C01D00BEE65C /* UserChatModel.swift in Sources */, + 5506CDDF292B50D10002F328 /* Friend.swift in Sources */, 60FD706A2924080A00A4C29A /* ChatMessage.swift in Sources */, 555A6B2F29236D73001336ED /* FriendsListViewModel.swift in Sources */, 6012734929221F4800E1456B /* LaunchScreenUseCase.swift in Sources */, @@ -1425,13 +1429,11 @@ 601273402921D34000E1456B /* LaunchScreenViewModel.swift in Sources */, 555A6B3829238C69001336ED /* ChatRoomList.swift in Sources */, 16530582291E19350026B815 /* ChatRoomListCoordinator.swift in Sources */, - 603FD0BD2928C23600687ED4 /* README.md in Sources */, 60FD70622923927C00A4C29A /* NonceGenerator.swift in Sources */, 16530576291E17F70026B815 /* UIViewController+Preview.swift in Sources */, 83D354412925412400B9236A /* UserProfileRepository.swift in Sources */, 7CFC7D6C2923710200A249E7 /* RangeZoneView.swift in Sources */, 8367AB642922AF6300678669 /* ProfileSettingViewController.swift in Sources */, - 555A6B3129236D86001336ED /* FriendsListModel.swift in Sources */, 1660D228291DDB37005F7B24 /* AppDelegate.swift in Sources */, 1660D266291DE092005F7B24 /* AppCoordinator.swift in Sources */, 7CE806412925528F00D828FF /* CreateGroupChatUseCase.swift in Sources */, @@ -1443,6 +1445,7 @@ 83D354432925414F00B9236A /* DefaultUserProfileRepository.swift in Sources */, 1648BA9B2921D7570076AC35 /* MainMapViewController.swift in Sources */, 83E7BBC82922AFED007C390A /* AppSettingViewController.swift in Sources */, + 5506CDDB292B4D270002F328 /* FriendListDIContainer.swift in Sources */, 1648BAAF292387020076AC35 /* GroupChatRoomAnnotationView.swift in Sources */, 7CE8063D29253A3800D828FF /* ProfileDetailCoordinator.swift in Sources */, 7C6684AE2924BC9E00A5E10A /* ProfileDetailViewModel.swift in Sources */, @@ -1453,6 +1456,7 @@ 1648BA972921D73E0076AC35 /* MainMapViewModel.swift in Sources */, 16530580291E19250026B815 /* ChatRoomListViewModel.swift in Sources */, 60FD705D29238CBB00A4C29A /* RealTimeDatabaseService.swift in Sources */, + 5506CDDD292B4F810002F328 /* FetchFriendListUseCase.swift in Sources */, 60FD705C29238CBB00A4C29A /* StorageService.swift in Sources */, 555A6B2D29236D61001336ED /* FriendsViewController.swift in Sources */, 1660D22A291DDB38005F7B24 /* SceneDelegate.swift in Sources */, diff --git a/NearTalk/NearTalk/Application/DIContainer/FriendListDIContainer.swift b/NearTalk/NearTalk/Application/DIContainer/FriendListDIContainer.swift new file mode 100644 index 00000000..f10560f0 --- /dev/null +++ b/NearTalk/NearTalk/Application/DIContainer/FriendListDIContainer.swift @@ -0,0 +1,65 @@ +// +// FreindListDIContainer.swift +// NearTalk +// +// Created by 김영욱 on 2022/11/21. +// + +import UIKit + +// ChatRoomListDIContainer가 필요한 DIContainer +final class XXDIContainer { + // MARK: - 필요한 데이터를 가저올 네트워크 통신 + lazy var apiDataStorageService: DefaultStorageService = { + // api -> Data 변환 + return DefaultStorageService() + }() + + lazy var imageDataStorageService: DefaultStorageService = { + // api -> Data 변환 + return DefaultStorageService() + }() + + func makeChatRoomListDIContainer() -> ChatRoomListDIContainer { + let dependencies = ChatRoomListDIContainer.Dependencies(apiDataTransferService: apiDataStorageService, imageDataTransferService: imageDataStorageService) + return ChatRoomListDIContainer(dependencies: dependencies) + } +} + +final class FreindListDIContainer { + + // MARK: - Dependencies + struct Dependencies { + let apiDataTransferService: DefaultStorageService + let imageDataTransferService: DefaultStorageService + } + + private let dependencies: Dependencies + + // MARK: - Persistent Storage + init(dependencies: Dependencies) { + self.dependencies = dependencies + } + + // MARK: - Services + + // MARK: - UseCases + func makeFreindListUseCase() -> ChatRoomListUseCase { + return DefaultChatRoomListUseCase(chatRoomListRepository: self.makeRepository()) + } + + // MARK: - Repositories + func makeRepository() -> ChatRoomListRepository { + return DefaultChatRoomListRepository(dataTransferService: dependencies.apiDataTransferService) + } + + // ExampleMVVM에서는 보여줄수 있는 Scene의 뷰컨트롤러와 뷰모델이 존재 + + + // MARK: - Coordinator + func makeChatRoomListCoordinator(navigationController: UINavigationController) -> ChatRoomListCoordinator { + return ChatRoomListCoordinator(navigationController: navigationController, dependencies: self) + } +} + +extension ChatRoomListDIContainer: ChatRoomListCoordinatorDependencies {} diff --git a/NearTalk/NearTalk/Domain/Entities/Friend.swift b/NearTalk/NearTalk/Domain/Entities/Friend.swift new file mode 100644 index 00000000..65ea9fef --- /dev/null +++ b/NearTalk/NearTalk/Domain/Entities/Friend.swift @@ -0,0 +1,16 @@ +// +// Friends.swift +// NearTalk +// +// Created by 김영욱 on 2022/11/21. +// + +import Foundation + +struct FriendInfo: Codable { + /// 유저 UUID + var userID: String? + var username: String? + var statusMessage: String? + var profileImagePath: String? +} diff --git a/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift b/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift new file mode 100644 index 00000000..e60a924e --- /dev/null +++ b/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift @@ -0,0 +1,39 @@ +// +// FetchFriendListUseCase.swift +// NearTalk +// +// Created by 김영욱 on 2022/11/21. +// + +import Foundation +import RxSwift + +protocol FetchFriendListUseCase { + func getFriendListData() -> Observable<[FriendInfo]> +} + +final class DefaultFetchFriendListUseCase: FetchFriendListUseCase { + + private let disposeBag = DisposeBag() + private let userUUIDRepository: UserUUIDRepository! + private let userProfileRepository: UserProfileRepository! + private let fireStoreService: FireStoreService! + private let userProfile: Single + + init(userUUIDRepository: UserUUIDRepository, userProfileRepository: UserProfileRepository, fireStoreService: FireStoreService) { + self.userUUIDRepository = userUUIDRepository + self.userProfileRepository = userProfileRepository + + self.userProfile = fireStoreService.getMyProfile() + } + + func getFriendListData() -> Observable<[FriendInfo]> { + self.userProfile + .asObservable() + .subscribe(onNext: { profile in + profile?.chatRooms + }) + .disposed(by: disposeBag) + } + +} diff --git a/NearTalk/NearTalk/Presentation/FriendsList/Coordinator/FriendsListCoordinator.swift b/NearTalk/NearTalk/Presentation/FriendsList/Coordinator/FriendsListCoordinator.swift index af781877..616026d9 100644 --- a/NearTalk/NearTalk/Presentation/FriendsList/Coordinator/FriendsListCoordinator.swift +++ b/NearTalk/NearTalk/Presentation/FriendsList/Coordinator/FriendsListCoordinator.swift @@ -6,3 +6,34 @@ // import Foundation + +import UIKit + +protocol FriendLsitCoordinatorDependencies { + +} + +final class FriendListCoordinator { + private weak var navigationController: UINavigationController? + +// private let dependencies: ChatRoomListCoordinatorDependencies + + private weak var friendListViewController: FriendsListViewController? + + // MARK: - Init + init(navigationController: UINavigationController, dependencies: ChatRoomListCoordinatorDependencies) { + self.navigationController = navigationController + self.dependencies = dependencies + } + + // MARK: - Lifecycles + func start() { + // action + + + } + + // MARK: - Dependency + + +} diff --git a/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListModel.swift b/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListModel.swift deleted file mode 100644 index f5b1e2e7..00000000 --- a/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListModel.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// FriendsListModel.swift -// NearTalk -// -// Created by 김영욱 on 2022/11/15. -// - -import Foundation - -struct FriendsListModel: Hashable { - var img: String - var name: String - var description: String -} diff --git a/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift b/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift index a83ba29f..a3d48d04 100644 --- a/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift +++ b/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift @@ -6,25 +6,57 @@ // import Foundation +import RxRelay +import RxSwift -final class FriendsListViewModel { - var friendsListDummyData: [FriendsListModel] = [] +struct FriendistViewModelActions { + let showDetailFriend: () -> Void +} + +protocol FriendListViewModelInput { + func didSelectItem(at index: Int) + func addFriendButton() +} + +protocol FriendListViewModelOutput { + var friendListData: BehaviorRelay<[String]> { get } +} + +protocol FriendListViewModel: FriendListViewModelInput, FriendListViewModelOutput {} + +final class FriendsListViewModel: FriendListViewModel { + + private let friendListUseCase: FetchFriendListUseCase + private let actions: FriendistViewModelActions? + private let disposeBag: DisposeBag = DisposeBag() + + // MARK: - OUTPUT + var friendListData: RxRelay.BehaviorRelay<[String]> init() { - self.createDummyData() + } - private func createDummyData() { - friendsListDummyData.append(FriendsListModel(img: "", name: "Ronald Robertson", description: "An suas viderer pro. Vis cu magna altera, ex his vivendo atomorum.")) - friendsListDummyData.append(FriendsListModel(img: "", name: "Johnny Watson", description: "Reprehenderit mollit excepteur labore deserunt officia laboris eiusmod cillum eu duis")) - friendsListDummyData.append(FriendsListModel(img: "", name: "Annette Cooper", description: "Aliqua mollit nisi incididunt id eu consequat eu cupidatat.")) - friendsListDummyData.append(FriendsListModel(img: "", name: "Arthur Bell", description: "Voluptate irure aliquip consectetur commodo ex ex.")) - friendsListDummyData.append(FriendsListModel(img: "", name: "Jane Warren", description: "Ex Lorem veniam veniam irure sunt adipisicing culpa.")) - friendsListDummyData.append(FriendsListModel(img: "", name: "Morris Henry", description: "Dolore veniam Lorem occaecat veniam irure laborum est amet.")) - friendsListDummyData.append(FriendsListModel(img: "", name: "Irma Flores", description: "Amet enim do laborum tempor nisi aliqua ad adipisicing.")) - friendsListDummyData.append(FriendsListModel(img: "", name: "008", description: "qwer")) - friendsListDummyData.append(FriendsListModel(img: "", name: "009", description: "asdf")) - friendsListDummyData.append(FriendsListModel(img: "", name: "010", description: "zxcv")) - + // MARK: - INPUT + func didSelectItem(at index: Int) { + } + + func addFriendButton() { + + } + +// private func createDummyData() { +// friendsListDummyData.append(FriendsListModel(img: "", name: "Ronald Robertson", description: "An suas viderer pro. Vis cu magna altera, ex his vivendo atomorum.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Johnny Watson", description: "Reprehenderit mollit excepteur labore deserunt officia laboris eiusmod cillum eu duis")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Annette Cooper", description: "Aliqua mollit nisi incididunt id eu consequat eu cupidatat.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Arthur Bell", description: "Voluptate irure aliquip consectetur commodo ex ex.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Jane Warren", description: "Ex Lorem veniam veniam irure sunt adipisicing culpa.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Morris Henry", description: "Dolore veniam Lorem occaecat veniam irure laborum est amet.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Irma Flores", description: "Amet enim do laborum tempor nisi aliqua ad adipisicing.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "008", description: "qwer")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "009", description: "asdf")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "010", description: "zxcv")) +// +// } } From 32fa62a8a3b014dc9b425c8720f574d53882bfc8 Mon Sep 17 00:00:00 2001 From: Woogie <100309352+yw22@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:26:39 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[Feat]=20Coordinator,=20Usecase=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NearTalk/NearTalk.xcodeproj/project.pbxproj | 38 +++++----- .../DIContainer/FriendListDIContainer.swift | 73 ++++++++++--------- .../DIContainer/RootTabBarDIContainer.swift | 2 +- .../NearTalk/Domain/Entities/Friend.swift | 17 ++++- .../UseCases/FetchFriendListUseCase.swift | 31 ++++---- .../ViewModel/ChatRoomListViewModel.swift | 6 +- .../Coordinator/FriendListCoordinator.swift | 45 ++++++++++++ .../View/FriendListCell.swift} | 8 +- .../View/FriendViewController.swift} | 37 +++++----- .../ViewModel/FriendListViewModel.swift | 54 ++++++++++++++ .../Coordinator/FriendsListCoordinator.swift | 39 ---------- .../ViewModel/FriendsListViewModel.swift | 62 ---------------- .../TabBar/View/RootTabBarController.swift | 2 +- 13 files changed, 212 insertions(+), 202 deletions(-) create mode 100644 NearTalk/NearTalk/Presentation/FriendList/Coordinator/FriendListCoordinator.swift rename NearTalk/NearTalk/Presentation/{FriendsList/View/FriendsListCell.swift => FriendList/View/FriendListCell.swift} (93%) rename NearTalk/NearTalk/Presentation/{FriendsList/View/FriendsViewController.swift => FriendList/View/FriendViewController.swift} (67%) create mode 100644 NearTalk/NearTalk/Presentation/FriendList/ViewModel/FriendListViewModel.swift delete mode 100644 NearTalk/NearTalk/Presentation/FriendsList/Coordinator/FriendsListCoordinator.swift delete mode 100644 NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift diff --git a/NearTalk/NearTalk.xcodeproj/project.pbxproj b/NearTalk/NearTalk.xcodeproj/project.pbxproj index 66606a10..84acd23d 100644 --- a/NearTalk/NearTalk.xcodeproj/project.pbxproj +++ b/NearTalk/NearTalk.xcodeproj/project.pbxproj @@ -37,10 +37,10 @@ 5506CDDB292B4D270002F328 /* FriendListDIContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5506CDDA292B4D270002F328 /* FriendListDIContainer.swift */; }; 5506CDDD292B4F810002F328 /* FetchFriendListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5506CDDC292B4F810002F328 /* FetchFriendListUseCase.swift */; }; 5506CDDF292B50D10002F328 /* Friend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5506CDDE292B50D10002F328 /* Friend.swift */; }; - 555A6B2B29236D51001336ED /* FriendsListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B2A29236D51001336ED /* FriendsListCell.swift */; }; - 555A6B2D29236D61001336ED /* FriendsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B2C29236D61001336ED /* FriendsViewController.swift */; }; - 555A6B2F29236D73001336ED /* FriendsListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B2E29236D73001336ED /* FriendsListViewModel.swift */; }; - 555A6B3329236D98001336ED /* FriendsListCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3229236D98001336ED /* FriendsListCoordinator.swift */; }; + 555A6B2B29236D51001336ED /* FriendListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B2A29236D51001336ED /* FriendListCell.swift */; }; + 555A6B2D29236D61001336ED /* FriendViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B2C29236D61001336ED /* FriendViewController.swift */; }; + 555A6B2F29236D73001336ED /* FriendListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B2E29236D73001336ED /* FriendListViewModel.swift */; }; + 555A6B3329236D98001336ED /* FriendListCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3229236D98001336ED /* FriendListCoordinator.swift */; }; 555A6B3529238C13001336ED /* ChatRoomListDIContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3429238C13001336ED /* ChatRoomListDIContainer.swift */; }; 555A6B3829238C69001336ED /* ChatRoomList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3729238C69001336ED /* ChatRoomList.swift */; }; 555A6B3A29238C9B001336ED /* ChatRoomListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3929238C9B001336ED /* ChatRoomListUseCase.swift */; }; @@ -225,10 +225,10 @@ 5506CDDA292B4D270002F328 /* FriendListDIContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendListDIContainer.swift; sourceTree = ""; }; 5506CDDC292B4F810002F328 /* FetchFriendListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchFriendListUseCase.swift; sourceTree = ""; }; 5506CDDE292B50D10002F328 /* Friend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Friend.swift; sourceTree = ""; }; - 555A6B2A29236D51001336ED /* FriendsListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsListCell.swift; sourceTree = ""; }; - 555A6B2C29236D61001336ED /* FriendsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsViewController.swift; sourceTree = ""; }; - 555A6B2E29236D73001336ED /* FriendsListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsListViewModel.swift; sourceTree = ""; }; - 555A6B3229236D98001336ED /* FriendsListCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsListCoordinator.swift; sourceTree = ""; }; + 555A6B2A29236D51001336ED /* FriendListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendListCell.swift; sourceTree = ""; }; + 555A6B2C29236D61001336ED /* FriendViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendViewController.swift; sourceTree = ""; }; + 555A6B2E29236D73001336ED /* FriendListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendListViewModel.swift; sourceTree = ""; }; + 555A6B3229236D98001336ED /* FriendListCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendListCoordinator.swift; sourceTree = ""; }; 555A6B3429238C13001336ED /* ChatRoomListDIContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomListDIContainer.swift; sourceTree = ""; }; 555A6B3729238C69001336ED /* ChatRoomList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomList.swift; sourceTree = ""; }; 555A6B3929238C9B001336ED /* ChatRoomListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomListUseCase.swift; sourceTree = ""; }; @@ -600,7 +600,7 @@ 603EDDAC2926C84E00BEE65C /* TabBar */, 7CFC7D6D2923748E00A249E7 /* ProfileDetail */, 7CFC7D672923709C00A249E7 /* CreatGroupChat */, - 555A6B2629236C28001336ED /* FriendsList */, + 555A6B2629236C28001336ED /* FriendList */, 1648BA922921D7240076AC35 /* MainMap */, 83E7F8C72922AB750003A2B6 /* MyProfile */, 8375F2202922B043004538AF /* Onboarding */, @@ -734,20 +734,20 @@ path = Repositories; sourceTree = ""; }; - 555A6B2629236C28001336ED /* FriendsList */ = { + 555A6B2629236C28001336ED /* FriendList */ = { isa = PBXGroup; children = ( 555A6B2929236C65001336ED /* View */, 555A6B2829236C5D001336ED /* ViewModel */, 555A6B2729236C51001336ED /* Coordinator */, ); - path = FriendsList; + path = FriendList; sourceTree = ""; }; 555A6B2729236C51001336ED /* Coordinator */ = { isa = PBXGroup; children = ( - 555A6B3229236D98001336ED /* FriendsListCoordinator.swift */, + 555A6B3229236D98001336ED /* FriendListCoordinator.swift */, ); path = Coordinator; sourceTree = ""; @@ -755,7 +755,7 @@ 555A6B2829236C5D001336ED /* ViewModel */ = { isa = PBXGroup; children = ( - 555A6B2E29236D73001336ED /* FriendsListViewModel.swift */, + 555A6B2E29236D73001336ED /* FriendListViewModel.swift */, ); path = ViewModel; sourceTree = ""; @@ -763,8 +763,8 @@ 555A6B2929236C65001336ED /* View */ = { isa = PBXGroup; children = ( - 555A6B2A29236D51001336ED /* FriendsListCell.swift */, - 555A6B2C29236D61001336ED /* FriendsViewController.swift */, + 555A6B2A29236D51001336ED /* FriendListCell.swift */, + 555A6B2C29236D61001336ED /* FriendViewController.swift */, ); path = View; sourceTree = ""; @@ -1430,7 +1430,7 @@ 8349529E2925FEAE004C5B3B /* ImageRepository.swift in Sources */, 60FD706029238DD400A4C29A /* FirebaseAuthService.swift in Sources */, 834952A02925FEF0004C5B3B /* DefaultImageRepository.swift in Sources */, - 555A6B3329236D98001336ED /* FriendsListCoordinator.swift in Sources */, + 555A6B3329236D98001336ED /* FriendListCoordinator.swift in Sources */, 6008FC9D2925DBCF0044F017 /* NCLocation.swift in Sources */, 6073A3AE2928AE9800D51CFD /* Codable+Dictionary.swift in Sources */, 603FD39C292B4F4A00687ED4 /* LogoutUseCase.swift in Sources */, @@ -1439,7 +1439,7 @@ 83D3544C2925623600B9236A /* UIImageView+Rounded.swift in Sources */, 603EDDA72926C4B300BEE65C /* TabBarUseCase.swift in Sources */, 603EDD6329261A2000BEE65C /* FirebaseKey.swift in Sources */, - 555A6B2B29236D51001336ED /* FriendsListCell.swift in Sources */, + 555A6B2B29236D51001336ED /* FriendListCell.swift in Sources */, 83D35446292541B500B9236A /* MyProfileViewModel.swift in Sources */, 605715A62920AA19004A0904 /* LaunchScreenDIContainer.swift in Sources */, 1648BABC2925CDDE0076AC35 /* BottomSheetViewController.swift in Sources */, @@ -1447,7 +1447,7 @@ 603EDDA32926C01D00BEE65C /* UserChatModel.swift in Sources */, 5506CDDF292B50D10002F328 /* Friend.swift in Sources */, 60FD706A2924080A00A4C29A /* ChatMessage.swift in Sources */, - 555A6B2F29236D73001336ED /* FriendsListViewModel.swift in Sources */, + 555A6B2F29236D73001336ED /* FriendListViewModel.swift in Sources */, 16530578291E18560026B815 /* UIViewPreview.swift in Sources */, 833062292924A3D7000E786E /* OnboardingDIContainer.swift in Sources */, 83D3543A29252F1A00B9236A /* MyProfileDIContainer.swift in Sources */, @@ -1496,7 +1496,7 @@ 60FD705D29238CBB00A4C29A /* RealTimeDatabaseService.swift in Sources */, 5506CDDD292B4F810002F328 /* FetchFriendListUseCase.swift in Sources */, 60FD705C29238CBB00A4C29A /* StorageService.swift in Sources */, - 555A6B2D29236D61001336ED /* FriendsViewController.swift in Sources */, + 555A6B2D29236D61001336ED /* FriendViewController.swift in Sources */, 1660D22A291DDB38005F7B24 /* SceneDelegate.swift in Sources */, 603EDDB62926C89C00BEE65C /* RootTabBarCoordinator.swift in Sources */, 7CFC7D70292374BD00A249E7 /* ProfileDetailViewController.swift in Sources */, diff --git a/NearTalk/NearTalk/Application/DIContainer/FriendListDIContainer.swift b/NearTalk/NearTalk/Application/DIContainer/FriendListDIContainer.swift index f10560f0..58a61840 100644 --- a/NearTalk/NearTalk/Application/DIContainer/FriendListDIContainer.swift +++ b/NearTalk/NearTalk/Application/DIContainer/FriendListDIContainer.swift @@ -1,5 +1,5 @@ // -// FreindListDIContainer.swift +// FriendListDIContainer.swift // NearTalk // // Created by 김영욱 on 2022/11/21. @@ -7,31 +7,12 @@ import UIKit -// ChatRoomListDIContainer가 필요한 DIContainer -final class XXDIContainer { - // MARK: - 필요한 데이터를 가저올 네트워크 통신 - lazy var apiDataStorageService: DefaultStorageService = { - // api -> Data 변환 - return DefaultStorageService() - }() - - lazy var imageDataStorageService: DefaultStorageService = { - // api -> Data 변환 - return DefaultStorageService() - }() - - func makeChatRoomListDIContainer() -> ChatRoomListDIContainer { - let dependencies = ChatRoomListDIContainer.Dependencies(apiDataTransferService: apiDataStorageService, imageDataTransferService: imageDataStorageService) - return ChatRoomListDIContainer(dependencies: dependencies) - } -} - -final class FreindListDIContainer { +final class FriendListDIContainer { // MARK: - Dependencies struct Dependencies { - let apiDataTransferService: DefaultStorageService - let imageDataTransferService: DefaultStorageService + let firestoreService: FirestoreService + let firebaseAuthService: FirebaseAuthService } private let dependencies: Dependencies @@ -40,26 +21,50 @@ final class FreindListDIContainer { init(dependencies: Dependencies) { self.dependencies = dependencies } - + // MARK: - Services - + // MARK: - UseCases - func makeFreindListUseCase() -> ChatRoomListUseCase { - return DefaultChatRoomListUseCase(chatRoomListRepository: self.makeRepository()) + func makeFetchFriendListUseCase() -> FetchFriendListUseCase { + return DefaultFetchFriendListUseCase(profileRepository: self.makeRepository()) + } + + func makeProfileDetailUseCaseAble() -> ProfileDetailUseCaseAble { + return ProfileDetailUseCase() } // MARK: - Repositories - func makeRepository() -> ChatRoomListRepository { - return DefaultChatRoomListRepository(dataTransferService: dependencies.apiDataTransferService) + func makeRepository() -> ProfileRepository { + return DefaultProfileRepository(firestoreService: dependencies.firestoreService, firebaseAuthService: dependencies.firebaseAuthService) } - // ExampleMVVM에서는 보여줄수 있는 Scene의 뷰컨트롤러와 뷰모델이 존재 - + // MARK: - Friend Lsit + func makeFriendListViewController(actions: FriendListViewModelActions) -> FriendListViewController { + return FriendListViewController.create(with: self.makeFriendListViewModel(actions: actions)) + } + + func makeFriendListViewModel(actions: FriendListViewModelActions) -> FriendListViewModel { + return DefaultFriendListViewModel(useCase: self.makeFetchFriendListUseCase(), actions: actions) + } + + // MARK: - Profile Detail +// func makeProfileDetailViewController() -> ProfileDetailViewController { +// return ProfileDetailViewController(viewModel: makeProfileDetailViewModel()) +// } +// +// func makeProfileDetailViewModel() -> ProfileDetailViewModel { +// return ProfileDetailViewModel(profileDetailUseCase: self.makeProfileDetailUseCaseAble(), profileDetailCoordinator: self.makeProfileDetailCoordinator(makeFriendListCoordinator)) +// } // MARK: - Coordinator - func makeChatRoomListCoordinator(navigationController: UINavigationController) -> ChatRoomListCoordinator { - return ChatRoomListCoordinator(navigationController: navigationController, dependencies: self) + func makeFriendListCoordinator(navigationController: UINavigationController) -> FriendListCoordinator { + return FriendListCoordinator(navigationController: navigationController, dependencies: self) } + +// func makeProfileDetailDIContainer() -> ProfileDetailDIContainer { +// let dependencies = ProfileDetailDIContainer.Dependencies() +// return ProfileDetailDICOntainer(dependencies: dependencies) +// } } -extension ChatRoomListDIContainer: ChatRoomListCoordinatorDependencies {} +extension FriendListDIContainer: FriendListCoordinatorDependencies {} diff --git a/NearTalk/NearTalk/Application/DIContainer/RootTabBarDIContainer.swift b/NearTalk/NearTalk/Application/DIContainer/RootTabBarDIContainer.swift index aaf92035..173d4b55 100644 --- a/NearTalk/NearTalk/Application/DIContainer/RootTabBarDIContainer.swift +++ b/NearTalk/NearTalk/Application/DIContainer/RootTabBarDIContainer.swift @@ -43,7 +43,7 @@ final class RootTabBarDIContainer { let dependency: RootTabBarControllerDependency = .init( mapViewController: MainMapViewController(), chatRoomListViewController: ChatRoomListViewController.create(with: DefaultChatRoomListViewModel(useCase: chatRoomListUseCase)), - friendListViewController: FriendsListViewController(), + friendListViewController: FriendListViewController(), myProfileViewController: myProfileVC ) return RootTabBarController(viewModel: makeViewModel(), dependency: dependency) diff --git a/NearTalk/NearTalk/Domain/Entities/Friend.swift b/NearTalk/NearTalk/Domain/Entities/Friend.swift index 65ea9fef..293c4de3 100644 --- a/NearTalk/NearTalk/Domain/Entities/Friend.swift +++ b/NearTalk/NearTalk/Domain/Entities/Friend.swift @@ -7,10 +7,25 @@ import Foundation -struct FriendInfo: Codable { +struct Friend: Codable, Hashable { /// 유저 UUID var userID: String? var username: String? var statusMessage: String? var profileImagePath: String? } + + +// private func createDummyData() { +// friendsListDummyData.append(FriendsListModel(img: "", name: "Ronald Robertson", description: "An suas viderer pro. Vis cu magna altera, ex his vivendo atomorum.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Johnny Watson", description: "Reprehenderit mollit excepteur labore deserunt officia laboris eiusmod cillum eu duis")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Annette Cooper", description: "Aliqua mollit nisi incididunt id eu consequat eu cupidatat.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Arthur Bell", description: "Voluptate irure aliquip consectetur commodo ex ex.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Jane Warren", description: "Ex Lorem veniam veniam irure sunt adipisicing culpa.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Morris Henry", description: "Dolore veniam Lorem occaecat veniam irure laborum est amet.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "Irma Flores", description: "Amet enim do laborum tempor nisi aliqua ad adipisicing.")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "008", description: "qwer")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "009", description: "asdf")) +// friendsListDummyData.append(FriendsListModel(img: "", name: "010", description: "zxcv")) +// +// } diff --git a/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift b/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift index e60a924e..26f12f72 100644 --- a/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift +++ b/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift @@ -9,31 +9,28 @@ import Foundation import RxSwift protocol FetchFriendListUseCase { - func getFriendListData() -> Observable<[FriendInfo]> + func getFriendsData() -> Observable<[Friend]> } final class DefaultFetchFriendListUseCase: FetchFriendListUseCase { private let disposeBag = DisposeBag() - private let userUUIDRepository: UserUUIDRepository! - private let userProfileRepository: UserProfileRepository! - private let fireStoreService: FireStoreService! - private let userProfile: Single + private let profileRepository: ProfileRepository! + private let frends: Single<[UserProfile]> - init(userUUIDRepository: UserUUIDRepository, userProfileRepository: UserProfileRepository, fireStoreService: FireStoreService) { - self.userUUIDRepository = userUUIDRepository - self.userProfileRepository = userProfileRepository - - self.userProfile = fireStoreService.getMyProfile() + init(profileRepository: ProfileRepository) { + self.profileRepository = profileRepository + self.frends = profileRepository.fetchFriendsProfile() } - func getFriendListData() -> Observable<[FriendInfo]> { - self.userProfile + func getFriendsData() -> Observable<[Friend]> { + return self.frends .asObservable() - .subscribe(onNext: { profile in - profile?.chatRooms - }) - .disposed(by: disposeBag) + .map { + $0.map { Friend(userID: $0.uuid, + username: $0.username, + statusMessage: $0.statusMessage, + profileImagePath: $0.profileImagePath) } + } } - } diff --git a/NearTalk/NearTalk/Presentation/ChatRoomList/ViewModel/ChatRoomListViewModel.swift b/NearTalk/NearTalk/Presentation/ChatRoomList/ViewModel/ChatRoomListViewModel.swift index 251fa89f..0c806f65 100644 --- a/NearTalk/NearTalk/Presentation/ChatRoomList/ViewModel/ChatRoomListViewModel.swift +++ b/NearTalk/NearTalk/Presentation/ChatRoomList/ViewModel/ChatRoomListViewModel.swift @@ -17,7 +17,6 @@ struct ChatRoomListViewModelActions { protocol ChatRoomListViewModelInput { func didCreateChatRoom() func didSelectItem(at index: Int) - func load() } protocol ChatRoomListViewModelOutput { @@ -41,10 +40,6 @@ final class DefaultChatRoomListViewModel: ChatRoomListViewModel { self.chatRoomListUseCase = useCase self.actions = actions - load() - } - - func load() { self.chatRoomListUseCase.getGroupChatList() .bind(to: groupChatRoomData) .disposed(by: self.disposeBag) @@ -53,6 +48,7 @@ final class DefaultChatRoomListViewModel: ChatRoomListViewModel { .bind(to: dmChatRoomData) .disposed(by: self.disposeBag) } + } // MARK: - Input diff --git a/NearTalk/NearTalk/Presentation/FriendList/Coordinator/FriendListCoordinator.swift b/NearTalk/NearTalk/Presentation/FriendList/Coordinator/FriendListCoordinator.swift new file mode 100644 index 00000000..a8315e10 --- /dev/null +++ b/NearTalk/NearTalk/Presentation/FriendList/Coordinator/FriendListCoordinator.swift @@ -0,0 +1,45 @@ +// +// FriendsListCoordinator.swift +// NearTalk +// +// Created by 김영욱 on 2022/11/15. +// + +import Foundation + +import UIKit + +protocol FriendListCoordinatorDependencies { + func makeFriendListViewController(actions: FriendListViewModelActions) -> FriendListViewController +// func makeProfileDetailViewController() +} + +final class FriendListCoordinator { + private weak var navigationController: UINavigationController? + private let dependencies: FriendListCoordinatorDependencies + + private weak var friendListViewController: FriendListViewController? + + // MARK: - Init + init(navigationController: UINavigationController, dependencies: FriendListCoordinatorDependencies) { + self.navigationController = navigationController + self.dependencies = dependencies + } + + // MARK: - Lifecycles + func start() { + let actions: FriendListViewModelActions = .init(showDetailFriend: self.showDetailFriend) + let viewController = dependencies.makeFriendListViewController(actions: actions) + + self.navigationController?.pushViewController(viewController, animated: false) + self.friendListViewController = viewController + + } + + // MARK: - Dependency + private func showDetailFriend() { +// let viewController = dependencies.makeProfileDetailViewController(actions: actions) +// navigationController?.pushViewController(viewController, animated: true) + } + +} diff --git a/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsListCell.swift b/NearTalk/NearTalk/Presentation/FriendList/View/FriendListCell.swift similarity index 93% rename from NearTalk/NearTalk/Presentation/FriendsList/View/FriendsListCell.swift rename to NearTalk/NearTalk/Presentation/FriendList/View/FriendListCell.swift index bf63b2c4..9b70c37a 100644 --- a/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsListCell.swift +++ b/NearTalk/NearTalk/Presentation/FriendList/View/FriendListCell.swift @@ -9,7 +9,7 @@ import SnapKit import Then import UIKit -final class FriendsListCell: UITableViewCell { +final class FriendListCell: UITableViewCell { static let identifier = String(describing: ChatRoomListCell.self) @@ -42,9 +42,9 @@ final class FriendsListCell: UITableViewCell { fatalError("init(coder:) has not been implemented") } - func configure(model: FriendsListModel) { - self.name.text = model.name - self.userDescription.text = model.description + func configure(model: Friend) { + self.name.text = model.username + self.userDescription.text = model.statusMessage } private func addSubviews() { diff --git a/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsViewController.swift b/NearTalk/NearTalk/Presentation/FriendList/View/FriendViewController.swift similarity index 67% rename from NearTalk/NearTalk/Presentation/FriendsList/View/FriendsViewController.swift rename to NearTalk/NearTalk/Presentation/FriendList/View/FriendViewController.swift index 2d68e3d1..2227f128 100644 --- a/NearTalk/NearTalk/Presentation/FriendsList/View/FriendsViewController.swift +++ b/NearTalk/NearTalk/Presentation/FriendList/View/FriendViewController.swift @@ -10,18 +10,29 @@ import SnapKit import Then import UIKit -final class FriendsListViewController: UIViewController { +final class FriendListViewController: UIViewController { // MARK: - UI properties private let tableView = UITableView(frame: CGRect.zero, style: .plain).then { - $0.register(FriendsListCell.self, forCellReuseIdentifier: FriendsListCell.identifier) + $0.register(FriendListCell.self, forCellReuseIdentifier: FriendListCell.identifier) } // MARK: - Properties + private let disposeBag: DisposeBag = DisposeBag() + private var viewModel: FriendListViewModel! - private var dataSource: UITableViewDiffableDataSource? - private var viewModel = FriendsListViewModel() + private var dataSource: UITableViewDiffableDataSource? + + enum Section { + case main + } // MARK: - Lifecycles + static func create(with viewModel: FriendListViewModel) -> FriendListViewController { + let view = FriendListViewController() + view.viewModel = viewModel + return view + } + override func viewDidLoad() { super.viewDidLoad() @@ -60,24 +71,12 @@ final class FriendsListViewController: UIViewController { // 데이터소스 세팅 private func configureDatasource() { - self.dataSource = UITableViewDiffableDataSource(tableView: self.tableView, cellProvider: { tableView, indexPath, _ in - guard let cell = tableView.dequeueReusableCell(withIdentifier: FriendsListCell.identifier, for: indexPath) as? FriendsListCell + self.dataSource = UITableViewDiffableDataSource(tableView: self.tableView, cellProvider: { tableView, indexPath, _ in + guard let cell = tableView.dequeueReusableCell(withIdentifier: FriendListCell.identifier, for: indexPath) as? FriendListCell else { return UITableViewCell() } - cell.configure(model: self.viewModel.friendsListDummyData[indexPath.row]) - return cell }) - - self.dataSource?.defaultRowAnimation = .fade - self.tableView.dataSource = self.dataSource - - // 빈 snapshot - var snapshot = NSDiffableDataSourceSnapshot() - snapshot.appendSections([0]) - snapshot.appendItems(viewModel.friendsListDummyData) - self.dataSource?.apply(snapshot) - } @objc private func didTapCreateChatRoomButton() { @@ -91,7 +90,7 @@ import SwiftUI struct FriendsListViewControllerPreview: PreviewProvider { static var previews: some View { - UINavigationController(rootViewController: FriendsListViewController()).showPreview(.iPhone14Pro) + UINavigationController(rootViewController: FriendListViewController()).showPreview(.iPhone14Pro) } } #endif diff --git a/NearTalk/NearTalk/Presentation/FriendList/ViewModel/FriendListViewModel.swift b/NearTalk/NearTalk/Presentation/FriendList/ViewModel/FriendListViewModel.swift new file mode 100644 index 00000000..c3f2ccb6 --- /dev/null +++ b/NearTalk/NearTalk/Presentation/FriendList/ViewModel/FriendListViewModel.swift @@ -0,0 +1,54 @@ +// +// FriendsListViewModel.swift +// NearTalk +// +// Created by 김영욱 on 2022/11/15. +// + +import Foundation +import RxRelay +import RxSwift + +struct FriendListViewModelActions { + let showDetailFriend: () -> Void +} + +protocol FriendListViewModelInput { + func didSelectItem(at index: Int) + func addFriend() +} + +protocol FriendListViewModelOutput { + var friendsData: BehaviorRelay<[Friend]> { get } +} + +protocol FriendListViewModel: FriendListViewModelInput, FriendListViewModelOutput {} + +final class DefaultFriendListViewModel: FriendListViewModel { + + private let fetchFriendListUseCase: FetchFriendListUseCase + private let actions: FriendListViewModelActions? + private let disposeBag: DisposeBag = DisposeBag() + + // MARK: - OUTPUT + var friendsData: BehaviorRelay<[Friend]> = BehaviorRelay<[Friend]>(value: []) + + init(useCase: FetchFriendListUseCase, actions: FriendListViewModelActions? = nil) { + self.fetchFriendListUseCase = useCase + self.actions = actions + + self.fetchFriendListUseCase.getFriendsData() + .bind(to: self.friendsData) + .disposed(by: self.disposeBag) + } + + // MARK: - INPUT + func didSelectItem(at index: Int) { + + } + + func addFriend() { + + } + +} diff --git a/NearTalk/NearTalk/Presentation/FriendsList/Coordinator/FriendsListCoordinator.swift b/NearTalk/NearTalk/Presentation/FriendsList/Coordinator/FriendsListCoordinator.swift deleted file mode 100644 index 616026d9..00000000 --- a/NearTalk/NearTalk/Presentation/FriendsList/Coordinator/FriendsListCoordinator.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// FriendsListCoordinator.swift -// NearTalk -// -// Created by 김영욱 on 2022/11/15. -// - -import Foundation - -import UIKit - -protocol FriendLsitCoordinatorDependencies { - -} - -final class FriendListCoordinator { - private weak var navigationController: UINavigationController? - -// private let dependencies: ChatRoomListCoordinatorDependencies - - private weak var friendListViewController: FriendsListViewController? - - // MARK: - Init - init(navigationController: UINavigationController, dependencies: ChatRoomListCoordinatorDependencies) { - self.navigationController = navigationController - self.dependencies = dependencies - } - - // MARK: - Lifecycles - func start() { - // action - - - } - - // MARK: - Dependency - - -} diff --git a/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift b/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift deleted file mode 100644 index a3d48d04..00000000 --- a/NearTalk/NearTalk/Presentation/FriendsList/ViewModel/FriendsListViewModel.swift +++ /dev/null @@ -1,62 +0,0 @@ -// -// FriendsListViewModel.swift -// NearTalk -// -// Created by 김영욱 on 2022/11/15. -// - -import Foundation -import RxRelay -import RxSwift - -struct FriendistViewModelActions { - let showDetailFriend: () -> Void -} - -protocol FriendListViewModelInput { - func didSelectItem(at index: Int) - func addFriendButton() -} - -protocol FriendListViewModelOutput { - var friendListData: BehaviorRelay<[String]> { get } -} - -protocol FriendListViewModel: FriendListViewModelInput, FriendListViewModelOutput {} - -final class FriendsListViewModel: FriendListViewModel { - - private let friendListUseCase: FetchFriendListUseCase - private let actions: FriendistViewModelActions? - private let disposeBag: DisposeBag = DisposeBag() - - // MARK: - OUTPUT - var friendListData: RxRelay.BehaviorRelay<[String]> - - init() { - - } - - // MARK: - INPUT - func didSelectItem(at index: Int) { - - } - - func addFriendButton() { - - } - -// private func createDummyData() { -// friendsListDummyData.append(FriendsListModel(img: "", name: "Ronald Robertson", description: "An suas viderer pro. Vis cu magna altera, ex his vivendo atomorum.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Johnny Watson", description: "Reprehenderit mollit excepteur labore deserunt officia laboris eiusmod cillum eu duis")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Annette Cooper", description: "Aliqua mollit nisi incididunt id eu consequat eu cupidatat.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Arthur Bell", description: "Voluptate irure aliquip consectetur commodo ex ex.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Jane Warren", description: "Ex Lorem veniam veniam irure sunt adipisicing culpa.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Morris Henry", description: "Dolore veniam Lorem occaecat veniam irure laborum est amet.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Irma Flores", description: "Amet enim do laborum tempor nisi aliqua ad adipisicing.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "008", description: "qwer")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "009", description: "asdf")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "010", description: "zxcv")) -// -// } -} diff --git a/NearTalk/NearTalk/Presentation/TabBar/View/RootTabBarController.swift b/NearTalk/NearTalk/Presentation/TabBar/View/RootTabBarController.swift index 69a548d3..997657e6 100644 --- a/NearTalk/NearTalk/Presentation/TabBar/View/RootTabBarController.swift +++ b/NearTalk/NearTalk/Presentation/TabBar/View/RootTabBarController.swift @@ -10,7 +10,7 @@ import UIKit struct RootTabBarControllerDependency { let mapViewController: MainMapViewController let chatRoomListViewController: ChatRoomListViewController - let friendListViewController: FriendsListViewController + let friendListViewController: FriendListViewController let myProfileViewController: MyProfileViewController } From 7461004f1ed218359652abf356ac91245d81c784 Mon Sep 17 00:00:00 2001 From: Woogie <100309352+yw22@users.noreply.github.com> Date: Tue, 22 Nov 2022 10:18:13 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[Chore]=20ChatRoomListUseCase=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NearTalk/NearTalk.xcodeproj/project.pbxproj | 8 ++++---- .../Application/DIContainer/ChatRoomListDIContainer.swift | 4 ++-- .../Application/DIContainer/RootTabBarDIContainer.swift | 2 +- ...atRoomListUseCase.swift => FetchChatRoomUseCase.swift} | 4 ++-- .../ChatRoomList/ViewModel/ChatRoomListViewModel.swift | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) rename NearTalk/NearTalk/Domain/UseCases/{ChatRoomListUseCase.swift => FetchChatRoomUseCase.swift} (93%) diff --git a/NearTalk/NearTalk.xcodeproj/project.pbxproj b/NearTalk/NearTalk.xcodeproj/project.pbxproj index 84acd23d..6e74f685 100644 --- a/NearTalk/NearTalk.xcodeproj/project.pbxproj +++ b/NearTalk/NearTalk.xcodeproj/project.pbxproj @@ -43,7 +43,7 @@ 555A6B3329236D98001336ED /* FriendListCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3229236D98001336ED /* FriendListCoordinator.swift */; }; 555A6B3529238C13001336ED /* ChatRoomListDIContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3429238C13001336ED /* ChatRoomListDIContainer.swift */; }; 555A6B3829238C69001336ED /* ChatRoomList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3729238C69001336ED /* ChatRoomList.swift */; }; - 555A6B3A29238C9B001336ED /* ChatRoomListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3929238C9B001336ED /* ChatRoomListUseCase.swift */; }; + 555A6B3A29238C9B001336ED /* FetchChatRoomUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3929238C9B001336ED /* FetchChatRoomUseCase.swift */; }; 555A6B3C29238D26001336ED /* DefaultChatRoomListRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3B29238D26001336ED /* DefaultChatRoomListRepository.swift */; }; 555A6B3E29238D65001336ED /* ChatRoomListRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555A6B3D29238D65001336ED /* ChatRoomListRepository.swift */; }; 555A6B432924B9E4001336ED /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 555A6B422924B9E4001336ED /* GoogleService-Info.plist */; }; @@ -231,7 +231,7 @@ 555A6B3229236D98001336ED /* FriendListCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendListCoordinator.swift; sourceTree = ""; }; 555A6B3429238C13001336ED /* ChatRoomListDIContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomListDIContainer.swift; sourceTree = ""; }; 555A6B3729238C69001336ED /* ChatRoomList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomList.swift; sourceTree = ""; }; - 555A6B3929238C9B001336ED /* ChatRoomListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomListUseCase.swift; sourceTree = ""; }; + 555A6B3929238C9B001336ED /* FetchChatRoomUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchChatRoomUseCase.swift; sourceTree = ""; }; 555A6B3B29238D26001336ED /* DefaultChatRoomListRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultChatRoomListRepository.swift; sourceTree = ""; }; 555A6B3D29238D65001336ED /* ChatRoomListRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ChatRoomListRepository.swift; path = NearTalk/Data/Repositories/ChatRoomListRepository.swift; sourceTree = SOURCE_ROOT; }; 555A6B422924B9E4001336ED /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; @@ -699,7 +699,7 @@ 1660D26C291DE32F005F7B24 /* UseCases */ = { isa = PBXGroup; children = ( - 555A6B3929238C9B001336ED /* ChatRoomListUseCase.swift */, + 555A6B3929238C9B001336ED /* FetchChatRoomUseCase.swift */, 8330622C2924A3F1000E786E /* OnboardingUseCase.swift */, 7CE806402925528F00D828FF /* CreateGroupChatUseCase.swift */, 7CE8063A2925312100D828FF /* ProfileDetailUseCase.swift */, @@ -1423,7 +1423,7 @@ 1653057E291E19150026B815 /* ChatRoomListViewController.swift in Sources */, 603EDDA92926C51100BEE65C /* TabBarRepository.swift in Sources */, 555A6B3529238C13001336ED /* ChatRoomListDIContainer.swift in Sources */, - 555A6B3A29238C9B001336ED /* ChatRoomListUseCase.swift in Sources */, + 555A6B3A29238C9B001336ED /* FetchChatRoomUseCase.swift in Sources */, 1648BAB1292387100076AC35 /* DmChatRoomAnnotationView.swift in Sources */, 1660D22C291DDB38005F7B24 /* ViewController.swift in Sources */, 555A6B482924BE65001336ED /* UserProfile.swift in Sources */, diff --git a/NearTalk/NearTalk/Application/DIContainer/ChatRoomListDIContainer.swift b/NearTalk/NearTalk/Application/DIContainer/ChatRoomListDIContainer.swift index e7a03a44..fb98389a 100644 --- a/NearTalk/NearTalk/Application/DIContainer/ChatRoomListDIContainer.swift +++ b/NearTalk/NearTalk/Application/DIContainer/ChatRoomListDIContainer.swift @@ -44,8 +44,8 @@ final class ChatRoomListDIContainer { // MARK: - Services // MARK: - UseCases - func makeChatRoomListUseCase() -> ChatRoomListUseCase { - return DefaultChatRoomListUseCase(chatRoomListRepository: self.makeRepository()) + func makeChatRoomListUseCase() -> FetchChatRoomUseCase { + return DefaultFetchChatRoomUseCase(chatRoomListRepository: self.makeRepository()) } // MARK: - Repositories diff --git a/NearTalk/NearTalk/Application/DIContainer/RootTabBarDIContainer.swift b/NearTalk/NearTalk/Application/DIContainer/RootTabBarDIContainer.swift index 173d4b55..07aba4c3 100644 --- a/NearTalk/NearTalk/Application/DIContainer/RootTabBarDIContainer.swift +++ b/NearTalk/NearTalk/Application/DIContainer/RootTabBarDIContainer.swift @@ -35,7 +35,7 @@ final class RootTabBarDIContainer { // MARK: - Create viewController func createTabBarController() -> RootTabBarController { let chatRoomListRepository = DefaultChatRoomListRepository(dataTransferService: DefaultStorageService()) - let chatRoomListUseCase: ChatRoomListUseCase = DefaultChatRoomListUseCase(chatRoomListRepository: chatRoomListRepository) + let chatRoomListUseCase: FetchChatRoomUseCase = DefaultFetchChatRoomUseCase(chatRoomListRepository: chatRoomListRepository) let myProfileDIContainer: MyProfileDIContainer = .init() let myProfileVC: MyProfileViewController = .init(coordinator: myProfileDIContainer.makeMyProfileCoordinator(), viewModel: myProfileDIContainer.makeViewModel()) diff --git a/NearTalk/NearTalk/Domain/UseCases/ChatRoomListUseCase.swift b/NearTalk/NearTalk/Domain/UseCases/FetchChatRoomUseCase.swift similarity index 93% rename from NearTalk/NearTalk/Domain/UseCases/ChatRoomListUseCase.swift rename to NearTalk/NearTalk/Domain/UseCases/FetchChatRoomUseCase.swift index aff21798..6f81d86e 100644 --- a/NearTalk/NearTalk/Domain/UseCases/ChatRoomListUseCase.swift +++ b/NearTalk/NearTalk/Domain/UseCases/FetchChatRoomUseCase.swift @@ -8,7 +8,7 @@ import Foundation import RxSwift -protocol ChatRoomListUseCase { +protocol FetchChatRoomUseCase { // func getGroupChatListCoreData() -> Observable<[GroupChatRoomListData]> // func getDataOfDMChatCoreData() -> Observable<[DMChatRoomListData]> @@ -16,7 +16,7 @@ protocol ChatRoomListUseCase { func getDMChatList() -> Observable<[DMChatRoomListData]> } -final class DefaultChatRoomListUseCase: ChatRoomListUseCase { +final class DefaultFetchChatRoomUseCase: FetchChatRoomUseCase { private let disposeBag = DisposeBag() private let chatRoomListRepository: ChatRoomListRepository! diff --git a/NearTalk/NearTalk/Presentation/ChatRoomList/ViewModel/ChatRoomListViewModel.swift b/NearTalk/NearTalk/Presentation/ChatRoomList/ViewModel/ChatRoomListViewModel.swift index 0c806f65..dabfabb7 100644 --- a/NearTalk/NearTalk/Presentation/ChatRoomList/ViewModel/ChatRoomListViewModel.swift +++ b/NearTalk/NearTalk/Presentation/ChatRoomList/ViewModel/ChatRoomListViewModel.swift @@ -28,7 +28,7 @@ protocol ChatRoomListViewModel: ChatRoomListViewModelInput, ChatRoomListViewMode final class DefaultChatRoomListViewModel: ChatRoomListViewModel { - private let chatRoomListUseCase: ChatRoomListUseCase + private let chatRoomListUseCase: FetchChatRoomUseCase private let actions: ChatRoomListViewModelActions? private let disposeBag: DisposeBag = DisposeBag() @@ -36,7 +36,7 @@ final class DefaultChatRoomListViewModel: ChatRoomListViewModel { var groupChatRoomData: BehaviorRelay<[GroupChatRoomListData]> = BehaviorRelay<[GroupChatRoomListData]>(value: []) var dmChatRoomData: BehaviorRelay<[DMChatRoomListData]> = BehaviorRelay<[DMChatRoomListData]>(value: []) - init(useCase: ChatRoomListUseCase, actions: ChatRoomListViewModelActions? = nil) { + init(useCase: FetchChatRoomUseCase, actions: ChatRoomListViewModelActions? = nil) { self.chatRoomListUseCase = useCase self.actions = actions From 57d45d3b4eca91b84711d3bbbc24ce5b60a82ae6 Mon Sep 17 00:00:00 2001 From: Woogie <100309352+yw22@users.noreply.github.com> Date: Tue, 22 Nov 2022 11:31:40 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[Feat]=20=EB=8D=94=EB=AF=B8=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80,=20Preview=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NearTalk/NearTalk.xcodeproj/project.pbxproj | 2 +- .../NearTalk/Domain/Entities/Friend.swift | 15 --------- .../UseCases/FetchFriendListUseCase.swift | 27 +++++++++++++++- .../View/ChatRoomListViewController.swift | 12 +++---- .../View/FriendViewController.swift | 32 ++++++++++++++++--- 5 files changed, 60 insertions(+), 28 deletions(-) diff --git a/NearTalk/NearTalk.xcodeproj/project.pbxproj b/NearTalk/NearTalk.xcodeproj/project.pbxproj index 6e74f685..0bc4e5bd 100644 --- a/NearTalk/NearTalk.xcodeproj/project.pbxproj +++ b/NearTalk/NearTalk.xcodeproj/project.pbxproj @@ -700,12 +700,12 @@ isa = PBXGroup; children = ( 555A6B3929238C9B001336ED /* FetchChatRoomUseCase.swift */, + 5506CDDC292B4F810002F328 /* FetchFriendListUseCase.swift */, 8330622C2924A3F1000E786E /* OnboardingUseCase.swift */, 7CE806402925528F00D828FF /* CreateGroupChatUseCase.swift */, 7CE8063A2925312100D828FF /* ProfileDetailUseCase.swift */, 83D3543E29253A5C00B9236A /* MyProfileLoadUseCase.swift */, 603EDDA62926C4B300BEE65C /* TabBarUseCase.swift */, - 5506CDDC292B4F810002F328 /* FetchFriendListUseCase.swift */, 603FD394292A1E7000687ED4 /* LoginUseCase.swift */, 603FD399292B4F0F00687ED4 /* VerifyUserUseCase.swift */, 603FD39B292B4F4A00687ED4 /* LogoutUseCase.swift */, diff --git a/NearTalk/NearTalk/Domain/Entities/Friend.swift b/NearTalk/NearTalk/Domain/Entities/Friend.swift index 293c4de3..c2a1b7ff 100644 --- a/NearTalk/NearTalk/Domain/Entities/Friend.swift +++ b/NearTalk/NearTalk/Domain/Entities/Friend.swift @@ -14,18 +14,3 @@ struct Friend: Codable, Hashable { var statusMessage: String? var profileImagePath: String? } - - -// private func createDummyData() { -// friendsListDummyData.append(FriendsListModel(img: "", name: "Ronald Robertson", description: "An suas viderer pro. Vis cu magna altera, ex his vivendo atomorum.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Johnny Watson", description: "Reprehenderit mollit excepteur labore deserunt officia laboris eiusmod cillum eu duis")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Annette Cooper", description: "Aliqua mollit nisi incididunt id eu consequat eu cupidatat.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Arthur Bell", description: "Voluptate irure aliquip consectetur commodo ex ex.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Jane Warren", description: "Ex Lorem veniam veniam irure sunt adipisicing culpa.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Morris Henry", description: "Dolore veniam Lorem occaecat veniam irure laborum est amet.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "Irma Flores", description: "Amet enim do laborum tempor nisi aliqua ad adipisicing.")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "008", description: "qwer")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "009", description: "asdf")) -// friendsListDummyData.append(FriendsListModel(img: "", name: "010", description: "zxcv")) -// -// } diff --git a/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift b/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift index 26f12f72..4f35f17c 100644 --- a/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift +++ b/NearTalk/NearTalk/Domain/UseCases/FetchFriendListUseCase.swift @@ -16,11 +16,13 @@ final class DefaultFetchFriendListUseCase: FetchFriendListUseCase { private let disposeBag = DisposeBag() private let profileRepository: ProfileRepository! + private let friendsDummyData: FriendsDummyData = FriendsDummyData() private let frends: Single<[UserProfile]> init(profileRepository: ProfileRepository) { self.profileRepository = profileRepository - self.frends = profileRepository.fetchFriendsProfile() +// self.frends = profileRepository.fetchFriendsProfile() + self.frends = friendsDummyData.fetchFriendsData() } func getFriendsData() -> Observable<[Friend]> { @@ -34,3 +36,26 @@ final class DefaultFetchFriendListUseCase: FetchFriendListUseCase { } } } + +struct FriendsDummyData { + var friends: [UserProfile] = [] + + init() { + friends.append(UserProfile(uuid: UUID().uuidString, username: "라이언", statusMessage: "가시밭길 위로 riding, you made me boost up", profileImagePath: "")) + friends.append(UserProfile(uuid: UUID().uuidString, username: "어피치", statusMessage: "거짓으로 가득 찬 party 가렵지도 않아", profileImagePath: "")) + friends.append(UserProfile(uuid: UUID().uuidString, username: "네오", statusMessage: "내 뒤에 말들이 많아, 나도 첨 듣는 내 rival", profileImagePath: "")) + friends.append(UserProfile(uuid: UUID().uuidString, username: "튜브", statusMessage: "모두 기도해 내 falling 그 손 위로 I'ma jump in", profileImagePath: "")) + } + + func fetchFriendsData() -> Single<[UserProfile]> { + return Single<[UserProfile]>.create { single in + guard !friends.isEmpty + else { + single(.failure(FirebaseAuthError.nilUser)) + return Disposables.create() + } + single(.success(self.friends)) + return Disposables.create() + } + } +} diff --git a/NearTalk/NearTalk/Presentation/ChatRoomList/View/ChatRoomListViewController.swift b/NearTalk/NearTalk/Presentation/ChatRoomList/View/ChatRoomListViewController.swift index 1d30040c..622d7b29 100644 --- a/NearTalk/NearTalk/Presentation/ChatRoomList/View/ChatRoomListViewController.swift +++ b/NearTalk/NearTalk/Presentation/ChatRoomList/View/ChatRoomListViewController.swift @@ -113,22 +113,22 @@ final class ChatRoomListViewController: UIViewController { .disposed(by: disposeBag) self.viewModel.dmChatRoomData - .bind(onNext: { model in + .bind(onNext: { [weak self] model in var snapshot = NSDiffableDataSourceSnapshot() snapshot.appendSections([.main]) snapshot.appendItems(model) - self.dmDataSource?.defaultRowAnimation = .fade - self.dmDataSource?.apply(snapshot, animatingDifferences: true) + self?.dmDataSource?.defaultRowAnimation = .fade + self?.dmDataSource?.apply(snapshot, animatingDifferences: true) }) .disposed(by: disposeBag) self.viewModel.groupChatRoomData - .bind(onNext: { model in + .bind(onNext: { [weak self] model in var snapshot = NSDiffableDataSourceSnapshot() snapshot.appendSections([.main]) snapshot.appendItems(model) - self.groupDataSource?.defaultRowAnimation = .fade - self.groupDataSource?.apply(snapshot, animatingDifferences: true) + self?.groupDataSource?.defaultRowAnimation = .fade + self?.groupDataSource?.apply(snapshot, animatingDifferences: true) }) .disposed(by: disposeBag) } diff --git a/NearTalk/NearTalk/Presentation/FriendList/View/FriendViewController.swift b/NearTalk/NearTalk/Presentation/FriendList/View/FriendViewController.swift index 2227f128..7e67788b 100644 --- a/NearTalk/NearTalk/Presentation/FriendList/View/FriendViewController.swift +++ b/NearTalk/NearTalk/Presentation/FriendList/View/FriendViewController.swift @@ -20,7 +20,7 @@ final class FriendListViewController: UIViewController { private let disposeBag: DisposeBag = DisposeBag() private var viewModel: FriendListViewModel! - private var dataSource: UITableViewDiffableDataSource? + private var dataSource: UITableViewDiffableDataSource? enum Section { case main @@ -50,6 +50,7 @@ final class FriendListViewController: UIViewController { self.configureTableView() self.configureNavigation() self.configureDatasource() + self.bind() } private func configureView() { @@ -70,15 +71,26 @@ final class FriendListViewController: UIViewController { // 데이터소스 세팅 private func configureDatasource() { - - self.dataSource = UITableViewDiffableDataSource(tableView: self.tableView, cellProvider: { tableView, indexPath, _ in + self.dataSource = UITableViewDiffableDataSource(tableView: self.tableView, cellProvider: { tableView, indexPath, model in guard let cell = tableView.dequeueReusableCell(withIdentifier: FriendListCell.identifier, for: indexPath) as? FriendListCell else { return UITableViewCell() } - + cell.configure(model: model) return cell }) } + private func bind() { + self.viewModel.friendsData + .bind(onNext: { [weak self] model in + var snapshot = NSDiffableDataSourceSnapshot() + snapshot.appendSections([.main]) + snapshot.appendItems(model) + self?.dataSource?.defaultRowAnimation = .fade + self?.dataSource?.apply(snapshot, animatingDifferences: true) + }) + .disposed(by: disposeBag) + } + @objc private func didTapCreateChatRoomButton() { print("친구 추가 이동") } @@ -90,7 +102,17 @@ import SwiftUI struct FriendsListViewControllerPreview: PreviewProvider { static var previews: some View { - UINavigationController(rootViewController: FriendListViewController()).showPreview(.iPhone14Pro) + lazy var firestoreService: DefaultFirestoreService = { + return DefaultFirestoreService() + }() + lazy var firebaseAuthService: DefaultFirebaseAuthService = { + return DefaultFirebaseAuthService() + }() + let dependencies = FriendListDIContainer.Dependencies(firestoreService: firestoreService, firebaseAuthService: firebaseAuthService) + let diContainer = FriendListDIContainer(dependencies: dependencies) + let actions = FriendListViewModelActions(showDetailFriend: {}) + let viewController = diContainer.makeFriendListViewController(actions: actions) + return UINavigationController(rootViewController: viewController).showPreview(.iPhone14Pro) } } #endif