From 99ba219f6c407a819f7b0626b1e7d6d2822906bc Mon Sep 17 00:00:00 2001 From: mmaybei Date: Tue, 16 Jul 2024 16:51:19 +0900 Subject: [PATCH] =?UTF-8?q?feat/#185=20=ED=99=88=20=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?=EB=8B=A4=EA=B0=80=EC=98=AC=20=EC=95=BD=EC=86=8D=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=ED=83=80=EC=9E=85=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?=EB=B0=8F=20=EB=B7=B0=EB=AA=A8=EB=8D=B8=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KkuMulKum.xcodeproj/project.pbxproj | 26 ++---- KkuMulKum/Resource/Service/HomeService.swift | 90 +++++++++++++++++++ .../Source/Core/MainTabBarController.swift | 5 +- .../Home/Model/UpcomingPromiseModel.swift | 56 ------------ .../UpcomingPromiseCollecitonViewCell.swift | 2 +- .../ViewController/HomeViewController.swift | 26 ++++-- .../Source/Home/ViewModel/HomeViewModel.swift | 24 +++-- .../MeetingListViewController.swift | 5 -- 8 files changed, 140 insertions(+), 94 deletions(-) create mode 100644 KkuMulKum/Resource/Service/HomeService.swift delete mode 100644 KkuMulKum/Source/Home/Model/UpcomingPromiseModel.swift diff --git a/KkuMulKum.xcodeproj/project.pbxproj b/KkuMulKum.xcodeproj/project.pbxproj index 1b38ab11..1436634b 100644 --- a/KkuMulKum.xcodeproj/project.pbxproj +++ b/KkuMulKum.xcodeproj/project.pbxproj @@ -72,6 +72,7 @@ A3DD9C5C2C43F9A800E58A13 /* SetReadyInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C5B2C43F9A800E58A13 /* SetReadyInfoViewController.swift */; }; A3DD9C5F2C441F8E00E58A13 /* SetReadyInfoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C5E2C441F8E00E58A13 /* SetReadyInfoViewModel.swift */; }; A3DD9C622C455E3300E58A13 /* MeetingListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C612C455E3300E58A13 /* MeetingListService.swift */; }; + A3DD9C682C45C78300E58A13 /* HomeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3DD9C672C45C78300E58A13 /* HomeService.swift */; }; A3FB184D2C3BF45F001483E5 /* MakeMeetingsRequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FB184C2C3BF45F001483E5 /* MakeMeetingsRequestModel.swift */; }; A3FB184F2C3BF4BC001483E5 /* MakeMeetingsResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FB184E2C3BF4BB001483E5 /* MakeMeetingsResponseModel.swift */; }; A3FB18512C3BF531001483E5 /* RegisterMeetingsResquestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3FB18502C3BF531001483E5 /* RegisterMeetingsResquestModel.swift */; }; @@ -218,6 +219,7 @@ A3DD9C5B2C43F9A800E58A13 /* SetReadyInfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetReadyInfoViewController.swift; sourceTree = ""; }; A3DD9C5E2C441F8E00E58A13 /* SetReadyInfoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetReadyInfoViewModel.swift; sourceTree = ""; }; A3DD9C612C455E3300E58A13 /* MeetingListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeetingListService.swift; sourceTree = ""; }; + A3DD9C672C45C78300E58A13 /* HomeService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeService.swift; sourceTree = ""; }; A3FB184C2C3BF45F001483E5 /* MakeMeetingsRequestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeMeetingsRequestModel.swift; sourceTree = ""; }; A3FB184E2C3BF4BB001483E5 /* MakeMeetingsResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MakeMeetingsResponseModel.swift; sourceTree = ""; }; A3FB18502C3BF531001483E5 /* RegisterMeetingsResquestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterMeetingsResquestModel.swift; sourceTree = ""; }; @@ -548,22 +550,6 @@ path = Bundle; sourceTree = ""; }; - A3DD9C332C41BAD000E58A13 /* Cell */ = { - isa = PBXGroup; - children = ( - A3DD9C322C41BAD000E58A13 /* MeetingTableViewCell.swift */, - ); - path = Cell; - sourceTree = ""; - }; - A3DD9C352C41BAD000E58A13 /* Model */ = { - isa = PBXGroup; - children = ( - A3DD9C342C41BAD000E58A13 /* MeetingDummyModel.swift */, - ); - path = Model; - sourceTree = ""; - }; A3DD9C372C41BAD000E58A13 /* View */ = { isa = PBXGroup; children = ( @@ -611,6 +597,7 @@ isa = PBXGroup; children = ( A3DD9C612C455E3300E58A13 /* MeetingListService.swift */, + A3DD9C672C45C78300E58A13 /* HomeService.swift */, ); path = Service; sourceTree = ""; @@ -955,7 +942,6 @@ DD865B662C39210E00C351A2 /* Login */ = { isa = PBXGroup; children = ( - 78BD61212C440AC8005752FD /* Service */, 789873372C3D1B4800435E96 /* ViewController */, 789873362C3D1B3900435E96 /* VIewModel */, 789873352C3D1B3000435E96 /* View */, @@ -1464,7 +1450,6 @@ DE6D4D112C3F14D80005584B /* MeetingInfoBannerView.swift in Sources */, DE6D4D122C3F14D80005584B /* MeetingInfoView.swift in Sources */, DD30721E2C3C0CC800416D9F /* PromiseInfoResponseModel.swift in Sources */, - 78BD61232C440AD5005752FD /* AuthService.swift in Sources */, DD931B722C3DA92700526452 /* EnterReadyInfoButtonView.swift in Sources */, DD41BEFF2C41DAA40095A068 /* TardyEmptyView.swift in Sources */, A3FB18512C3BF531001483E5 /* RegisterMeetingsResquestModel.swift in Sources */, @@ -1517,6 +1502,7 @@ DD3976832C41C2AD00E2A4C4 /* HomeViewModel.swift in Sources */, DD41BF012C41DE4F0095A068 /* TardyCollectionViewCell.swift in Sources */, DE9E189A2C3BCCBE00DB76B4 /* UtilsTemp.swift in Sources */, + A3DD9C682C45C78300E58A13 /* HomeService.swift in Sources */, 782B407B2C3E395A008B0CA7 /* WelcomeView.swift in Sources */, DD3072142C3BF87A00416D9F /* NearestPromiseResponseModel.swift in Sources */, 782B407F2C3E44B7008B0CA7 /* WelcomeViewModel.swift in Sources */, @@ -1544,9 +1530,9 @@ DD41BEFC2C41D54D0095A068 /* TardyPenaltyView.swift in Sources */, 789873322C3D1A7B00435E96 /* LoginViewController.swift in Sources */, 782B40722C3DBFA3008B0CA7 /* ProfileSetupViewModel.swift in Sources */, - DDAF1C8F2C3D6E3D008A37D3 /* BasePromiseSegmentedControl.swift in Sources */, + DDAF1C8F2C3D6E3D008A37D3 /* PagePromiseSegmentedControl.swift in Sources */, DD49099C2C441719003ED304 /* TardyService.swift in Sources */, - 782B40722C3DBFA3008B0CA7 /* ProfileViewModel.swift in Sources */, + 782B40722C3DBFA3008B0CA7 /* ProfileSetupViewModel.swift in Sources */, DDAF1C8F2C3D6E3D008A37D3 /* PagePromiseSegmentedControl.swift in Sources */, DE32D1D22C3BF703006848DF /* LoginUserResponseModel.swift in Sources */, DE9E18892C3BC91000DB76B4 /* ResponseBodyDTO.swift in Sources */, diff --git a/KkuMulKum/Resource/Service/HomeService.swift b/KkuMulKum/Resource/Service/HomeService.swift new file mode 100644 index 00000000..f095b3c8 --- /dev/null +++ b/KkuMulKum/Resource/Service/HomeService.swift @@ -0,0 +1,90 @@ +// +// HomeService.swift +// KkuMulKum +// +// Created by 예삐 on 7/16/24. +// + +import Foundation + +protocol HomeServiceType { + func fetchLoginUser() -> LoginUserModel? + func fetchNearestPromise() -> NearestPromiseModel? + func fetchUpcomingPromise() -> UpcomingPromiseListModel? +} + +final class MockHomeService: HomeServiceType { + func fetchLoginUser() -> LoginUserModel? { + let mockData = LoginUserModel( + name: "꾸물리안", + level: 4, + promiseCount: 8, + tardyCount: 2, + tardySum: 72, + profileImageURL: "" + ) + return mockData + } + + func fetchNearestPromise() -> NearestPromiseModel? { + let mockData = NearestPromiseModel( + id: 1, + dDay: 0, + name: "꾸물이들의 냐미한 밤", + meetingName: "꾸물이들", + dressUpLevel: "냐미", + date: "2024.07.16", + time: "PM 8:00", + placeName: "DMC역" + ) + return mockData + } + + func fetchUpcomingPromise() -> UpcomingPromiseListModel? { + let mockData = UpcomingPromiseListModel( + promises: [ + UpcomingPromise( + id: 1, + dDay: 1, + name: "누가 코코볼 다 먹었어?", + meetingName: "우마우스", + dressUpLevel: "", + date: "2024.07.17", + time: "PM 2:00", + placeName: "가자하우스" + ), + UpcomingPromise( + id: 2, + dDay: 1, + name: "누가 코코볼 다 먹었어?", + meetingName: "우마우스", + dressUpLevel: "", + date: "2024.07.17", + time: "PM 2:00", + placeName: "가자하우스" + ), + UpcomingPromise( + id: 3, + dDay: 1, + name: "누가 코코볼 다 먹었어?", + meetingName: "우마우스", + dressUpLevel: "", + date: "2024.07.17", + time: "PM 2:00", + placeName: "가자하우스" + ), + UpcomingPromise( + id: 4, + dDay: 1, + name: "누가 코코볼 다 먹었어?", + meetingName: "우마우스", + dressUpLevel: "", + date: "2024.07.17", + time: "PM 2:00", + placeName: "가자하우스" + ) + ] + ) + return mockData + } +} diff --git a/KkuMulKum/Source/Core/MainTabBarController.swift b/KkuMulKum/Source/Core/MainTabBarController.swift index 48378ae5..b70b5f03 100644 --- a/KkuMulKum/Source/Core/MainTabBarController.swift +++ b/KkuMulKum/Source/Core/MainTabBarController.swift @@ -24,7 +24,10 @@ final class MainTabBarController: UITabBarController { private func setTabBar() { - let homeViewController: HomeViewController = HomeViewController().then { + let homeViewController: HomeViewController = HomeViewController( + viewModel: HomeViewModel( + service: MockHomeService() + )).then { $0.tabBarItem.title = "홈" $0.tabBarItem.image = .iconHome } diff --git a/KkuMulKum/Source/Home/Model/UpcomingPromiseModel.swift b/KkuMulKum/Source/Home/Model/UpcomingPromiseModel.swift deleted file mode 100644 index 663cf291..00000000 --- a/KkuMulKum/Source/Home/Model/UpcomingPromiseModel.swift +++ /dev/null @@ -1,56 +0,0 @@ -// -// UpcomingPromiseModel.swift -// KkuMulKum -// -// Created by 예삐 on 7/10/24. -// - -import UIKit - -struct UpcomingPromiseModel { - let name: String - let meetingName: String - let dDay: Int - let date: String - let time: String - let placeName: String -} - -extension UpcomingPromiseModel { - static func dummy() -> [UpcomingPromiseModel] { - return [ - UpcomingPromiseModel( - name: "리프레쉬 데이", - meetingName: "꾸물이들", - dDay: 0, - date: "2024.07.11", - time: "PM 2:00", - placeName: "어디가지" - ), - UpcomingPromiseModel( - name: "리프레쉬 데이", - meetingName: "꾸물이들", - dDay: 4, - date: "2024.07.13", - time: "PM 2:00", - placeName: "어디가지" - ), - UpcomingPromiseModel( - name: "리프레쉬 데이", - meetingName: "꾸물이들", - dDay: 4, - date: "2024.07.13", - time: "PM 2:00", - placeName: "어디가지" - ), - UpcomingPromiseModel( - name: "리프레쉬 데이", - meetingName: "꾸물이들", - dDay: 4, - date: "2024.07.13", - time: "PM 2:00", - placeName: "어디가지" - ) - ] - } -} diff --git a/KkuMulKum/Source/Home/View/UpcomingPromiseCollecitonViewCell.swift b/KkuMulKum/Source/Home/View/UpcomingPromiseCollecitonViewCell.swift index 23dac12a..f228c615 100644 --- a/KkuMulKum/Source/Home/View/UpcomingPromiseCollecitonViewCell.swift +++ b/KkuMulKum/Source/Home/View/UpcomingPromiseCollecitonViewCell.swift @@ -137,7 +137,7 @@ final class UpcomingPromiseCollectionViewCell: BaseCollectionViewCell { // MARK: - Data Bind extension UpcomingPromiseCollectionViewCell { - func dataBind(_ contentData: UpcomingPromiseModel) { + func dataBind(_ contentData: UpcomingPromise) { let dDayText = contentData.dDay == 0 ? "DAY" : "\(contentData.dDay)" dDayLabel.setText( "D-\(dDayText)", diff --git a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift index b8e1fa13..6f56a999 100644 --- a/KkuMulKum/Source/Home/ViewController/HomeViewController.swift +++ b/KkuMulKum/Source/Home/ViewController/HomeViewController.swift @@ -15,12 +15,25 @@ class HomeViewController: BaseViewController { // MARK: - Property private let rootView = HomeView() - private let viewModel = HomeViewModel() + + private let viewModel: HomeViewModel final let cellWidth: CGFloat = 200 final let cellHeight: CGFloat = 216 final let contentInterSpacing: CGFloat = 12 final let contentInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20) + + + // MARK: - Initializer + + init(viewModel: HomeViewModel) { + self.viewModel = viewModel + super.init(nibName: nil, bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } // MARK: - LifeCycle @@ -36,8 +49,9 @@ class HomeViewController: BaseViewController { register() updateUI() + updateUpcomingPromise() - viewModel.dummy() + viewModel.requestUpcomingPromise() } override func viewWillAppear(_ animated: Bool) { @@ -107,7 +121,7 @@ extension HomeViewController: UICollectionViewDataSource { _ collectionView: UICollectionView, numberOfItemsInSection section: Int ) -> Int { - return viewModel.upcomingPromiseData.value.count + return viewModel.upcomingPromiseList.value?.promises.count ?? 0 } func collectionView( @@ -118,7 +132,9 @@ extension HomeViewController: UICollectionViewDataSource { withReuseIdentifier: UpcomingPromiseCollectionViewCell.reuseIdentifier, for: indexPath ) as? UpcomingPromiseCollectionViewCell else { return UICollectionViewCell() } - cell.dataBind(viewModel.upcomingPromiseData.value[indexPath.item]) + if let data = viewModel.upcomingPromiseList.value?.promises[indexPath.item] { + cell.dataBind(data) + } return cell } } @@ -190,7 +206,7 @@ private extension HomeViewController { } func updateUpcomingPromise() { - viewModel.upcomingPromiseData.bind { [weak self] _ in + viewModel.upcomingPromiseList.bind { [weak self] _ in DispatchQueue.main.async { self?.rootView.upcomingPromiseView.reloadData() } diff --git a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift index 16a47fef..f5577422 100644 --- a/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift +++ b/KkuMulKum/Source/Home/ViewModel/HomeViewModel.swift @@ -18,7 +18,16 @@ enum ReadyState { final class HomeViewModel { var currentState = ObservablePattern(.none) - var upcomingPromiseData = ObservablePattern<[UpcomingPromiseModel]>([]) + + var loginUser = ObservablePattern(nil) + var nearestPromise = ObservablePattern(nil) + var upcomingPromiseList = ObservablePattern(nil) + + private let service: HomeServiceType + + init(service: HomeServiceType) { + self.service = service + } var homePrepareTime: String = "" var homeMoveTime: String = "" @@ -45,12 +54,15 @@ final class HomeViewModel { } } - /// 더미 함수 이후에 삭제 - func dummy() { - upcomingPromiseData.value = UpcomingPromiseModel.dummy() + func requestLoginUser() { + loginUser.value = service.fetchLoginUser() + } + + func requestNearestPromise() { + nearestPromise.value = service.fetchNearestPromise() } - func updateContentData(newData: [UpcomingPromiseModel]) { - upcomingPromiseData.value = newData + func requestUpcomingPromise() { + upcomingPromiseList.value = service.fetchUpcomingPromise() } } diff --git a/KkuMulKum/Source/MeetingList/ViewController/MeetingListViewController.swift b/KkuMulKum/Source/MeetingList/ViewController/MeetingListViewController.swift index b20c9c14..2a1e9b4e 100644 --- a/KkuMulKum/Source/MeetingList/ViewController/MeetingListViewController.swift +++ b/KkuMulKum/Source/MeetingList/ViewController/MeetingListViewController.swift @@ -62,10 +62,6 @@ class MeetingListViewController: BaseViewController { rootView.tableView.dataSource = self } - private func updateInfoLabel() { - - } - private func updateMeetingList() { viewModel.meetingList.bind { [weak self] _ in DispatchQueue.main.async { @@ -104,7 +100,6 @@ extension MeetingListViewController: UITableViewDataSource { if let data = viewModel.meetingList.value?.meetings[indexPath.item] { cell.dataBind(data) } - //cell.dataBind(viewModel.meetingList.value?[indexPath.item]) cell.selectionStyle = .none return cell }